@@ -16,94 +16,120 @@ 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 {
38
+ @Suite ( . serialized)
39
+ struct CFamilyTargetTestCase {
40
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
41
+ func testCLibraryWithSpaces( buildSystem: BuildSystemProvider . Kind ) async throws {
39
42
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 " )
43
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
44
+ if buildSystem == . native {
45
+ let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
46
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Bar.c.o " )
47
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
48
+ }
44
49
}
45
50
}
46
51
47
- func testCUsingCAndSwiftDep( ) async throws {
52
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
53
+ func testCUsingCAndSwiftDep( buildSystem: BuildSystemProvider . Kind ) async throws {
48
54
try await fixture ( name: " DependencyResolution/External/CUsingCDep " ) { fixturePath in
49
55
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 " )
56
+ try await executeSwiftBuild ( packageRoot, buildSystem: buildSystem)
57
+ if buildSystem == . native {
58
+ let debugPath = fixturePath. appending ( components: " Bar " , " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
59
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Sea.c.o " )
60
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
61
+ }
54
62
let path = try SwiftPM . packagePath ( for: " Foo " , packageRoot: packageRoot)
55
- XCTAssertEqual ( try GitRepository ( path: path) . getTags ( ) , [ " 1.2.3 " ] )
63
+ #expect ( try GitRepository ( path: path) . getTags ( ) == [ " 1.2.3 " ] )
56
64
}
57
65
}
58
66
59
- func testModuleMapGenerationCases( ) async throws {
67
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
68
+ func testModuleMapGenerationCases( buildSystem: BuildSystemProvider . Kind ) async throws {
60
69
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 " )
70
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
71
+ if buildSystem == . native {
72
+ let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
73
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Jaz.c.o " )
74
+ assertDirectoryContainsFile ( dir: debugPath, filename: " main.swift.o " )
75
+ assertDirectoryContainsFile ( dir: debugPath, filename: " FlatInclude.c.o " )
76
+ assertDirectoryContainsFile ( dir: debugPath, filename: " UmbrellaHeader.c.o " )
77
+ }
67
78
}
68
79
}
69
-
70
- func testNoIncludeDirCheck( ) async throws {
80
+
81
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
82
+ func testNoIncludeDirCheck( buildSystem: BuildSystemProvider . Kind ) async throws {
71
83
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 ) )
84
+ var buildError : ( any Error ) ? = nil
85
+ do {
86
+ try await executeSwiftBuild ( fixturePath , buildSystem : buildSystem )
87
+ } catch {
88
+ buildError = error
77
89
}
90
+ guard let buildError else {
91
+ Issue . record ( StringError ( " This build should throw an error " ) )
92
+ return
93
+ }
94
+ // The err.localizedDescription doesn't capture the detailed error string so interpolate
95
+ let errStr = " \( buildError) "
96
+ let missingIncludeDirStr = " \( ModuleError . invalidPublicHeadersDirectory ( " Cfactorial " ) ) "
97
+ #expect( errStr. contains ( missingIncludeDirStr) )
78
98
}
79
99
}
80
100
81
- func testCanForwardExtraFlagsToClang( ) async throws {
101
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
102
+ func testCanForwardExtraFlagsToClang( buildSystem: BuildSystemProvider . Kind ) async throws {
82
103
// Try building a fixture which needs extra flags to be able to build.
83
104
try await fixture ( name: " CFamilyTargets/CDynamicLookup " ) { fixturePath in
84
- await XCTAssertBuilds ( fixturePath, Xld: [ " -undefined " , " dynamic_lookup " ] )
105
+ try await executeSwiftBuild ( fixturePath, Xld: [ " -undefined " , " dynamic_lookup " ] , buildSystem : buildSystem )
85
106
let debugPath = fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " )
86
- XCTAssertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
107
+ if buildSystem == . native {
108
+ assertDirectoryContainsFile ( dir: debugPath, filename: " Foo.c.o " )
109
+ }
87
110
}
88
111
}
89
112
90
- func testObjectiveCPackageWithTestTarget( ) async throws {
91
- #if !os(macOS)
92
- try XCTSkipIf ( true , " test is only supported on macOS " )
93
- #endif
113
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
114
+ func testObjectiveCPackageWithTestTarget( buildSystem: BuildSystemProvider . Kind ) async throws {
94
115
try await fixture ( name: " CFamilyTargets/ObjCmacOSPackage " ) { fixturePath in
95
116
// Build the package.
96
- await XCTAssertBuilds ( fixturePath)
97
- XCTAssertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HelloWorldExample.m.o " )
117
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
118
+ if buildSystem == . native {
119
+ assertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HelloWorldExample.m.o " )
120
+ }
98
121
// Run swift-test on package.
99
- await XCTAssertSwiftTest ( fixturePath)
122
+ try await executeSwiftTest ( fixturePath, buildSystem : buildSystem )
100
123
}
101
124
}
102
-
103
- func testCanBuildRelativeHeaderSearchPaths( ) async throws {
125
+
126
+ @Test ( arguments: [ BuildSystemProvider . Kind. native, . swiftbuild] )
127
+ func testCanBuildRelativeHeaderSearchPaths( buildSystem: BuildSystemProvider . Kind ) async throws {
104
128
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 " )
129
+ try await executeSwiftBuild ( fixturePath, buildSystem: buildSystem)
130
+ if buildSystem == . native {
131
+ assertDirectoryContainsFile ( dir: fixturePath. appending ( components: " .build " , try UserToolchain . default. targetTriple. platformBuildPathComponent, " debug " ) , filename: " HeaderInclude.swiftmodule " )
132
+ }
107
133
}
108
134
}
109
135
}
0 commit comments