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+
1315import Basics
1416import Commands
1517import PackageModel
1618import _InternalTestSupport
1719import 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