Jonathan Grynspan

@finestructure @cocoaphony Is the code in the test function actually throwing an error or just calling #expect() (or some such)? If a test function throws an error, it's just thrown naturally until something catches it. If code in Swift Testing catches it (which happens outside the context of test-scoped traits) then the error is recorded as a test issue.

Nick Lockwood

@danielkasaj @nicklockwood @vanvoorden I was trying to understand why this is better than just putting the try before the #expect() as I am doing. I understand now though - the issue is that putting try outside the expect sometimes won't compile (in my case it does, so I think it doesn't matter in this case)

Daniel Kasaj

@nicklockwood @vanvoorden you don’t have to worry if it’s before #expect or inside the parentheses

Alex Grebenyuk

@nicklockwood wait a second, #expect doesn’t require a throw. I mixed it up with something else. Yeah if the expression inside it could throw, I’d expect to put “try” inside the #expect.

Mar 07, 2025, 13:56 · · · 0 · 0
Nick Lockwood

@danielkasaj @vanvoorden how does the output differ in this approach vs putting the try before the #expect?

Daniel Kasaj

@vanvoorden @nicklockwood

let result = try …
#expect(result == expected)

This is the way

Mar 07, 2025, 05:39 · · · 0 · 0
orj

@cocoaphony @dimsumthinking note that comments added to @Test and #expect macros are captured as metadata and are printed in logs on test failures. So just keep doing what you’re doing.

Nick Lockwood

I just realized I've been putting the `try` in the wrong place in Swift Testing the whole time 😩 It should be:

try #expect(result == expected)

not:

#expect(try result == expected)

The stupid thing is that I *knew* about this, and I was careful to be consistent, but I was consistently *wrong*

Steven Woolgar

@mattiem oh weird, if I change:

#expect(type =~ Spanner.SpannerType.HairPin)

To:

print(type =~ Spanner.SpannerType.HairPin)

It no longer has a problem.

Sounds like something #expect() is doing

CM Thiede

@carnage4life that's the point, no? To stir up the #crazies with having to deal with the #demons #trapped inside theirs? I #imagine they #expect their #free #peepShow to be of their choosing too, but #God doesn't #operate that way!

#DealersChoice

Can we ALL get a little more #private once again?

Bring #Privacy Back Again

There, that's a #slogan worth a #chant

The rest can #buggerOff

Art of Goulwen R

20. Expect — But wealth wasn’t what she expected from him …

This year, I’ll tell the story of the Human Chair and how it arrived in Lady d’Arcy seminary. I’ll use my own words list.

#art #fanart #artwork #artoftheday #nautilebleu #owncharacter #inktober #horror #expect #spooky #creepy #weird #humanchair #artistsupportingartists #characterart #fediart #mastodonart #mastoart #creativetoots

Roddi

Der Bug in iOS 18 erwähnt in der gestrigen Freakshow (ja sehr nerdig, aber Leute haben gefragt)

@Test func testConvertUnorderListHTMLToPlainText() {
let htmlString = "<ul><li>Test</li><li>Test2</li></ul>"
let decoded = try? NSAttributedString(data: Data(htmlString.utf8), options: {[.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue] }(), documentAttributes: nil)
#expect(decoded?.string == "\t•\tTest\n\t•\tTest2\n")
}

Robert Widmann

@griotspeak you can put the tests in the same file as the types they’re testing you know!

struct Foo { private var bar: Bar }

#if ENABLE_LITERATE_TESTING
internal import Testing

extension Foo {
@Suite(“Foo Tests”)
fileprivate struct Tests {
@Test
func baz() {
#expect(Foo().bar.isBazzy)
}
}
}
#endif

anything but @\testable!

billwake

@throwspace Thanks, I think I get what you're saying. I was hoping for a way that the new parameterized tests to pass the source location of the parameter instances (maybe as an extra argument?).

The failure message shows the failing argument at the #expect but not at the original source location.

I had put together github.com/wwake/EgTest for parameterized testing with XCTest and am hoping I can retire it.

I don't see a macro to get a SourceLocation to map (as #file/#line do).

Thanks

GitHub - wwake/EGTest: EGTest - a package for parameterized testing in Swift

EGTest - a package for parameterized testing in Swift…

github.com