Skip to content

Commit b5eac91

Browse files
author
David Ungar
committed
Test the other combos
1 parent b96fb6d commit b5eac91

File tree

1 file changed

+117
-53
lines changed

1 file changed

+117
-53
lines changed

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 117 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ extension IncrementalCompilationTests {
337337
fileprivate enum RemovalTestOption: String, CaseIterable, Comparable, Hashable, CustomStringConvertible {
338338
case
339339
removeInputFromInvocation,
340-
removeSourceFile,
341-
removePreviouslyAddedInputFromOutputFileMap,
342340
removeSwiftDepsFile,
343341
restoreBadPriors
344342

@@ -380,7 +378,6 @@ extension IncrementalCompilationTests {
380378

381379
/// Someday, turn this test on and test all cases
382380
func testRemovalInAllCases() throws {
383-
throw XCTSkip("unimplemented")
384381
try testRemoval(includeFailingCombos: true)
385382
}
386383

@@ -401,26 +398,16 @@ extension IncrementalCompilationTests {
401398
}
402399

403400
private func testRemoval(_ options: RemovalTestOptions) throws {
404-
guard !options.isEmpty else {return}
405-
print("*** testRemoval \(options) ***", to: &stderrStream); stderrStream.flush()
401+
setUp() // clear derived data, restore output file map
402+
print("\n*** testRemoval \(options) ***", to: &stderrStream); stderrStream.flush()
406403

407404
let newInput = "another"
408405
let topLevelName = "nameInAnother"
409406
try testAddingInput(newInput: newInput, defining: topLevelName)
410-
if options.contains(.removeSourceFile) {
411-
removeInput(newInput)
412-
}
413-
if options.contains(.removeSwiftDepsFile) {
414-
removeSwiftDeps(newInput)
415-
}
416-
if options.contains(.removePreviouslyAddedInputFromOutputFileMap) {
417-
// FACTOR
418-
OutputFileMapCreator.write(module: module,
419-
inputPaths: inputPathsAndContents.map {$0.0},
420-
derivedData: derivedDataPath,
421-
to: OFM)
422-
}
423-
let includeInputInInvocation = !options.contains(.removeInputFromInvocation)
407+
408+
let removeInputFromInvocation = options.contains(.removeInputFromInvocation)
409+
let removeSwiftDepsFile = options.contains(.removeSwiftDepsFile)
410+
let restoreBadPriors = options.contains(.restoreBadPriors)
424411
do {
425412
let wrapperFn = options.contains(.restoreBadPriors)
426413
? preservingPriorsDo
@@ -429,14 +416,16 @@ extension IncrementalCompilationTests {
429416
try self.checkNonincrementalAfterRemoving(
430417
removedInput: newInput,
431418
defining: topLevelName,
432-
includeInputInInvocation: includeInputInInvocation)
419+
removeInputFromInvocation: removeInputFromInvocation,
420+
removeSwiftDepsFile: removeSwiftDepsFile)
433421
}
434422
}
435423
try checkRestorationOfIncrementalityAfterRemoval(
436424
removedInput: newInput,
437425
defining: topLevelName,
438-
includeInputInInvocation: includeInputInInvocation,
439-
afterRestoringBadPriors: options.contains(.restoreBadPriors))
426+
removeInputFromInvocation: removeInputFromInvocation,
427+
removeSwiftDepsFile: removeSwiftDepsFile,
428+
afterRestoringBadPriors: restoreBadPriors)
440429
}
441430
}
442431

