Skip to content

Commit dc09a0e

Browse files
Support the latest SwiftPM producing .xctest for test products (#512)
swiftlang/swift-package-manager#8254 introduced a change to produce `.xctest` files for test products instead of `.wasm` files. This change updates the CartonTestPlugin to support both formats and use the `.xctest` file if it is available.
1 parent 57ab2e7 commit dc09a0e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Plugins/CartonTestPlugin/CartonTestPluginCommand.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ struct CartonTestPluginCommand: CommandPlugin {
6565
let options = try Options.parse(from: &extractor)
6666
let buildDirectory = try self.buildDirectory(context: context)
6767

68-
let testProductArtifactPath: String
68+
var testProductArtifactPath: String
6969
if let prebuiltTestBundlePath = options.prebuiltTestBundlePath {
7070
testProductArtifactPath = prebuiltTestBundlePath
7171
} else {
72-
let wasmFileName = "\(productName).wasm"
73-
testProductArtifactPath = buildDirectory.appending(subpath: wasmFileName).string
7472
#if compiler(>=5.10)
7573
var buildParameters = PackageManager.BuildParameters()
7674
options.environment.applyBuildParameters(&buildParameters)
@@ -80,10 +78,23 @@ struct CartonTestPluginCommand: CommandPlugin {
8078
guard build.succeeded else {
8179
throw Error("Failed to build test product: \(build.logText)")
8280
}
83-
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {
81+
var foundArtifactPath: String?
82+
for fileExtension in ["xctest", "wasm"] {
83+
let wasmFileName = "\(productName).\(fileExtension)"
84+
testProductArtifactPath = buildDirectory.appending(subpath: wasmFileName).string
85+
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {
86+
continue
87+
}
88+
foundArtifactPath = testProductArtifactPath
89+
break
90+
}
91+
guard let artifactPath = foundArtifactPath else {
8492
throw Error("Product \(productName) did not produce \(buildDirectory)!?")
8593
}
94+
testProductArtifactPath = artifactPath
8695
#else
96+
let wasmFileName = "\(productName).wasm"
97+
testProductArtifactPath = buildDirectory.appending(subpath: wasmFileName).string
8798
// NOTE: Old SwiftPM does not allow to build *only tests* from plugin, so we expect
8899
// the test product to be built already by external wrapper command.
89100
guard FileManager.default.fileExists(atPath: testProductArtifactPath) else {

0 commit comments

Comments
 (0)