Skip to content

Commit bab5b4c

Browse files
committed
Simplify SwiftDriverTests by adopting supplementaryOutputFilemap utility.
1 parent d8b5acf commit bab5b4c

File tree

1 file changed

+14
-111
lines changed

1 file changed

+14
-111
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 14 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,41 +2811,12 @@ final class SwiftDriverTests: XCTestCase {
28112811
])
28122812
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
28132813
XCTAssertEqual(plannedJobs.count, 1)
2814-
let suppleArg = "-supplementary-output-file-map"
2815-
// Make sure we are using supplementary file map
2816-
XCTAssert(plannedJobs[0].commandLine.contains(.flag(suppleArg)))
2817-
let args = plannedJobs[0].commandLine
2818-
var fileMapPath: VirtualPath?
2819-
for pair in args.enumerated() {
2820-
if pair.element == .flag(suppleArg) {
2821-
let filemap = args[pair.offset + 1]
2822-
switch filemap {
2823-
case .path(let p):
2824-
fileMapPath = p
2825-
default:
2826-
break
2827-
}
2828-
}
2829-
}
2830-
XCTAssert(fileMapPath != nil)
2831-
switch fileMapPath! {
2832-
case .fileList(_, let list):
2833-
switch list {
2834-
case .outputFileMap(let map):
2835-
// This is to match the legacy driver behavior
2836-
// Make sure the supplementary output map has an entry for the Swift file
2837-
// under indexing and its indexData entry is the primary output file
2838-
let entry = map.entries[VirtualPath.relative(try RelativePath(validating: "foo5.swift")).intern()]!
2839-
XCTAssert(VirtualPath.lookup(entry[.indexData]!) == .absolute(try .init(validating: "/tmp/t.o")))
2840-
return
2841-
default:
2842-
break
2843-
}
2844-
break
2845-
default:
2846-
break
2847-
}
2848-
XCTAssert(false)
2814+
let map = try XCTUnwrap(plannedJobs[0].commandLine.supplementaryOutputFilemap)
2815+
// This is to match the legacy driver behavior
2816+
// Make sure the supplementary output map has an entry for the Swift file
2817+
// under indexing and its indexData entry is the primary output file
2818+
let entry = map.entries[VirtualPath.relative(try RelativePath(validating: "foo5.swift")).intern()]!
2819+
XCTAssert(VirtualPath.lookup(entry[.indexData]!) == .absolute(try .init(validating: "/tmp/t.o")))
28492820
}
28502821

