I'm in the process of adopting swift-testing in one of my projects. It has a lot of types and some protocols they conform to, so many tests have the following shape:
@Test(arguments: listOfAllFooTypes)
func invariants(type: any Foo.Type) {
whereIs(type) // or we don't run our test!
func whereIs<T>(_ type: T.Type) where T: Foo {
#expect(...)
#expect(...)
#expect(...)
}
}
That's an awkward ceremony! Granted, XCTest is similar. But swift-testing has macros! If @Test
could unbox existentials automatically, awesome! Imagine this instead:
@Test(arguments: listOfAllFooTypes)
func invariants<T>(type: T.Type) where T: Foo {
#expect(...)
#expect(...)
#expect(...)
}