diff --git a/Fixtures/Miscellaneous/EchoExecutable/Package.swift b/Fixtures/Miscellaneous/EchoExecutable/Package.swift index ec5a31ab18c..13570183d6d 100644 --- a/Fixtures/Miscellaneous/EchoExecutable/Package.swift +++ b/Fixtures/Miscellaneous/EchoExecutable/Package.swift @@ -7,5 +7,6 @@ let package = Package( .executable(name: "secho", targets: ["secho"]) ], targets: [ - .target(name: "secho", dependencies: []) - ]) \ No newline at end of file + .target(name: "secho", dependencies: []), + .testTarget(name: "TestSuite") + ]) diff --git a/Fixtures/Miscellaneous/EchoExecutable/Tests/TestSuite/Tests.swift b/Fixtures/Miscellaneous/EchoExecutable/Tests/TestSuite/Tests.swift new file mode 100644 index 00000000000..8bf929fa594 --- /dev/null +++ b/Fixtures/Miscellaneous/EchoExecutable/Tests/TestSuite/Tests.swift @@ -0,0 +1,7 @@ +import XCTest + +final class TestCase: XCTestCase { + func testFoo() { + XCTAssertTrue(true) + } +} diff --git a/Fixtures/Miscellaneous/EchoExecutable/echo.sh b/Fixtures/Miscellaneous/EchoExecutable/echo.sh index 86fa5e54ba2..40f21597c66 100755 --- a/Fixtures/Miscellaneous/EchoExecutable/echo.sh +++ b/Fixtures/Miscellaneous/EchoExecutable/echo.sh @@ -1,3 +1,4 @@ #!/bin/sh +echo sentinel echo "$@" diff --git a/Fixtures/Miscellaneous/EchoExecutable/toolset.json b/Fixtures/Miscellaneous/EchoExecutable/toolset.json index 8e624fd63f7..1092b5740c3 100644 --- a/Fixtures/Miscellaneous/EchoExecutable/toolset.json +++ b/Fixtures/Miscellaneous/EchoExecutable/toolset.json @@ -1,5 +1,6 @@ { "debugger": { "path": "echo.sh" }, + "testRunner": { "path": "echo.sh" }, "schemaVersion" : "1.0", "rootPath" : "." } diff --git a/Sources/Commands/SwiftTestCommand.swift b/Sources/Commands/SwiftTestCommand.swift index e46c1f2bd9f..1fc6276b4f4 100644 --- a/Sources/Commands/SwiftTestCommand.swift +++ b/Sources/Commands/SwiftTestCommand.swift @@ -948,23 +948,31 @@ final class TestRunner { /// Constructs arguments to execute XCTest. private func args(forTestAt testPath: AbsolutePath) throws -> [String] { var args: [String] = [] + + if let runner = self.toolchain.swiftSDK.toolset.knownTools[.testRunner], let runnerPath = runner.path { + args.append(runnerPath.pathString) + args.append(contentsOf: runner.extraCLIOptions) + args.append(testPath.relative(to: localFileSystem.currentWorkingDirectory!).pathString) + args.append(contentsOf: self.additionalArguments) + } else { #if os(macOS) - switch library { - case .xctest: - guard let xctestPath = self.toolchain.xctestPath else { - throw TestError.xcodeNotInstalled + switch library { + case .xctest: + guard let xctestPath = self.toolchain.xctestPath else { + throw TestError.xcodeNotInstalled + } + args += [xctestPath.pathString] + case .swiftTesting: + let helper = try self.toolchain.getSwiftTestingHelper() + args += [helper.pathString, "--test-bundle-path", testPath.pathString] } - args += [xctestPath.pathString] - case .swiftTesting: - let helper = try self.toolchain.getSwiftTestingHelper() - args += [helper.pathString, "--test-bundle-path", testPath.pathString] + args += self.additionalArguments + args += [testPath.pathString] + #else + args += [testPath.pathString] + args += self.additionalArguments + #endif } - args += additionalArguments - args += [testPath.pathString] -#else - args += [testPath.pathString] - args += additionalArguments -#endif if library == .swiftTesting { // HACK: tell the test bundle/executable that we want to run Swift Testing, not XCTest. diff --git a/Sources/SPMBuildCore/BuildParameters/BuildParameters.swift b/Sources/SPMBuildCore/BuildParameters/BuildParameters.swift index 93c0240ae42..df01c6758ca 100644 --- a/Sources/SPMBuildCore/BuildParameters/BuildParameters.swift +++ b/Sources/SPMBuildCore/BuildParameters/BuildParameters.swift @@ -302,9 +302,6 @@ public struct BuildParameters: Encodable { case .library(.automatic), .plugin: fatalError() case .test: - guard !self.triple.isWasm else { - return try RelativePath(validating: "\(product.name).wasm") - } let base = "\(product.name).xctest" if self.triple.isDarwin() { return try RelativePath(validating: "\(base)/Contents/MacOS/\(product.name)") diff --git a/Tests/BuildTests/CrossCompilationBuildPlanTests.swift b/Tests/BuildTests/CrossCompilationBuildPlanTests.swift index 4b006cd7af9..28321da4df8 100644 --- a/Tests/BuildTests/CrossCompilationBuildPlanTests.swift +++ b/Tests/BuildTests/CrossCompilationBuildPlanTests.swift @@ -210,7 +210,7 @@ final class CrossCompilationBuildPlanTests: XCTestCase { [ result.plan.destinationBuildParameters.toolchain.swiftCompilerPath.pathString, "-L", buildPath.pathString, - "-o", buildPath.appending(components: "PkgPackageTests.wasm").pathString, + "-o", buildPath.appending(components: "PkgPackageTests.xctest").pathString, "-module-name", "PkgPackageTests", "-emit-executable", "@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))", @@ -220,7 +220,7 @@ final class CrossCompilationBuildPlanTests: XCTestCase { ) let testPathExtension = try testBuildDescription.binaryPath.extension - XCTAssertEqual(testPathExtension, "wasm") + XCTAssertEqual(testPathExtension, "xctest") } func testMacros() async throws { diff --git a/Tests/CommandsTests/RunCommandTests.swift b/Tests/CommandsTests/RunCommandTests.swift index 21278007f7f..b15dd0bd216 100644 --- a/Tests/CommandsTests/RunCommandTests.swift +++ b/Tests/CommandsTests/RunCommandTests.swift @@ -48,9 +48,8 @@ final class RunCommandTests: CommandsTestCase { ["--toolset", "\(fixturePath)/toolset.json"], packagePath: fixturePath) // We only expect tool's output on the stdout stream. - XCTAssertMatch(stdout, .contains(""" - \(fixturePath)/.build - """)) + XCTAssertMatch(stdout, .contains("\(fixturePath)/.build")) + XCTAssertMatch(stdout, .contains("sentinel")) // swift-build-tool output should go to stderr. XCTAssertMatch(stderr, .regex("Compiling")) diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 033e6e5bf1e..6ce6ad9511e 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -36,6 +36,24 @@ final class TestCommandTests: CommandsTestCase { XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout) } + // `runner.sh` script from the toolset won't work on Windows + #if !os(Windows) + func testToolsetRunner() async throws { + try await fixture(name: "Miscellaneous/EchoExecutable") { fixturePath in + let (stdout, stderr) = try await SwiftPM.Test.execute( + ["--toolset", "\(fixturePath)/toolset.json"], packagePath: fixturePath) + + // We only expect tool's output on the stdout stream. + XCTAssertMatch(stdout, .contains("sentinel")) + XCTAssertMatch(stdout, .contains("\(fixturePath)")) + + // swift-build-tool output should go to stderr. + XCTAssertMatch(stderr, .regex("Compiling")) + XCTAssertMatch(stderr, .contains("Linking")) + } + } + #endif + func testNumWorkersParallelRequirement() async throws { #if !os(macOS) // Running swift-test fixtures on linux is not yet possible.