Skip to content

Commit b986922

Browse files
authored
Tests: adopt AbsolutePath in more of the PackageLoadingTests (#5542)
This adjusts the Package Loading test suite to use `AbsolutePath` to represent and perform path operations. This allows flexibility for differing path separator characters (e.g. `\` on Windows).
1 parent ff8a19c commit b986922

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ class TargetSourcesBuilderTests: XCTestCase {
5959
observabilityScope: observability.topScope
6060
)
6161

62-
let contents = builder.computeContents().map{ $0.pathString }.sorted()
62+
let contents = builder.computeContents().sorted()
6363

6464
XCTAssertEqual(contents, [
65-
"/Bar.swift",
66-
"/Foo.swift",
67-
"/Hello.something/hello.txt",
68-
"/file",
69-
"/path/to/somefile.txt",
70-
"/some/path.swift",
71-
"/some/path/toBeCopied",
65+
AbsolutePath("/Bar.swift"),
66+
AbsolutePath("/Foo.swift"),
67+
AbsolutePath("/Hello.something/hello.txt"),
68+
AbsolutePath("/file"),
69+
AbsolutePath("/path/to/somefile.txt"),
70+
AbsolutePath("/some/path.swift"),
71+
AbsolutePath("/some/path/toBeCopied"),
7272
])
7373

7474
XCTAssertNoDiagnostics(observability.diagnostics)
@@ -103,11 +103,11 @@ class TargetSourcesBuilderTests: XCTestCase {
103103
observabilityScope: observability.topScope
104104
)
105105

106-
let contents = builder.computeContents().map{ $0.pathString }.sorted()
106+
let contents = builder.computeContents().sorted()
107107

108108
XCTAssertEqual(contents, [
109-
"/some.thing",
110-
"/some/hello.swift",
109+
AbsolutePath("/some.thing"),
110+
AbsolutePath("/some/hello.swift"),
111111
])
112112

113113
XCTAssertNoDiagnostics(observability.diagnostics)
@@ -142,17 +142,19 @@ class TargetSourcesBuilderTests: XCTestCase {
142142
observabilityScope: observability.topScope
143143
)
144144

145-
let contents = builder.computeContents().map{ $0.pathString }.sorted()
145+
let contents = builder.computeContents().sorted()
146146

147147
XCTAssertEqual(contents, [
148-
"/some.thing/hello.txt",
149-
"/some/hello.swift",
148+
AbsolutePath("/some.thing/hello.txt"),
149+
AbsolutePath("/some/hello.swift"),
150150
])
151151

152152
XCTAssertNoDiagnostics(observability.diagnostics)
153153
}
154154

155155
func testSpecialDirectoryWithExt_5_6() throws {
156+
let root = AbsolutePath.root
157+
156158
let target = try TargetDescription(
157159
name: "Foo",
158160
path: nil,
@@ -164,8 +166,8 @@ class TargetSourcesBuilderTests: XCTestCase {
164166

165167
let fs = InMemoryFileSystem()
166168
fs.createEmptyFiles(at: .root, files: [
167-
"/some.xcassets/hello.txt",
168-
"/some/hello.swift",
169+
root.appending(components: "some.xcassets", "hello.txt").pathString,
170+
root.appending(components: "some", "hello.swift").pathString
169171
])
170172

171173
let observability = ObservabilitySystem.makeForTesting()
@@ -181,11 +183,11 @@ class TargetSourcesBuilderTests: XCTestCase {
181183
observabilityScope: observability.topScope
182184
)
183185

184-
let contents = builder.computeContents().map{ $0.pathString }.sorted()
186+
let contents = builder.computeContents().sorted()
185187

186188
XCTAssertEqual(contents, [
187-
"/some.xcassets",
188-
"/some/hello.swift"
189+
root.appending(components: "some.xcassets"),
190+
root.appending(components: "some", "hello.swift"),
189191
])
190192

191193
XCTAssertNoDiagnostics(observability.diagnostics)
@@ -242,9 +244,9 @@ class TargetSourcesBuilderTests: XCTestCase {
242244
)
243245

244246
let files = [
245-
"/Foo.swift",
246-
"/Bar.swift",
247-
"/Baz.something"
247+
AbsolutePath("/Foo.swift").pathString,
248+
AbsolutePath("/Bar.swift").pathString,
249+
AbsolutePath("/Baz.something").pathString,
248250
]
249251

250252
let fs = InMemoryFileSystem()
@@ -282,8 +284,8 @@ class TargetSourcesBuilderTests: XCTestCase {
282284
testDiagnostics(diagnostics, problemsOnly: false) { result in
283285
var diagnosticsFound = [Basics.Diagnostic?]()
284286
diagnosticsFound.append(result.check(diagnostic: "multiple resources named 'foo.txt' in target 'Foo'", severity: .error))
285-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'Resources/foo.txt'", severity: .info))
286-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'Resources/Sub/foo.txt'", severity: .info))
287+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("Resources").appending(components: "foo.txt"))'", severity: .info))
288+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("Resources").appending(components: "Sub", "foo.txt"))'", severity: .info))
287289

288290
for diagnostic in diagnosticsFound {
289291
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -311,8 +313,8 @@ class TargetSourcesBuilderTests: XCTestCase {
311313
testDiagnostics(diagnostics, problemsOnly: false) { result in
312314
var diagnosticsFound = [Basics.Diagnostic?]()
313315
diagnosticsFound.append(result.check(diagnostic: "multiple resources named 'foo.txt' in target 'Foo'", severity: .error))
314-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'Processed/foo.txt'", severity: .info))
315-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'Copied/foo.txt'", severity: .info))
316+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("Processed").appending(components: "foo.txt"))'", severity: .info))
317+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("Copied").appending(components: "foo.txt"))'", severity: .info))
316318

317319
for diagnostic in diagnosticsFound {
318320
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -358,8 +360,8 @@ class TargetSourcesBuilderTests: XCTestCase {
358360
testDiagnostics(diagnostics, problemsOnly: false) { result in
359361
var diagnosticsFound = [Basics.Diagnostic?]()
360362
diagnosticsFound.append(result.check(diagnostic: "multiple resources named 'Copy' in target 'Foo'", severity: .error))
361-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'A/Copy'", severity: .info))
362-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'B/Copy'", severity: .info))
363+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("A").appending(components: "Copy"))'", severity: .info))
364+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("B").appending(components: "Copy"))'", severity: .info))
363365

364366
for diagnostic in diagnosticsFound {
365367
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -386,9 +388,9 @@ class TargetSourcesBuilderTests: XCTestCase {
386388
build(target: target, toolsVersion: .v5_3, fs: fs) { _, _, _, _, identity, kind, path, diagnostics in
387389
testDiagnostics(diagnostics, problemsOnly: false) { result in
388390
var diagnosticsFound = [Basics.Diagnostic?]()
389-
diagnosticsFound.append(result.check(diagnostic: "multiple resources named 'en.lproj/foo.txt' in target 'Foo'", severity: .error))
390-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'A/en.lproj/foo.txt'", severity: .info))
391-
diagnosticsFound.append(result.checkUnordered(diagnostic: "found 'B/EN.lproj/foo.txt'", severity: .info))
391+
diagnosticsFound.append(result.check(diagnostic: "multiple resources named '\(RelativePath("en.lproj").appending(components: "foo.txt"))' in target 'Foo'", severity: .error))
392+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("A").appending(components: "en.lproj", "foo.txt"))'", severity: .info))
393+
diagnosticsFound.append(result.checkUnordered(diagnostic: "found '\(RelativePath("B").appending(components: "EN.lproj", "foo.txt"))'", severity: .info))
392394

393395
for diagnostic in diagnosticsFound {
394396
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -415,7 +417,7 @@ class TargetSourcesBuilderTests: XCTestCase {
415417
build(target: target, toolsVersion: .v5_3, fs: fs) { _, _, _, _, identity, kind, path, diagnostics in
416418
testDiagnostics(diagnostics) { result in
417419
let diagnostic = result.check(
418-
diagnostic: "resource 'B/en.lproj' in target 'Foo' conflicts with other localization directories",
420+
diagnostic: "resource '\(RelativePath("B").appending(components: "en.lproj"))' in target 'Foo' conflicts with other localization directories",
419421
severity: .error
420422
)
421423
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -453,7 +455,7 @@ class TargetSourcesBuilderTests: XCTestCase {
453455
build(target: target, toolsVersion: .v5_3, fs: fs) { _, _, _, _, identity, kind, path, diagnostics in
454456
testDiagnostics(diagnostics) { result in
455457
let diagnostic = result.check(
456-
diagnostic: "localization directory 'Processed/en.lproj' in target 'Foo' contains sub-directories, which is forbidden",
458+
diagnostic: "localization directory '\(RelativePath("Processed").appending(components: "en.lproj"))' in target 'Foo' contains sub-directories, which is forbidden",
457459
severity: .error
458460
)
459461
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -476,7 +478,7 @@ class TargetSourcesBuilderTests: XCTestCase {
476478
testDiagnostics(diagnostics) { result in
477479
let diagnostic = result.check(
478480
diagnostic: .contains("""
479-
resource 'Resources/en.lproj/Localizable.strings' in target 'Foo' is in a localization directory \
481+
resource '\(RelativePath("Resources").appending(components: "en.lproj", "Localizable.strings"))' in target 'Foo' is in a localization directory \
480482
and has an explicit localization declaration
481483
"""),
482484
severity: .error
@@ -629,7 +631,7 @@ class TargetSourcesBuilderTests: XCTestCase {
629631
build(target: target, toolsVersion: .v5_3, fs: fs) { _, _, _, _, identity, kind, path, diagnostics in
630632
testDiagnostics(diagnostics) { result in
631633
let diagnostic = result.check(
632-
diagnostic: .contains("resource 'Resources/Processed/Info.plist' in target 'Foo' is forbidden"),
634+
diagnostic: .contains("resource '\(RelativePath("Resources").appending(components: "Processed", "Info.plist"))' in target 'Foo' is forbidden"),
633635
severity: .error
634636
)
635637
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -651,7 +653,7 @@ class TargetSourcesBuilderTests: XCTestCase {
651653
build(target: target, toolsVersion: .v5_3, fs: fs) { _, _, _, _, identity, kind, path, diagnostics in
652654
testDiagnostics(diagnostics) { result in
653655
let diagnostic = result.check(
654-
diagnostic: .contains("resource 'Resources/Copied/Info.plist' in target 'Foo' is forbidden"),
656+
diagnostic: .contains("resource '\(RelativePath("Resources").appending(components: "Copied", "Info.plist"))' in target 'Foo' is forbidden"),
655657
severity: .error
656658
)
657659
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, identity)
@@ -697,8 +699,8 @@ class TargetSourcesBuilderTests: XCTestCase {
697699

698700
testDiagnostics(observability.diagnostics) { result in
699701
var diagnosticsFound = [Basics.Diagnostic?]()
700-
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Exclude '/fileOutsideRoot.py': File not found.", severity: .warning))
701-
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Exclude '/fakeDir': File not found.", severity: .warning))
702+
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Exclude '\(AbsolutePath("/fileOutsideRoot.py"))': File not found.", severity: .warning))
703+
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Exclude '\(AbsolutePath("/fakeDir"))': File not found.", severity: .warning))
702704

703705
for diagnostic in diagnosticsFound {
704706
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, builder.packageIdentity)
@@ -831,9 +833,9 @@ class TargetSourcesBuilderTests: XCTestCase {
831833

832834
testDiagnostics(observability.diagnostics) { result in
833835
var diagnosticsFound = [Basics.Diagnostic?]()
834-
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Source '/InvalidPackage.swift': File not found.", severity: .warning))
835-
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Source '/DoesNotExist.swift': File not found.", severity: .warning))
836-
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Source '/Tests/InvalidPackageTests/InvalidPackageTests.swift': File not found.", severity: .warning))
836+
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Source '\(AbsolutePath("/InvalidPackage.swift"))': File not found.", severity: .warning))
837+
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Source '\(AbsolutePath("/DoesNotExist.swift"))': File not found.", severity: .warning))
838+
diagnosticsFound.append(result.checkUnordered(diagnostic: "Invalid Source '\(AbsolutePath("/Tests/InvalidPackageTests/InvalidPackageTests.swift"))': File not found.", severity: .warning))
837839

838840
for diagnostic in diagnosticsFound {
839841
XCTAssertEqual(diagnostic?.metadata?.packageIdentity, builder.packageIdentity)

0 commit comments

Comments
 (0)