Skip to content

Commit bb0a0bf

Browse files
committed
Add tests and fix flow control error
1 parent d9e1c2b commit bb0a0bf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ extension Driver {
13541354
if let originalPath = swiftFiles[basename] {
13551355
diagnosticsEngine.emit(.error_two_files_same_name(basename: basename, firstPath: originalPath, secondPath: input))
13561356
diagnosticsEngine.emit(.note_explain_two_files_same_name)
1357+
throw Diagnostics.fatalError
13571358
} else {
13581359
swiftFiles[basename] = input
13591360
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,27 @@ final class SwiftDriverTests: XCTestCase {
627627
XCTAssertFalse(plannedJobs[2].commandLine.contains(.flag("-emit-dependencies-path")))
628628
XCTAssertFalse(plannedJobs[2].commandLine.contains(.flag("-serialize-diagnostics-path")))
629629
}
630+
631+
func testReferenceDependencies() throws {
632+
var driver = try Driver(args: ["swiftc", "foo.swift", "-incremental"])
633+
let plannedJobs = try driver.planBuild()
634+
XCTAssertTrue(plannedJobs[0].kind == .compile)
635+
XCTAssertTrue(plannedJobs[0].commandLine.contains(.flag("-emit-reference-dependencies-path")))
636+
}
637+
638+
func testDuplicateName() throws {
639+
assertDiagnostics { diagnosticsEngine, verify in
640+
_ = try? Driver(args: ["swiftc", "-c", "foo.swift", "foo.swift"], diagnosticsEngine: diagnosticsEngine)
641+
verify.expect(.error("filename \"foo.swift\" used twice: 'foo.swift' and 'foo.swift'"))
642+
verify.expect(.note("filenames are used to distinguish private declarations with the same name"))
643+
}
644+
645+
assertDiagnostics { diagnosticsEngine, verify in
646+
_ = try? Driver(args: ["swiftc", "-c", "foo.swift", "foo/foo.swift"], diagnosticsEngine: diagnosticsEngine)
647+
verify.expect(.error("filename \"foo.swift\" used twice: 'foo.swift' and 'foo/foo.swift'"))
648+
verify.expect(.note("filenames are used to distinguish private declarations with the same name"))
649+
}
650+
}
630651

631652
func testOutputFileMapStoring() throws {
632653
// Create sample OutputFileMap:

0 commit comments

Comments
 (0)