28512822
func testMultiThreadedWholeModuleOptimizationCompiles() throws {
@@ -2917,14 +2888,7 @@ final class SwiftDriverTests: XCTestCase {
29172888
XCTAssertEqual(plannedJobs.count, 2)
29182889
let compileJob = plannedJobs[0]
29192890
XCTAssertEqual(compileJob.kind, .compile)
2920-
XCTAssert(compileJob.commandLine.contains(.flag("-supplementary-output-file-map")))
2921-
let argIdx = try XCTUnwrap(compileJob.commandLine.firstIndex(where: { $0 == .flag("-supplementary-output-file-map") }))
2922-
let supplOutputs = compileJob.commandLine[argIdx+1]
2923-
guard case let .path(path) = supplOutputs,
2924-
case let .fileList(_, fileList) = path,
2925-
case let .outputFileMap(outFileMap) = fileList else {
2926-
throw StringError("Unexpected argument for output file map")
2927-
}
2891+
let outFileMap = try XCTUnwrap(compileJob.commandLine.supplementaryOutputFilemap)
29282892
let firstKey: String = try VirtualPath.lookup(XCTUnwrap(outFileMap.entries.keys.first)).description
29292893
XCTAssertEqual(firstKey, "foo.swift")
29302894
}
@@ -3073,14 +3037,7 @@ final class SwiftDriverTests: XCTestCase {
30733037
XCTAssertEqual(plannedJobs.count, 2)
30743038
XCTAssertEqual(plannedJobs[0].kind, .compile)
30753039
print(plannedJobs[0].commandLine.joinedUnresolvedArguments)
3076-
XCTAssert(plannedJobs[0].commandLine.contains(.flag("-supplementary-output-file-map")))
3077-
let argIdx = try XCTUnwrap(plannedJobs[0].commandLine.firstIndex(where: { $0 == .flag("-supplementary-output-file-map") }))
3078-
let supplOutputs = plannedJobs[0].commandLine[argIdx+1]
3079-
guard case let .path(path) = supplOutputs,
3080-
case let .fileList(_, fileList) = path,
3081-
case let .outputFileMap(outFileMap) = fileList else {
3082-
throw StringError("Unexpected argument for output file map")
3083-
}
3040+
let outFileMap = try XCTUnwrap(plannedJobs[0].commandLine.supplementaryOutputFilemap)
30843041
XCTAssertEqual(outFileMap.entries.values.first?.keys.first, fileType)
30853042
}
30863043

@@ -6636,48 +6593,21 @@ final class SwiftDriverTests: XCTestCase {
66366593
let plannedJobs = try driver.planBuild()
66376594

66386595
let jobA = plannedJobs[0]
6639-
let flagA = jobA.commandLine.firstIndex(of: .flag("-supplementary-output-file-map"))!
6640-
let fileListArgumentA = jobA.commandLine[jobA.commandLine.index(after: flagA)]
6641-
guard case let .path(.fileList(_, fileListA)) = fileListArgumentA else {
6642-
XCTFail("Argument wasn't a filelist")
6643-
return
6644-
}
6645-
guard case let .outputFileMap(mapA) = fileListA else {
6646-
XCTFail("FileList wasn't OutputFileMap")
6647-
return
6648-
}
6596+
let mapA = try XCTUnwrap(jobA.commandLine.supplementaryOutputFilemap)
66496597
let filesA = try XCTUnwrap(mapA.entries[VirtualPath.relative(try RelativePath(validating: "a.swift")).intern()])
66506598
XCTAssertTrue(filesA.keys.contains(.swiftModule))
66516599
XCTAssertTrue(filesA.keys.contains(.swiftDocumentation))
66526600
XCTAssertTrue(filesA.keys.contains(.swiftSourceInfoFile))
66536601

66546602
let jobB = plannedJobs[1]
6655-
let flagB = jobB.commandLine.firstIndex(of: .flag("-supplementary-output-file-map"))!
6656-
let fileListArgumentB = jobB.commandLine[jobB.commandLine.index(after: flagB)]
6657-
guard case let .path(.fileList(_, fileListB)) = fileListArgumentB else {
6658-
XCTFail("Argument wasn't a filelist")
6659-
return
6660-
}
6661-
guard case let .outputFileMap(mapB) = fileListB else {
6662-
XCTFail("FileList wasn't OutputFileMap")
6663-
return
6664-
}
6603+
let mapB = try XCTUnwrap(jobB.commandLine.supplementaryOutputFilemap)
66656604
let filesB = try XCTUnwrap(mapB.entries[VirtualPath.relative(try RelativePath(validating: "b.swift")).intern()])
66666605
XCTAssertTrue(filesB.keys.contains(.swiftModule))
66676606
XCTAssertTrue(filesB.keys.contains(.swiftDocumentation))
66686607
XCTAssertTrue(filesB.keys.contains(.swiftSourceInfoFile))
66696608

66706609
let jobC = plannedJobs[2]
6671-
let flagC = jobC.commandLine.firstIndex(of: .flag("-supplementary-output-file-map"))!
6672-
let fileListArgumentC = jobC.commandLine[jobC.commandLine.index(after: flagC)]
6673-
guard case let .path(.fileList(_, fileListC)) = fileListArgumentC else {
6674-
XCTFail("Argument wasn't a filelist")
6675-
return
6676-
}
6677-
guard case let .outputFileMap(mapC) = fileListC else {
6678-
XCTFail("FileList wasn't OutputFileMap")
6679-
return
6680-
}
6610+
let mapC = try XCTUnwrap(jobC.commandLine.supplementaryOutputFilemap)
66816611
let filesC = try XCTUnwrap(mapC.entries[VirtualPath.relative(try RelativePath(validating: "c.swift")).intern()])
66826612
XCTAssertTrue(filesC.keys.contains(.swiftModule))
66836613
XCTAssertTrue(filesC.keys.contains(.swiftDocumentation))
@@ -6800,29 +6730,11 @@ final class SwiftDriverTests: XCTestCase {
68006730
let plannedJobs = try driver.planBuild()
68016731

68026732
let jobA = plannedJobs[0]
6803-
let flagA = jobA.commandLine.firstIndex(of: .flag("-supplementary-output-file-map"))!
6804-
let fileListArgumentA = jobA.commandLine[jobA.commandLine.index(after: flagA)]
6805-
guard case let .path(.fileList(_, fileListA)) = fileListArgumentA else {
6806-
XCTFail("Argument wasn't a filelist")
6807-
return
6808-
}
6809-
guard case let .outputFileMap(mapA) = fileListA else {
6810-
XCTFail("FileList wasn't OutputFileMap")
6811-
return
6812-
}
6733+
let mapA = try XCTUnwrap(jobA.commandLine.supplementaryOutputFilemap)
68136734
XCTAssertEqual(mapA.entries, [VirtualPath.relative(try .init(validating: "a.swift")).intern(): [:]])
68146735

68156736
let jobB = plannedJobs[1]
6816-
let flagB = jobB.commandLine.firstIndex(of: .flag("-supplementary-output-file-map"))!
6817-
let fileListArgumentB = jobB.commandLine[jobB.commandLine.index(after: flagB)]
6818-
guard case let .path(.fileList(_, fileListB)) = fileListArgumentB else {
6819-
XCTFail("Argument wasn't a filelist")
6820-
return
6821-
}
6822-
guard case let .outputFileMap(mapB) = fileListB else {
6823-
XCTFail("FileList wasn't OutputFileMap")
6824-
return
6825-
}
6737+
let mapB = try XCTUnwrap(jobB.commandLine.supplementaryOutputFilemap)
68266738
XCTAssertEqual(mapB.entries, [VirtualPath.relative(try .init(validating: "b.swift")).intern(): [:]])
68276739
}
68286740

@@ -6831,16 +6743,7 @@ final class SwiftDriverTests: XCTestCase {
68316743
let plannedJobs = try driver.planBuild()
68326744

68336745
let jobA = plannedJobs[0]
6834-
let flagA = jobA.commandLine.firstIndex(of: .flag("-supplementary-output-file-map"))!
6835-
let fileListArgumentA = jobA.commandLine[jobA.commandLine.index(after: flagA)]
6836-
guard case let .path(.fileList(_, fileListA)) = fileListArgumentA else {
6837-
XCTFail("Argument wasn't a filelist")
6838-
return
6839-
}
6840-
guard case let .outputFileMap(mapA) = fileListA else {
6841-
XCTFail("FileList wasn't OutputFileMap")
6842-
return
6843-
}
6746+
let mapA = try XCTUnwrap(jobA.commandLine.supplementaryOutputFilemap)
68446747
XCTAssertEqual(mapA.entries, [VirtualPath.relative(try .init(validating: "a.swift")).intern(): [:]])
68456748
}
68466749
}

0 commit comments

Comments
 (0)