Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass all arguments when initing testing parameters in swift build #7396

Merged
merged 1 commit into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
}