Hello,
I'm having issues porting one of my Cocoapods to SwiftPM. The package contains two products "MyPackage" and "MyPackageTestSupport".
The key thing here is that "MyPackageTestSupport" imports "MyPackage" using @testability
and relies on the ENABLE_TESTABILITY=YES
build setting. The target "MyPackageTests" then imports "MyPackageTestSupport". This allows test targets to import the test support package and use the helpers and test factory methods it provides which can use the internal initialisers of the types defined in "MyPackage". Other 3rd party consumers of "MyPackage" can also use "MyPackageTestSupport" on the test targets to create test instances of types they wouldn't have access to otherwise.
This was doable on Cocoapods just be adding setting s.pod_target_xcconfig = { 'ENABLE_TESTABILITY' => 'YES' }
.
Is there a way to ENABLE_TESTABILITY
for products created via SwiftPM, an example package file is shown below.
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyPackage",
platforms: [
.iOS(.v11),
.macOS(.v10_14)
],
products: [
.library(
name: "MyPackage",
targets: ["MyPackage"]),
.library(
name: "MyPackageTestSupport",
targets: ["MyPackageTestSupport"]),
],
targets: [
.target(
name: "MyPackage",
dependencies: []),
.target(
name: "MyPackageTestSupport",
dependencies: ["iOS-Networking"]),
.testTarget(
name: "MyPackageTests",
dependencies: [
"MyPackage",
"MyPackageTestSupport"]),
]
)
Currently when building for archive an Xcode project that has "MyPackage" as a dependency I'm getting the error "Module 'MyPackage' was not compiled for testing" in the TestSupport files.