Skip to content

Commit 1074c6d

Browse files
author
David Ungar
committed
Add a test.
1 parent 2f2da5d commit 1074c6d

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

Tests/SwiftDriverTests/Helpers/AssertDiagnostics.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ import SwiftDriver
1515
import TSCBasic
1616
import TestUtilities
1717

18-
func assertDriverDiagnostics(
18+
@discardableResult
19+
func assertDriverDiagnostics<Result> (
1920
args: [String],
2021
env: [String: String] = ProcessEnv.vars,
2122
file: StaticString = #file, line: UInt = #line,
22-
do body: (inout Driver, DiagnosticVerifier) throws -> Void
23-
) throws {
23+
do body: (inout Driver, DiagnosticVerifier) throws -> Result
24+
) throws -> Result {
2425
let matcher = DiagnosticVerifier()
2526
defer { matcher.verify(file: file, line: line) }
2627

2728
var driver = try Driver(args: args, env: env, diagnosticsEngine: DiagnosticsEngine(handlers: [matcher.emit(_:)]))
28-
try body(&driver, matcher)
29+
return try body(&driver, matcher)
2930
}
3031

3132
/// Asserts that the `Driver` it instantiates will only emit warnings and errors

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,13 @@ final class IncrementalCompilationTests: XCTestCase {
407407
}
408408

409409
extension IncrementalCompilationTests {
410+
@discardableResult
410411
func doABuild(_ message: String,
411412
checkDiagnostics: Bool,
412413
extraArguments: [String],
413414
expectingRemarks texts: [String],
414-
whenAutolinking: [String]) throws {
415+
whenAutolinking: [String]
416+
) throws -> Driver? {
415417
try doABuild(
416418
message,
417419
checkDiagnostics: checkDiagnostics,
@@ -420,14 +422,16 @@ extension IncrementalCompilationTests {
420422
expectingWhenAutolinking: whenAutolinking.map {.remark($0)})
421423
}
422424

425+
@discardableResult
423426
func doABuild(_ message: String,
424427
checkDiagnostics: Bool,
425428
extraArguments: [String],
426429
expecting expectations: [Diagnostic.Message],
427-
expectingWhenAutolinking autolinkExpectations: [Diagnostic.Message]) throws {
430+
expectingWhenAutolinking autolinkExpectations: [Diagnostic.Message]
431+
) throws -> Driver? {
428432
print("*** starting build \(message) ***", to: &stderrStream); stderrStream.flush()
429433

430-
func doIt(_ driver: inout Driver) {
434+
func doTheCompile(_ driver: inout Driver) {
431435
let jobs = try! driver.planBuild()
432436
try? driver.run(jobs: jobs)
433437
}
@@ -437,14 +441,16 @@ extension IncrementalCompilationTests {
437441
throw XCTSkip("Cannot perform this test on this host")
438442
}
439443
let allArgs = commonArgs + extraArguments + sdkArgumentsForTesting
444+
let postMortemDriver: Driver?
440445
if checkDiagnostics {
441-
try assertDriverDiagnostics(args: allArgs) {driver, verifier in
446+
postMortemDriver = try assertDriverDiagnostics(args: allArgs) {driver, verifier in
442447
verifier.forbidUnexpected(.error, .warning, .note, .remark, .ignored)
443448
expectations.forEach {verifier.expect($0)}
444449
if driver.isAutolinkExtractJobNeeded {
445450
autolinkExpectations.forEach {verifier.expect($0)}
446451
}
447-
doIt(&driver)
452+
doTheCompile(&driver)
453+
return driver
448454
}
449455
}
450456
else {
@@ -454,9 +460,11 @@ extension IncrementalCompilationTests {
454460
var driver = try Driver(args: allArgs, env: ProcessEnv.vars,
455461
diagnosticsEngine: diagnosticEngine,
456462
fileSystem: localFileSystem)
457-
doIt(&driver)
463+
doTheCompile(&driver)
464+
postMortemDriver = driver
458465
}
459466
print("", to: &stderrStream); stderrStream.flush()
467+
return postMortemDriver
460468
}
461469
}
462470

@@ -587,6 +595,22 @@ extension IncrementalCompilationTests {
587595
}
588596
}
589597

598+
/// Ensure that if an output of post-compile job is missing, the job gets rerun.
599+
func testIncrementalPostCompileJob() throws {
600+
let driver = try XCTUnwrap(tryInitial(checkDiagnostics: true))
601+
for postCompileOutput in try driver.postCompileOutputs() {
602+
let absPostCompileOutput = try XCTUnwrap(postCompileOutput.file.absolutePath)
603+
try localFileSystem.removeFileTree(absPostCompileOutput)
604+
XCTAssertFalse(localFileSystem.exists(absPostCompileOutput))
605+
tryNoChange()
606+
XCTAssertTrue(localFileSystem.exists(absPostCompileOutput))
607+
}
608+
}
609+
610+
private func postCompileOutputs() -> [AbsolutePath] {
611+
abort()
612+
}
613+
590614
func testIncremental(checkDiagnostics: Bool) throws {
591615
try tryInitial(checkDiagnostics: checkDiagnostics)
592616
#if true // sometimes want to skip for debugging
@@ -597,10 +621,10 @@ extension IncrementalCompilationTests {
597621
tryReplacingMain(checkDiagnostics: checkDiagnostics)
598622
}
599623

600-
624+
@discardableResult
601625
func tryInitial(checkDiagnostics: Bool = false,
602626
extraArguments: [String] = []
603-
) throws {
627+
) throws -> Driver? {
604628
try doABuild(
605629
"initial",
606630
checkDiagnostics: checkDiagnostics,
@@ -919,3 +943,8 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
919943
}
920944
}
921945

946+
fileprivate extension Driver {
947+
func postCompileOutputs() throws -> [TypedVirtualPath] {
948+
try XCTUnwrap(incrementalCompilationState).jobsAfterCompiles.flatMap {$0.outputs}
949+
}
950+
}

0 commit comments

Comments
 (0)