Skip to content

test helpers: do not use default build system #8975

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import class Foundation.FileManager
import class Foundation.ProcessInfo
import class PackageModel.UserToolchain
import Basics
import Testing

Expand All @@ -29,6 +30,13 @@ extension Trait where Self == Testing.ConditionTrait {
}
}

/// Enabled only if toolchain support swift concurrency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a sidenote I think we're on new enough versions of macOS and Xcode everywhere in CI now to drop this entirely

public static var requiresSwiftConcurrencySupport: Self {
enabled("skipping because test environment doesn't support concurrency") {
(try? UserToolchain.default)!.supportsSwiftConcurrency()
}
}

/// Skip test unconditionally
public static func skip(_ comment: Comment? = nil) -> Self {
disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true }
Expand Down
8 changes: 4 additions & 4 deletions Sources/_InternalTestSupport/XCTAssertHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public func XCTAssertBuilds(
env: Environment? = nil,
file: StaticString = #file,
line: UInt = #line,
buildSystem: BuildSystemProvider.Kind = .native
buildSystem: BuildSystemProvider.Kind,
) async {
for conf in configurations {
await XCTAssertAsyncNoThrow(
Expand Down Expand Up @@ -184,7 +184,7 @@ public func XCTAssertSwiftTest(
env: Environment? = nil,
file: StaticString = #file,
line: UInt = #line,
buildSystem: BuildSystemProvider.Kind = .native
buildSystem: BuildSystemProvider.Kind,
) async {
await XCTAssertAsyncNoThrow(
try await executeSwiftTest(
Expand All @@ -211,7 +211,7 @@ public func XCTAssertBuildFails(
env: Environment? = nil,
file: StaticString = #file,
line: UInt = #line,
buildSystem: BuildSystemProvider.Kind = .native
buildSystem: BuildSystemProvider.Kind,
) async -> CommandExecutionError? {
var failure: CommandExecutionError? = nil
await XCTAssertThrowsCommandExecutionError(
Expand Down Expand Up @@ -337,6 +337,6 @@ public func XCTExhibitsGitHubIssue(_ number: Int) throws {

try XCTSkipIf(
ProcessInfo.processInfo.environment[envVar] != nil,
"https://github.com/swiftlang/swift-package-manager/issues/\(number): \(envVar)environment variable is set"
"https://github.com/swiftlang/swift-package-manager/issues/\(number): \(envVar) environment variable is set"
)
}
10 changes: 5 additions & 5 deletions Sources/_InternalTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public func executeSwiftBuild(
Xld: [String] = [],
Xswiftc: [String] = [],
env: Environment? = nil,
buildSystem: BuildSystemProvider.Kind = .native,
buildSystem: BuildSystemProvider.Kind,
throwIfCommandFails: Bool = true,
) async throws -> (stdout: String, stderr: String) {
let args = swiftArgs(
Expand All @@ -419,7 +419,7 @@ public func executeSwiftRun(
Xld: [String] = [],
Xswiftc: [String] = [],
env: Environment? = nil,
buildSystem: BuildSystemProvider.Kind
buildSystem: BuildSystemProvider.Kind,
) async throws -> (stdout: String, stderr: String) {
var args = swiftArgs(
configuration: configuration,
Expand All @@ -444,7 +444,7 @@ public func executeSwiftPackage(
Xld: [String] = [],
Xswiftc: [String] = [],
env: Environment? = nil,
buildSystem: BuildSystemProvider.Kind = .native
buildSystem: BuildSystemProvider.Kind,
) async throws -> (stdout: String, stderr: String) {
let args = swiftArgs(
configuration: configuration,
Expand All @@ -466,7 +466,7 @@ public func executeSwiftPackageRegistry(
Xld: [String] = [],
Xswiftc: [String] = [],
env: Environment? = nil,
buildSystem: BuildSystemProvider.Kind = .native
buildSystem: BuildSystemProvider.Kind,
) async throws -> (stdout: String, stderr: String) {
let args = swiftArgs(
configuration: configuration,
Expand All @@ -489,7 +489,7 @@ public func executeSwiftTest(
Xswiftc: [String] = [],
env: Environment? = nil,
throwIfCommandFails: Bool = false,
buildSystem: BuildSystemProvider.Kind = .native
buildSystem: BuildSystemProvider.Kind,
) async throws -> (stdout: String, stderr: String) {
let args = swiftArgs(
configuration: configuration,
Expand Down
6 changes: 3 additions & 3 deletions Tests/BuildTests/BuildSystemDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class BuildSystemDelegateTests: XCTestCase {
// These linker diagnostics are only produced on macOS.
try XCTSkipIf(true, "test is only supported on macOS")
#endif
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
XCTAssertTrue(fullLog.contains("ld: warning: search path 'foobar' not found"), "log didn't contain expected linker diagnostics")
}
}
Expand All @@ -40,11 +40,11 @@ final class BuildSystemDelegateTests: XCTestCase {
let executableExt = ""
#endif
try await fixtureXCTest(name: "Miscellaneous/TestableExe") { fixturePath in
_ = try await executeSwiftBuild(fixturePath)
_ = try await executeSwiftBuild(fixturePath, buildSystem: .native)
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1\(executableExt)")
XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'")
try localFileSystem.removeFileTree(execPath)
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
XCTAssertFalse(fullLog.contains("replacing existing signature"), "log contained non-fatal codesigning messages")
}
}
Expand Down
22 changes: 15 additions & 7 deletions Tests/BuildTests/IncrementalBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class IncrementalBuildTests: XCTestCase {
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
try await fixtureXCTest(name: "CFamilyTargets/CLibrarySources") { fixturePath in
// Build it once and capture the log (this will be a full build).
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)

// Check various things that we expect to see in the full build log.
// FIXME: This is specific to the format of the log output, which
Expand All @@ -64,15 +64,15 @@ final class IncrementalBuildTests: XCTestCase {
let llbuildContents1: String = try localFileSystem.readFileContents(llbuildManifest)

// Now build again. This should be an incremental build.
let (log2, _) = try await executeSwiftBuild(fixturePath)
let (log2, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
XCTAssertMatch(log2, .contains("Compiling CLibrarySources Foo.c"))

// Read the second llbuild manifest.
let llbuildContents2: String = try localFileSystem.readFileContents(llbuildManifest)

// Now build again without changing anything. This should be a null
// build.
let (log3, _) = try await executeSwiftBuild(fixturePath)
let (log3, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
XCTAssertNoMatch(log3, .contains("Compiling CLibrarySources Foo.c"))

// Read the third llbuild manifest.
Expand All @@ -91,7 +91,7 @@ final class IncrementalBuildTests: XCTestCase {
)

// Now build again. This should be an incremental build.
let (log4, _) = try await executeSwiftBuild(fixturePath)
let (log4, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
XCTAssertMatch(log4, .contains("Compiling CLibrarySources Foo.c"))
}
}
Expand All @@ -101,7 +101,7 @@ final class IncrementalBuildTests: XCTestCase {
try await fixtureXCTest(name: "ValidLayouts/SingleModule/Library") { fixturePath in
@discardableResult
func build() async throws -> String {
return try await executeSwiftBuild(fixturePath).stdout
return try await executeSwiftBuild(fixturePath, buildSystem: .native).stdout
}

// Perform a full build.
Expand Down Expand Up @@ -135,7 +135,11 @@ final class IncrementalBuildTests: XCTestCase {
try await fixtureXCTest(name: "ValidLayouts/SingleModule/Library") { fixturePath in
@discardableResult
func build() async throws -> String {
return try await executeSwiftBuild(fixturePath, extraArgs: ["--disable-build-manifest-caching"]).stdout
return try await executeSwiftBuild(
fixturePath,
extraArgs: ["--disable-build-manifest-caching"],
buildSystem: .native,
).stdout
}

// Perform a full build.
Expand Down Expand Up @@ -166,7 +170,11 @@ final class IncrementalBuildTests: XCTestCase {

let newSdkPathStr = "/tmp/../\(sdkPathStr)"
// Perform a full build again because SDK changed.
let log1 = try await executeSwiftBuild(fixturePath, env: ["SDKROOT": newSdkPathStr]).stdout
let log1 = try await executeSwiftBuild(
fixturePath,
env: ["SDKROOT": newSdkPathStr],
buildSystem: .native,
).stdout
XCTAssertMatch(log1, .contains("Compiling Library"))
}
#endif
Expand Down
14 changes: 11 additions & 3 deletions Tests/BuildTests/PluginsBuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class PluginsBuildPlanTests: XCTestCase {
try XCTSkipOnWindows(because: "Fails to build the project to due to incorrect Path handling. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511")

try await fixtureXCTest(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in
let (stdout, _) = try await executeSwiftBuild(fixturePath)
let (stdout, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
XCTAssertMatch(stdout, .contains("Build complete!"))
// FIXME: This is temporary until build of plugin tools is extracted into its own command.
XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugin-tools.db"))))
Expand Down Expand Up @@ -49,7 +49,11 @@ final class PluginsBuildPlanTests: XCTestCase {

// By default, plugin dependencies are built for the host platform
try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["-v", "build-plugin-dependency"])
let (stdout, stderr) = try await executeSwiftPackage(
fixturePath,
extraArgs: ["-v", "build-plugin-dependency"],
buildSystem: .native,
)
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub"))
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!"))
XCTAssertTrue(
Expand All @@ -66,7 +70,11 @@ final class PluginsBuildPlanTests: XCTestCase {

// When cross compiling the final product, plugin dependencies should still be built for the host
try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"])
let (stdout, stderr) = try await executeSwiftPackage(
fixturePath,
extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"],
buildSystem: .native,
)
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub"))
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!"))
XCTAssertTrue(
Expand Down
Loading