Skip to content

Commit 4ffbc0d

Browse files
committed
Run CFamilyTargetTests with Swift Build backend
1 parent 985b56f commit 4ffbc0d

File tree

1 file changed

+75
-45
lines changed

1 file changed

+75
-45
lines changed

Tests/FunctionalTests/CFamilyTargetTests.swift

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,94 +16,124 @@ import PackageGraph
1616
import PackageLoading
1717
import PackageModel
1818
import SourceControl
19+
import SPMBuildCore
1920
import _InternalTestSupport
2021
import Workspace
21-
import XCTest
22+
import Testing
2223

2324
import class Basics.AsyncProcess
2425

2526
/// 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) {
2728
do {
2829
for entry in try walk(dir) {
2930
if entry.basename == filename { return }
3031
}
3132
} catch {
32-
XCTFail("Failed with error \(error)", file: file, line: line)
33+
Issue.record(StringError("Failed with error \(error)"), sourceLocation: sourceLocation)
3334
}
34-
XCTFail("Directory \(dir) does not contain \(file)", file: file, line: line)
35+
Issue.record(StringError("Directory \(dir) does not contain \(filename)"), sourceLocation: sourceLocation)
3536
}
3637

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
4453
}
4554
}
4655

47-
func testCUsingCAndSwiftDep() async throws {
56+
@Test(arguments: [BuildSystemProvider.Kind.native, .swiftbuild])
57+
func testCUsingCAndSwiftDep(buildSystem: BuildSystemProvider.Kind) async throws {
4858
try await fixture(name: "DependencyResolution/External/CUsingCDep") { fixturePath in
4959
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+
}
5466
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"])
5668
}
5769
}
5870

59-
func testModuleMapGenerationCases() async throws {
71+
@Test(arguments: [BuildSystemProvider.Kind.native, .swiftbuild])
72+
func testModuleMapGenerationCases(buildSystem: BuildSystemProvider.Kind) async throws {
6073
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+
}
6782
}
6883
}
69-
70-
func testNoIncludeDirCheck() async throws {
84+
85+
@Test(arguments: [BuildSystemProvider.Kind.native, .swiftbuild])
86+
func testNoIncludeDirCheck(buildSystem: BuildSystemProvider.Kind) async throws {
7187
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
7793
}
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))
78102
}
79103
}
80104

81-
func testCanForwardExtraFlagsToClang() async throws {
105+
@Test(arguments: [BuildSystemProvider.Kind.native, .swiftbuild])
106+
func testCanForwardExtraFlagsToClang(buildSystem: BuildSystemProvider.Kind) async throws {
82107
// Try building a fixture which needs extra flags to be able to build.
83108
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)
85110
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+
}
87114
}
88115
}
89116

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 {
94119
try await fixture(name: "CFamilyTargets/ObjCmacOSPackage") { fixturePath in
95120
// 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+
}
98125
// Run swift-test on package.
99-
await XCTAssertSwiftTest(fixturePath)
126+
try await executeSwiftTest(fixturePath, buildSystem: buildSystem)
100127
}
101128
}
102-
103-
func testCanBuildRelativeHeaderSearchPaths() async throws {
129+
130+
@Test(arguments: [BuildSystemProvider.Kind.native, .swiftbuild])
131+
func testCanBuildRelativeHeaderSearchPaths(buildSystem: BuildSystemProvider.Kind) async throws {
104132
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+
}
107137
}
108138
}
109139
}

0 commit comments

Comments
 (0)