diff --git a/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Package.swift b/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Package.swift new file mode 100644 index 00000000000..d7749959468 --- /dev/null +++ b/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Package.swift @@ -0,0 +1,9 @@ +// swift-tools-version:5.10 +import PackageDescription + +let package = Package( + name: "IgnoresLinuxMain", + targets: [ + .testTarget(name: "IgnoresLinuxMainTests"), + ] +) diff --git a/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Tests/IgnoresLinuxMainTests/SomeTest.swift b/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Tests/IgnoresLinuxMainTests/SomeTest.swift new file mode 100644 index 00000000000..dec36ed294c --- /dev/null +++ b/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Tests/IgnoresLinuxMainTests/SomeTest.swift @@ -0,0 +1,5 @@ +import XCTest + +final class SomeTests: XCTestCase { + func testSomething() {} +} diff --git a/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Tests/LinuxMain.swift b/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Tests/LinuxMain.swift new file mode 100644 index 00000000000..f7b651fc7aa --- /dev/null +++ b/Fixtures/Miscellaneous/TestDiscovery/IgnoresLinuxMain/Tests/LinuxMain.swift @@ -0,0 +1 @@ +fatalError("Should not use the contents of LinuxMain.swift") diff --git a/Sources/Commands/SwiftBuildCommand.swift b/Sources/Commands/SwiftBuildCommand.swift index e55f533dcce..6d74dd63c25 100644 --- a/Sources/Commands/SwiftBuildCommand.swift +++ b/Sources/Commands/SwiftBuildCommand.swift @@ -154,6 +154,11 @@ package struct SwiftBuildCommand: AsyncSwiftCommand { buildParameters.testingParameters = .init( configuration: buildParameters.configuration, targetTriple: buildParameters.triple, + enableCodeCoverage: buildParameters.testingParameters.enableCodeCoverage, + enableTestability: buildParameters.testingParameters.enableTestability, + experimentalTestOutput: buildParameters.testingParameters.experimentalTestOutput, + forceTestDiscovery: globalOptions.build.enableTestDiscovery, + testEntryPointPath: globalOptions.build.testEntryPointPath, library: library ) try build(swiftCommandState, subset: subset, buildParameters: buildParameters) diff --git a/Tests/CommandsTests/BuildCommandTests.swift b/Tests/CommandsTests/BuildCommandTests.swift index b54c6726dbb..9e3a2cc1b3b 100644 --- a/Tests/CommandsTests/BuildCommandTests.swift +++ b/Tests/CommandsTests/BuildCommandTests.swift @@ -42,10 +42,14 @@ final class BuildCommandTests: CommandsTestCase { try SwiftPM.Build.execute(args, packagePath: packagePath, env: environment) } - func build(_ args: [String], packagePath: AbsolutePath? = nil, isRelease: Bool = false) throws -> BuildResult { + func build(_ args: [String], packagePath: AbsolutePath? = nil, isRelease: Bool = false, cleanAfterward: Bool = true) throws -> BuildResult { let buildConfigurationArguments = isRelease ? ["-c", "release"] : [] let (stdout, stderr) = try execute(args + buildConfigurationArguments, packagePath: packagePath) - defer { try! SwiftPM.Package.execute(["clean"], packagePath: packagePath) } + defer { + if cleanAfterward { + try! SwiftPM.Package.execute(["clean"], packagePath: packagePath) + } + } let (binPathOutput, _) = try execute( ["--show-bin-path"] + buildConfigurationArguments, packagePath: packagePath @@ -644,4 +648,20 @@ final class BuildCommandTests: CommandsTestCase { XCTAssertNoMatch(buildResult.stdout, .contains("codesign --force --sign - --entitlements")) } } + +//#if !canImport(Darwin) + func testIgnoresLinuxMain() throws { + try fixture(name: "Miscellaneous/TestDiscovery/IgnoresLinuxMain") { fixturePath in + let buildResult = try self.build(["-v", "--build-tests", "--enable-test-discovery"], packagePath: fixturePath, cleanAfterward: false) + let testBinaryPath = buildResult.binPath.appending("IgnoresLinuxMainPackageTests.xctest") + + let processTerminated = expectation(description: "Process terminated") + _ = try Process.run(testBinaryPath.asURL, arguments: [] ) { process in + XCTAssertEqual(process.terminationStatus, EXIT_SUCCESS) + processTerminated.fulfill() + } + wait(for: [processTerminated], timeout: .infinity) + } + } +//#endif }