I am able to use an Xcode project with Precondition Catching to build a library which imports XCTest to add a couple of additional test functions. I had to use the following build settings.
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
ENABLE_TESTING_SEARCH_PATHS = YES
SYSTEM_FRAMEWORK_SEARCH_PATHS = $(CORRESPONDING_DEVICE_PLATFORM_DIR)/Developer/Library/Frameworks $(inherited)
This works by expanding the search path to find XCTest but this package named Hela I am not able to apply these same build settings in Package.swift. I know the CORRESPONDING_DEVICE_PLATFORM_DIR
build variable will not be defined so I have tried setting it to the correct path manually using using cSettings
and cxxSettings
but that also does not work.
Is there a way to make this work?
I made 2 changes to fix the problem.
First, I added XCTest as a linked framework in Package.swift in the Hela package. Second, I found that simply adding a Swift package to an Xcode project causes the primary build target to link the Hela package which links XCTest. Since that will only work with test targets linking that primary target should be removed. Instead only link the test target which will use the Hela package.
The details are covered on the issue on GitHub. See the commits for the changes.