TL;DR: Is it possible to invoke
XCTFail dynamically without importing XCTest?
We're developing an SPM package that ships with a test support module that has a helper that invokes
XCTFail. Unfortunately, it turns out that SPM does not support the use case where a
MyLibraryTestSupport library product depends on a
MyLibrary library product, because downstream apps that import the library into their app and the test support library in tests will break due to duplicate symbols.
We've tried mitigating this issue by marking both packages
.dynamic, but this prevents downstream packages from reliably depending on our package (https://github.com/pointfreeco/swift-composable-architecture/issues/60).
A few other bugs we've discovered:
- On-device Xcode previews break due to automatic linking of the test support module (https://github.com/pointfreeco/swift-composable-architecture/issues/57)
- Test targets can crash due to duplicate symbols, with greater frequency in Xcode 11.3 (https://github.com/pointfreeco/swift-composable-architecture/pull/52)
We could move our test support library to its own package/repository, but this seems like a non-starter, as it makes package maintenance and consumption more burdensome.
What we'd like to do instead is merge the libraries, but the test helper's call to
import XCTest immediately causes problems. So we're wondering if it's somehow possible to get a dynamic handle on
XCTFail so that our test helper can be invoked on test runs but not cause any problems for applications that link to our library.
Does anyone know if this is possible or have another solution given the above?
We're also tracking this issue here: https://github.com/pointfreeco/swift-composable-architecture/issues/70