@@ -16,94 +16,124 @@ import PackageGraph
16
16
import PackageLoading
17
17
import PackageModel
18
18
import SourceControl
19
+ import SPMBuildCore
19
20
import _InternalTestSupport
20
21
import Workspace
21
- import XCTest
22
+ import Testing
22
23
23
24
import class Basics. AsyncProcess
24
25
25
26
/// Asserts if a directory (recursively) contains a file.
26
- private func XCTAssertDirectoryContainsFile ( dir: AbsolutePath , filename: String , file : StaticString = #file , line : UInt = #line ) {
27
+ private func assertDirectoryContainsFile ( dir: AbsolutePath , filename: String , sourceLocation : SourceLocation = #_sourceLocation ) {
27
28
do {
28
29
for entry in try walk ( dir) {
29
30
if entry. basename == filename { return }
30
31
}
31
32
} catch {
32
- XCTFail ( " Failed with error \( error) " , file : file , line : line )
33
+ Issue . record ( StringError ( " Failed with error \( error) " ) , sourceLocation : sourceLocation )
33
34
}
34
- XCTFail ( " Directory \( dir) does not contain \( file ) " , file : file , line : line )
35
+ Issue . record ( StringError ( " Directory \( dir) does not contain \( filename ) " ) , sourceLocation : sourceLocation )
35
36
}
36
37
37
- final class CFamilyTargetTestCase : XCTestCase {
38
- func testCLibraryWithSpaces( ) async throws {
39
- try await fixture ( name: " CFamilyTargets/CLibraryWithSpaces " ) { fixturePath in
40
- await XCTAssertBuilds ( fixturePath)
41
- let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
42
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Bar.c.o " )
43
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
38
+ @Suite ( . serialized)
39
+ struct CFamilyTargetTestCase {
40
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
41
+ func testCLibraryWithSpaces( buildSystem: BuildSystemProvider . Kind ) async throws {
42
+ try await withKnownIssue ( " https://github.com/swiftlang/swift-build/issues/333 " ) {
43
+ try await fixture ( name: " CFamilyTargets/CLibraryWithSpaces " ) { fixturePath in
44
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
45
+ if buildSystem == . native {
46
+ let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
47
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Bar.c.o " )
48
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
49
+ }
50
+ }
51
+ } when: {
52
+ buildSystem == . swiftbuild
44
53
}
45
54
}
46
55
47
- func testCUsingCAndSwiftDep( ) async throws {
56
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
57
+ func testCUsingCAndSwiftDep( buildSystem: BuildSystemProvider . Kind ) async throws {
48
58
try await fixture ( name: " DependencyResolution/External/CUsingCDep " ) { fixturePath in
49
59
let packageRoot = fixturePath. appending ( " Bar " )
50
- await XCTAssertBuilds ( packageRoot)
51
- let debugPath = fixturePath. appending ( components: " Bar " , " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
52
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Sea.c.o " )
53
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
60
+ try await executeSwiftBuild ( packageRoot, buildSystem: buildSystem)
61
+ if buildSystem == . native {
62
+ let debugPath = fixturePath. appending ( components: " Bar " , " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
63
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Sea.c.o " )
64
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
65
+ }
54
66
let path = try SwiftPM . packagePath ( for: " Foo " , packageRoot: packageRoot)
55
- XCTAssertEqual ( try GitRepository ( path: path) . getTags ( ) , [ " 1.2.3 " ] )
67
+ #expect ( try GitRepository ( path: path) . getTags ( ) == [ " 1.2.3 " ] )
56
68
}
57
69
}
58
70
59
- func testModuleMapGenerationCases( ) async throws {
71
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
72
+ func testModuleMapGenerationCases( buildSystem: BuildSystemProvider . Kind ) async throws {
60
73
try await fixture ( name: " CFamilyTargets/ModuleMapGenerationCases " ) { fixturePath in
61
- await XCTAssertBuilds ( fixturePath)
62
- let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
63
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Jaz.c.o " )
64
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " main.swift.o " )
65
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " FlatInclude.c.o " )
66
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " UmbrellaHeader.c.o " )
74
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
75
+ if buildSystem == . native {
76
+ let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
77
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Jaz.c.o " )
78
+ assertDirectoryContainsFile ( dir: debugPath, filename: " main.swift.o " )
79
+ assertDirectoryContainsFile ( dir: debugPath, filename: " FlatInclude.c.o " )
80
+ assertDirectoryContainsFile ( dir: debugPath, filename: " UmbrellaHeader.c.o " )
81
+ }
67
82
}
68
83
}
69
-
70
- func testNoIncludeDirCheck( ) async throws {
84
+
85
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
86
+ func testNoIncludeDirCheck( buildSystem: BuildSystemProvider . Kind ) async throws {
71
87
try await fixture ( name: " CFamilyTargets/CLibraryNoIncludeDir " ) { fixturePath in
72
- await XCTAssertAsyncThrowsError ( try await executeSwiftBuild ( fixturePath ) , " This build should throw an error " ) { err in
73
- // The err.localizedDescription doesn't capture the detailed error string so interpolate
74
- let errStr = " \( err ) "
75
- let missingIncludeDirStr = " \( ModuleError . invalidPublicHeadersDirectory ( " Cfactorial " ) ) "
76
- XCTAssert ( errStr . contains ( missingIncludeDirStr ) )
88
+ var buildError : ( any Error ) ? = nil
89
+ do {
90
+ try await executeSwiftBuild ( fixturePath , buildSystem : buildSystem )
91
+ } catch {
92
+ buildError = error
77
93
}
94
+ guard let buildError else {
95
+ Issue . record ( StringError ( " This build should throw an error " ) )
96
+ return
97
+ }
98
+ // The err.localizedDescription doesn't capture the detailed error string so interpolate
99
+ let errStr = " \( buildError) "
100
+ let missingIncludeDirStr = " \( ModuleError . invalidPublicHeadersDirectory ( " Cfactorial " ) ) "
101
+ #expect( errStr. contains ( missingIncludeDirStr) )
78
102
}
79
103
}
80
104
81
- func testCanForwardExtraFlagsToClang( ) async throws {
105
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
106
+ func testCanForwardExtraFlagsToClang( buildSystem: BuildSystemProvider . Kind ) async throws {
82
107
// Try building a fixture which needs extra flags to be able to build.
83
108
try await fixture ( name: " CFamilyTargets/CDynamicLookup " ) { fixturePath in
84
- await XCTAssertBuilds ( fixturePath, Xld: [ " -undefined " , " dynamic_lookup " ] )
109
+ try await executeSwiftBuild ( fixturePath, Xld: [ " -undefined " , " dynamic_lookup " ] , buildSystem : buildSystem )
85
110
let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
86
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
111
+ if buildSystem == . native {
112
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
113
+ }
87
114
}
88
115
}
89
116
90
- func testObjectiveCPackageWithTestTarget( ) async throws {
91
- #if !os(macOS)
92
- try XCTSkipIf ( true , " test is only supported on macOS " )
93
- #endif
117
+ @Test ( . requireHostOS( . macOS) , arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
118
+ func testObjectiveCPackageWithTestTarget( buildSystem: BuildSystemProvider . Kind ) async throws {
94
119
try await fixture ( name: " CFamilyTargets/ObjCmacOSPackage " ) { fixturePath in
95
120
// Build the package.
96
- await XCTAssertBuilds ( fixturePath)
97
- XCTAssertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HelloWorldExample.m.o " )
121
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
122
+ if buildSystem == . native {
123
+ assertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HelloWorldExample.m.o " )
124
+ }
98
125
// Run swift-test on package.
99
- await XCTAssertSwiftTest ( fixturePath)
126
+ try await executeSwiftTest ( fixturePath, buildSystem : buildSystem )
100
127
}
101
128
}
102
-
103
- func testCanBuildRelativeHeaderSearchPaths( ) async throws {
129
+
130
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
131
+ func testCanBuildRelativeHeaderSearchPaths( buildSystem: BuildSystemProvider . Kind ) async throws {
104
132
try await fixture ( name: " CFamilyTargets/CLibraryParentSearchPath " ) { fixturePath in
105
- await XCTAssertBuilds ( fixturePath)
106
- XCTAssertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HeaderInclude.swiftmodule " )
133
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
134
+ if buildSystem == . native {
135
+ assertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HeaderInclude.swiftmodule " )
136
+ }
107
137
}
108
138
}
109
139
}
0 commit comments