Skip to content

Commit 3a9edce

Browse files
committed
test helpers: do not use default build system
Many of the executeSwift* command helpers accept a build system provider, which was defaulted to the native build system. Since we are augmenting the tests to also run against the SwiftBuild, setting a default value may lead to an undesirable test behaviour. Update all the executeSwift* commands to no set a default build system provider.
1 parent 5c57a39 commit 3a9edce

23 files changed

+1163
-412
lines changed

Sources/_InternalTestSupport/SwiftTesting+TraitConditional.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import class Foundation.FileManager
1313
import class Foundation.ProcessInfo
14+
import class PackageModel.UserToolchain
1415
import Basics
1516
import Testing
1617

@@ -29,6 +30,13 @@ extension Trait where Self == Testing.ConditionTrait {
2930
}
3031
}
3132

33+
/// Enabled only if toolchain support swift concurrency
34+
public static var requiresSwiftConcurrencySupport: Self {
35+
enabled("skipping because test environment doesn't support concurrency") {
36+
(try? UserToolchain.default)!.supportsSwiftConcurrency()
37+
}
38+
}
39+
3240
/// Skip test unconditionally
3341
public static func skip(_ comment: Comment? = nil) -> Self {
3442
disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true }

Sources/_InternalTestSupport/XCTAssertHelpers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public func XCTAssertBuilds(
154154
env: Environment? = nil,
155155
file: StaticString = #file,
156156
line: UInt = #line,
157-
buildSystem: BuildSystemProvider.Kind = .native
157+
buildSystem: BuildSystemProvider.Kind,
158158
) async {
159159
for conf in configurations {
160160
await XCTAssertAsyncNoThrow(
@@ -184,7 +184,7 @@ public func XCTAssertSwiftTest(
184184
env: Environment? = nil,
185185
file: StaticString = #file,
186186
line: UInt = #line,
187-
buildSystem: BuildSystemProvider.Kind = .native
187+
buildSystem: BuildSystemProvider.Kind,
188188
) async {
189189
await XCTAssertAsyncNoThrow(
190190
try await executeSwiftTest(
@@ -211,7 +211,7 @@ public func XCTAssertBuildFails(
211211
env: Environment? = nil,
212212
file: StaticString = #file,
213213
line: UInt = #line,
214-
buildSystem: BuildSystemProvider.Kind = .native
214+
buildSystem: BuildSystemProvider.Kind,
215215
) async -> CommandExecutionError? {
216216
var failure: CommandExecutionError? = nil
217217
await XCTAssertThrowsCommandExecutionError(

Sources/_InternalTestSupport/misc.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public func executeSwiftBuild(
395395
Xld: [String] = [],
396396
Xswiftc: [String] = [],
397397
env: Environment? = nil,
398-
buildSystem: BuildSystemProvider.Kind = .native,
398+
buildSystem: BuildSystemProvider.Kind,
399399
throwIfCommandFails: Bool = true,
400400
) async throws -> (stdout: String, stderr: String) {
401401
let args = swiftArgs(
@@ -419,7 +419,7 @@ public func executeSwiftRun(
419419
Xld: [String] = [],
420420
Xswiftc: [String] = [],
421421
env: Environment? = nil,
422-
buildSystem: BuildSystemProvider.Kind
422+
buildSystem: BuildSystemProvider.Kind,
423423
) async throws -> (stdout: String, stderr: String) {
424424
var args = swiftArgs(
425425
configuration: configuration,
@@ -444,7 +444,7 @@ public func executeSwiftPackage(
444444
Xld: [String] = [],
445445
Xswiftc: [String] = [],
446446
env: Environment? = nil,
447-
buildSystem: BuildSystemProvider.Kind = .native
447+
buildSystem: BuildSystemProvider.Kind,
448448
) async throws -> (stdout: String, stderr: String) {
449449
let args = swiftArgs(
450450
configuration: configuration,
@@ -466,7 +466,7 @@ public func executeSwiftPackageRegistry(
466466
Xld: [String] = [],
467467
Xswiftc: [String] = [],
468468
env: Environment? = nil,
469-
buildSystem: BuildSystemProvider.Kind = .native
469+
buildSystem: BuildSystemProvider.Kind,
470470
) async throws -> (stdout: String, stderr: String) {
471471
let args = swiftArgs(
472472
configuration: configuration,
@@ -489,7 +489,7 @@ public func executeSwiftTest(
489489
Xswiftc: [String] = [],
490490
env: Environment? = nil,
491491
throwIfCommandFails: Bool = false,
492-
buildSystem: BuildSystemProvider.Kind = .native
492+
buildSystem: BuildSystemProvider.Kind,
493493
) async throws -> (stdout: String, stderr: String) {
494494
let args = swiftArgs(
495495
configuration: configuration,

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
632632
let (stdout, stderr) = try await executeSwiftBuild(
633633
fixturePath.appending("appPkg"),
634634
extraArgs: ["--vv"],
635-
buildSystem: buildSystemProvider
635+
buildSystem: buildSystemProvider,
636636
)
637637

638638
let out = if buildSystemProvider == .swiftbuild {
@@ -670,7 +670,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
670670
let (stdout, _) = try await executeSwiftBuild(
671671
fixturePath.appending("appPkg"),
672672
extraArgs: ["--vv"],
673-
buildSystem: .xcode
673+
buildSystem: .xcode,
674674
)
675675
XCTAssertMatch(stdout, .contains("-module-name Foo"))
676676
XCTAssertMatch(stdout, .contains("-module-name Zoo"))

Tests/BuildTests/BuildSystemDelegateTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class BuildSystemDelegateTests: XCTestCase {
2424
// These linker diagnostics are only produced on macOS.
2525
try XCTSkipIf(true, "test is only supported on macOS")
2626
#endif
27-
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
27+
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
2828
XCTAssertTrue(fullLog.contains("ld: warning: search path 'foobar' not found"), "log didn't contain expected linker diagnostics")
2929
}
3030
}
@@ -40,11 +40,11 @@ final class BuildSystemDelegateTests: XCTestCase {
4040
let executableExt = ""
4141
#endif
4242
try await fixtureXCTest(name: "Miscellaneous/TestableExe") { fixturePath in
43-
_ = try await executeSwiftBuild(fixturePath)
43+
_ = try await executeSwiftBuild(fixturePath, buildSystem: .native)
4444
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1\(executableExt)")
4545
XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'")
4646
try localFileSystem.removeFileTree(execPath)
47-
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
47+
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
4848
XCTAssertFalse(fullLog.contains("replacing existing signature"), "log contained non-fatal codesigning messages")
4949
}
5050
}

Tests/BuildTests/IncrementalBuildTests.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class IncrementalBuildTests: XCTestCase {
4242
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
4343
try await fixtureXCTest(name: "CFamilyTargets/CLibrarySources") { fixturePath in
4444
// Build it once and capture the log (this will be a full build).
45-
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
45+
let (fullLog, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native)
4646

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

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

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

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

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

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

107107
// Perform a full build.
@@ -135,7 +135,11 @@ final class IncrementalBuildTests: XCTestCase {
135135
try await fixtureXCTest(name: "ValidLayouts/SingleModule/Library") { fixturePath in
136136
@discardableResult
137137
func build() async throws -> String {
138-
return try await executeSwiftBuild(fixturePath, extraArgs: ["--disable-build-manifest-caching"]).stdout
138+
return try await executeSwiftBuild(
139+
fixturePath,
140+
extraArgs: ["--disable-build-manifest-caching"],
141+
buildSystem: .native,
142+
).stdout
139143
}
140144

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

167171
let newSdkPathStr = "/tmp/../\(sdkPathStr)"
168172
// Perform a full build again because SDK changed.
169-
let log1 = try await executeSwiftBuild(fixturePath, env: ["SDKROOT": newSdkPathStr]).stdout
173+
let log1 = try await executeSwiftBuild(
174+
fixturePath,
175+
env: ["SDKROOT": newSdkPathStr],
176+
buildSystem: .native,
177+
).stdout
170178
XCTAssertMatch(log1, .contains("Compiling Library"))
171179
}
172180
#endif

Tests/BuildTests/PluginsBuildPlanTests.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class PluginsBuildPlanTests: XCTestCase {
2121
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")
2222

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

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

6771
// When cross compiling the final product, plugin dependencies should still be built for the host
6872
try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
69-
let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"])
73+
let (stdout, stderr) = try await executeSwiftPackage(
74+
fixturePath,
75+
extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"],
76+
buildSystem: .native,
77+
)
7078
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub"))
7179
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!"))
7280
XCTAssertTrue(

0 commit comments

Comments
 (0)