@@ -701,25 +690,62 @@ extension IncrementalCompilationTests {
701690
private func checkNonincrementalAfterRemoving(
702691
removedInput: String,
703692
defining topLevelName: String,
704-
includeInputInInvocation: Bool
693+
removeInputFromInvocation: Bool,
694+
removeSwiftDepsFile: Bool
705695
) throws {
706-
let extraArguments = includeInputInInvocation
707-
? [inputPath(basename: removedInput).pathString]
708-
: []
709-
try doABuild(
710-
"after removal of \(removedInput)",
711-
checkDiagnostics: true,
712-
extraArguments: extraArguments,
713-
expecting: [
696+
let extraArguments = removeInputFromInvocation
697+
? [] : [inputPath(basename: removedInput).pathString]
698+
699+
if removeSwiftDepsFile {
700+
removeSwiftDeps(removedInput)
701+
}
702+
let expectations: [[Diagnostic.Message]]
703+
switch (removeInputFromInvocation, removeSwiftDepsFile) {
704+
case (false, false):
705+
expectations = [
706+
.readGraphAndSkipAll("main", "other", "another")
707+
]
708+
case
709+
(true, false),
710+
(true, true):
711+
expectations = [
714712
.remarks(
715713
"Incremental compilation: Incremental compilation has been disabled, because the following inputs were used in the previous compilation but not in this one: \(removedInput).swift"),
716714
.findingBatchingCompiling("main", "other"),
717715
.linking,
718-
],
716+
]
717+
case (false, true):
718+
expectations = [
719+
.readGraph,
720+
.enablingCrossModule,
721+
.maySkip("main", "other", "another"),
722+
.missing("another"),
723+
.queuingInitial("another"),
724+
.skipping("main", "other"),
725+
.findingBatchingCompiling("another"),
726+
.schedulingPostCompileJobs,
727+
.linking,
728+
.skipped("main", "other"),
729+
]
730+
}
731+
732+
let driver = try doABuild(
733+
"after removal of \(removedInput)",
734+
checkDiagnostics: true,
735+
extraArguments: extraArguments,
736+
expecting: expectations,
719737
whenAutolinking: autolinkLifecycleExpectations)
720-
.verifyNoGraph()
721738

722-
verifyNoPriors()
739+
if removeInputFromInvocation {
740+
driver.verifyNoGraph()
741+
verifyNoPriors()
742+
}
743+
else {
744+
let graph = try driver.moduleDependencyGraph()
745+
graph.verifyGraph()
746+
XCTAssert(graph.contains(sourceBasenameWithoutExt: removedInput))
747+
XCTAssert(graph.contains(name: topLevelName))
748+
}
723749
}
724750

725751
/// Ensure that incremental builds happen after a removal.
@@ -731,34 +757,57 @@ extension IncrementalCompilationTests {
731757
private func checkRestorationOfIncrementalityAfterRemoval(
732758
removedInput: String,
733759
defining topLevelName: String,
734-
includeInputInInvocation: Bool,
760+
removeInputFromInvocation: Bool,
761+
removeSwiftDepsFile: Bool,
735762
afterRestoringBadPriors: Bool
736763
) throws -> ModuleDependencyGraph {
737-
let extraArguments = includeInputInInvocation
738-
? [inputPath(basename: removedInput).pathString]
739-
: []
740-
let expectations: [[Diagnostic.Message]] = afterRestoringBadPriors
741-
? [
742-
.readGraph,
743-
.enablingCrossModule,
744-
.skippingAll("main", "other"),
745-
]
746-
: [
747-
.createdGraphFromSwiftdeps,
748-
.enablingCrossModule,
749-
.skippingAll("main", "other"),
750-
]
764+
let extraArguments = removeInputFromInvocation
765+
? [] : [inputPath(basename: removedInput).pathString]
766+
let inputs = ["main", "other"] + (removeInputFromInvocation ? [] : [removedInput])
767+
let expectations: [[Diagnostic.Message]]
768+
switch (removeInputFromInvocation, removeSwiftDepsFile, afterRestoringBadPriors) {
769+
case
770+
(false, false, false),
771+
(false, true, false),
772+
(false, false, true ),
773+
(true, false, true ),
774+
(true, true, true ),
775+
(false, true, true ):
776+
expectations = [
777+
.readGraphAndSkipAll(inputs)
778+
]
779+
case
780+
(true, false, false),
781+
(true, true, false):
782+
expectations = [
783+
.createdGraphFromSwiftdeps,
784+
.enablingCrossModule,
785+
.skippingAll(inputs),
786+
]
787+
}
788+
751789
let graph = try doABuild(
752-
"after after removal of \(removedInput)",
790+
"restoring incrementality after removal of \(removedInput)",
753791
checkDiagnostics: true,
754792
extraArguments: extraArguments,
755793
expecting: expectations,
756794
whenAutolinking: autolinkLifecycleExpectations)
757795
.moduleDependencyGraph()
758796

759797
graph.verifyGraph()
760-
graph.ensureOmits(sourceBasenameWithoutExt: removedInput)
761-
graph.ensureOmits(name: topLevelName)
798+
if removeInputFromInvocation {
799+
if afterRestoringBadPriors {
800+
print("*** WARNING: skipping checks, driver fails to cleaned out the graph ***",
801+
to: &stderrStream); stderrStream.flush()
802+
return graph
803+
}
804+
graph.ensureOmits(sourceBasenameWithoutExt: removedInput)
805+
graph.ensureOmits(name: topLevelName)
806+
}
807+
else {
808+
XCTAssert(graph.contains(sourceBasenameWithoutExt: removedInput))
809+
XCTAssert(graph.contains(name: topLevelName))
810+
}
762811

763812
return graph
764813
}
@@ -897,12 +946,14 @@ fileprivate extension ModuleDependencyGraph {
897946
allNodes.contains {$0.contains(name: target)}
898947
}
899948
func ensureOmits(sourceBasenameWithoutExt target: String) {
949+
// Written this way to show the faulty node when the assertion fails
900950
nodeFinder.forEachNode { node in
901951
XCTAssertFalse(node.contains(sourceBasenameWithoutExt: target),
902952
"graph should omit source: \(target)")
903953
}
904954
}
905955
func ensureOmits(name: String) {
956+
// Written this way to show the faulty node when the assertion fails
906957
nodeFinder.forEachNode { node in
907958
XCTAssertFalse(node.contains(name: name),
908959
"graph should omit decl named: \(name)")
@@ -1097,11 +1148,24 @@ fileprivate extension Array where Element == Diagnostic.Message {
10971148
static func skipped(_ inputs: String...) -> Self {
10981149
skipped(inputs)
10991150
}
1100-
static func skippingAll(_ inputs: String...) -> Self {
1151+
static func skippingAll(_ inputs: [String]) -> Self {
11011152
[
11021153
maySkip(inputs), skipping(inputs), skippingLinking, skipped(inputs)
11031154
].flatMap {$0}
11041155
}
1156+
static func skippingAll(_ inputs: String...) -> Self {
1157+
skippingAll(inputs)
1158+
}
1159+
static func readGraphAndSkipAll(_ inputs: [String]) -> Self {
1160+
[
1161+
readGraph,
1162+
enablingCrossModule,
1163+
skippingAll(inputs)
1164+
].flatMap{$0}
1165+
}
1166+
static func readGraphAndSkipAll(_ inputs: String...) -> Self {
1167+
readGraphAndSkipAll(inputs)
1168+
}
11051169

11061170
// MARK: - batching
11071171
static func addingToBatch(_ inputs: [String], _ b: Int) -> Self {

0 commit comments

Comments
 (0)