Skip to content

Commit 69c1632

Browse files
committed
Tests: Migrate and Augment Resources and ModuleMaps Tests
Migrate the ResourcesTests and ModuleMap Tests to Swift Testing and augment them to build the cross matrix of `debug` and `release` build configuration with `native` and `swiftbuild` build systems Relates to #8997
1 parent 52f7c41 commit 69c1632

File tree

4 files changed

+333
-182
lines changed

4 files changed

+333
-182
lines changed

Sources/_InternalTestSupport/SwiftTesting+Tags.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ extension Tag.FunctionalArea {
3535
@Tag public static var IndexMode: Tag
3636
@Tag public static var Sanitizer: Tag
3737
@Tag public static var LinkSwiftStaticStdlib: Tag
38+
@Tag public static var Metal: Tag
39+
@Tag public static var ModuleMaps: Tag
40+
@Tag public static var Resources: Tag
41+
3842
}
3943

4044
extension Tag.Feature {

Tests/BuildMetalTests/BuildMetalTests.swift

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,33 @@ import _InternalTestSupport
1414
import Testing
1515
import Basics
1616
import Foundation
17+
import struct SPMBuildCore.BuildSystemProvider
18+
import enum PackageModel.BuildConfiguration
1719
#if os(macOS)
1820
import Metal
1921
#endif
2022

21-
@Suite
23+
@Suite(
24+
.tags(
25+
.FunctionalArea.Metal,
26+
)
27+
)
2228
struct BuildMetalTests {
2329

24-
#if os(macOS)
2530
@Test(
2631
.disabled("Require downloadable Metal toolchain"),
27-
.tags(.TestSize.large),
32+
.tags(
33+
.TestSize.large,
34+
),
2835
.requireHostOS(.macOS),
29-
arguments: getBuildData(for: [.swiftbuild])
36+
arguments: BuildConfiguration.allCases,
3037
)
31-
func simpleLibrary(data: BuildData) async throws {
32-
let buildSystem = data.buildSystem
33-
let configuration = data.config
34-
38+
func simpleLibrary(
39+
config: BuildConfiguration,
40+
) async throws {
41+
let buildSystem = BuildSystemProvider.Kind.swiftbuild
42+
let configuration = config
43+
3544
try await fixture(name: "Metal/SimpleLibrary") { fixturePath in
3645

3746
// Build the package
@@ -41,7 +50,7 @@ struct BuildMetalTests {
4150
buildSystem: buildSystem,
4251
throwIfCommandFails: true
4352
)
44-
53+
4554
// Get the bin path
4655
let (binPathOutput, _) = try await executeSwiftBuild(
4756
fixturePath,
@@ -50,22 +59,23 @@ struct BuildMetalTests {
5059
buildSystem: buildSystem,
5160
throwIfCommandFails: true
5261
)
53-
62+
5463
let binPath = try AbsolutePath(validating: binPathOutput.trimmingCharacters(in: .whitespacesAndNewlines))
55-
64+
5665
// Check that default.metallib exists
5766
let metallibPath = binPath.appending(components:["MyRenderer_MyRenderer.bundle", "Contents", "Resources", "default.metallib"])
5867
#expect(
5968
localFileSystem.exists(metallibPath),
6069
"Expected default.metallib to exist at \(metallibPath)"
6170
)
6271

72+
#if os(macOS)
6373
// Verify we can load the metal library
6474
let device = try #require(MTLCreateSystemDefaultDevice())
6575
let library = try device.makeLibrary(URL: URL(fileURLWithPath: metallibPath.pathString))
6676

6777
#expect(library.functionNames.contains("simpleVertexShader"))
78+
#endif
6879
}
6980
}
70-
#endif
7181
}

Tests/FunctionalTests/ModuleMapTests.swift

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,45 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2026 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
99
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Foundation
14+
1315
import Basics
1416
import Commands
1517
import PackageModel
1618
import _InternalTestSupport
1719
import Workspace
18-
import XCTest
20+
import Testing
21+
22+
import struct SPMBuildCore.BuildSystemProvider
1923

20-
final class ModuleMapsTestCase: XCTestCase {
21-
private func fixtureXCTest(
24+
@Suite(
25+
.serialized, // crash occurs when executed in parallel. needs investigation
26+
.tags(
27+
.FunctionalArea.ModuleMaps,
28+
),
29+
)
30+
struct ModuleMapsTestCase {
31+
private func localFixture(
2232
name: String,
2333
cModuleName: String,
2434
rootpkg: String,
35+
buildSystem: BuildSystemProvider.Kind,
36+
config: BuildConfiguration,
2537
body: @escaping (AbsolutePath, [String]) async throws -> Void
2638
) async throws {
27-
try await _InternalTestSupport.fixtureXCTest(name: name) { fixturePath in
39+
try await fixture(name: name) { fixturePath in
2840
let input = fixturePath.appending(components: cModuleName, "C", "foo.c")
29-
let triple = try UserToolchain.default.targetTriple
30-
let outdir = fixturePath.appending(components: rootpkg, ".build", triple.platformBuildPathComponent, "debug")
41+
let outdir = try fixturePath.appending(components: [rootpkg] + buildSystem.binPath(for: config))
3142
try makeDirectories(outdir)
43+
let triple = try UserToolchain.default.targetTriple
3244
let output = outdir.appending("libfoo\(triple.dynamicLibraryExtension)")
3345
try await AsyncProcess.checkNonZeroExit(args: executableName("clang"), "-shared", input.pathString, "-o", output.pathString)
3446

@@ -41,53 +53,80 @@ final class ModuleMapsTestCase: XCTestCase {
4153
}
4254
}
4355

44-
func testDirectDependency() async throws {
45-
try XCTSkipOnWindows(because: "fails to build on windows (maybe not supported?)")
46-
try await fixtureXCTest(name: "ModuleMaps/Direct", cModuleName: "CFoo", rootpkg: "App") { fixturePath, Xld in
47-
await XCTAssertBuilds(
48-
fixturePath.appending("App"),
49-
Xld: Xld,
50-
buildSystem: .native,
51-
)
56+
@Test(
57+
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms),
58+
)
59+
func directDependency(
60+
buildData: BuildData,
61+
) async throws {
62+
let configuration = buildData.config
63+
let buildSystem = buildData.buildSystem
64+
try await withKnownIssue(isIntermittent: true) {
65+
try await localFixture(
66+
name: "ModuleMaps/Direct",
67+
cModuleName: "CFoo",
68+
rootpkg: "App",
69+
buildSystem: buildSystem,
70+
config: configuration,
71+
) { fixturePath, Xld in
72+
try await executeSwiftBuild(
73+
fixturePath.appending("App"),
74+
configuration: configuration,
75+
Xld: Xld,
76+
buildSystem: buildSystem,
77+
)
5278

53-
let triple = try UserToolchain.default.targetTriple
54-
let targetPath = fixturePath.appending(components: "App", ".build", triple.platformBuildPathComponent)
55-
let debugout = try await AsyncProcess.checkNonZeroExit(
56-
args: targetPath.appending(components: "debug", "App").pathString
57-
)
58-
XCTAssertEqual(debugout, "123\n")
59-
let releaseout = try await AsyncProcess.checkNonZeroExit(
60-
args: targetPath.appending(components: "release", "App").pathString
61-
)
62-
XCTAssertEqual(releaseout, "123\n")
79+
let executable = try fixturePath.appending(components: ["App"] + buildSystem.binPath(for: configuration) + ["App"])
80+
let releaseout = try await AsyncProcess.checkNonZeroExit(
81+
args: executable.pathString
82+
)
83+
#expect(releaseout == "123\n")
84+
}
85+
} when: {
86+
ProcessInfo.hostOperatingSystem == .windows
87+
|| (buildSystem == .swiftbuild && configuration == .release)
6388
}
6489
}
6590

66-
func testTransitiveDependency() async throws {
67-
try XCTSkipOnWindows(because: "fails to build on windows (maybe not supported?)")
68-
try await fixtureXCTest(name: "ModuleMaps/Transitive", cModuleName: "packageD", rootpkg: "packageA") { fixturePath, Xld in
69-
await XCTAssertBuilds(
70-
fixturePath.appending("packageA"),
71-
Xld: Xld,
72-
buildSystem: .native,
73-
)
74-
75-
func verify(_ conf: String) async throws {
76-
let triple = try UserToolchain.default.targetTriple
91+
@Test(
92+
.serialized, // crash occurs when executed in parallel. needs investigation
93+
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms),
94+
)
95+
func transitiveDependency(
96+
buildData: BuildData,
97+
) async throws {
98+
let configuration = buildData.config
99+
let buildSystem = buildData.buildSystem
100+
try await withKnownIssue(isIntermittent: true) {
101+
try await localFixture(
102+
name: "ModuleMaps/Transitive",
103+
cModuleName: "packageD",
104+
rootpkg: "packageA",
105+
buildSystem: buildSystem,
106+
config: configuration,
107+
) { fixturePath, Xld in
108+
try await executeSwiftBuild(
109+
fixturePath.appending("packageA"),
110+
configuration: configuration,
111+
Xld: Xld,
112+
buildSystem: buildSystem,
113+
)
114+
115+
let executable = try fixturePath.appending(components: ["packageA"] + buildSystem.binPath(for: configuration) + ["packageA"])
77116
let out = try await AsyncProcess.checkNonZeroExit(
78-
args: fixturePath.appending(components: "packageA", ".build", triple.platformBuildPathComponent, conf, "packageA").pathString
117+
args: executable.pathString
79118
)
80-
XCTAssertEqual(out, """
119+
#expect(out == """
81120
calling Y.bar()
82121
Y.bar() called
83122
X.foo() called
84123
123
85124
86125
""")
87126
}
88-
89-
try await verify("debug")
90-
try await verify("release")
127+
} when: {
128+
ProcessInfo.hostOperatingSystem == .windows
129+
|| (buildSystem == .swiftbuild && configuration == .release)
91130
}
92131
}
93132
}

0 commit comments

Comments
 (0)