Skip to content

Commit

Permalink
Pass all arguments when initing testing parameters in swift build.
Browse files Browse the repository at this point in the history
Resolves #7389.
  • Loading branch information
grynspan committed Mar 6, 2024
1 parent a5f9b6c commit e948488
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
@@ -0,0 +1,9 @@
// swift-tools-version:5.10
import PackageDescription

let package = Package(
name: "IgnoresLinuxMain",
targets: [
.testTarget(name: "IgnoresLinuxMainTests"),
]
)
@@ -0,0 +1,5 @@
import XCTest

final class SomeTests: XCTestCase {
func testSomething() {}
}
@@ -0,0 +1 @@
fatalError("Should not use the contents of LinuxMain.swift")
5 changes: 5 additions & 0 deletions Sources/Commands/SwiftBuildCommand.swift
Expand Up @@ -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)
Expand Down
24 changes: 22 additions & 2 deletions Tests/CommandsTests/BuildCommandTests.swift
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit e948488

Please sign in to comment.