@@ -337,8 +337,6 @@ extension IncrementalCompilationTests {
337
337
fileprivate enum RemovalTestOption : String , CaseIterable , Comparable , Hashable , CustomStringConvertible {
338
338
case
339
339
removeInputFromInvocation,
340
- removeSourceFile,
341
- removePreviouslyAddedInputFromOutputFileMap,
342
340
removeSwiftDepsFile,
343
341
restoreBadPriors
344
342
@@ -380,7 +378,6 @@ extension IncrementalCompilationTests {
380
378
381
379
/// Someday, turn this test on and test all cases
382
380
func testRemovalInAllCases( ) throws {
383
- throw XCTSkip ( " unimplemented " )
384
381
try testRemoval ( includeFailingCombos: true )
385
382
}
386
383
@@ -401,26 +398,16 @@ extension IncrementalCompilationTests {
401
398
}
402
399
403
400
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 ( )
406
403
407
404
let newInput = " another "
408
405
let topLevelName = " nameInAnother "
409
406
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)
424
411
do {
425
412
let wrapperFn = options. contains ( . restoreBadPriors)
426
413
? preservingPriorsDo
@@ -429,14 +416,16 @@ extension IncrementalCompilationTests {
429
416
try self . checkNonincrementalAfterRemoving (
430
417
removedInput: newInput,
431
418
defining: topLevelName,
432
- includeInputInInvocation: includeInputInInvocation)
419
+ removeInputFromInvocation: removeInputFromInvocation,
420
+ removeSwiftDepsFile: removeSwiftDepsFile)
433
421
}
434
422
}
435
423
try checkRestorationOfIncrementalityAfterRemoval (
436
424
removedInput: newInput,
437
425
defining: topLevelName,
438
- includeInputInInvocation: includeInputInInvocation,
439
- afterRestoringBadPriors: options. contains ( . restoreBadPriors) )
426
+ removeInputFromInvocation: removeInputFromInvocation,
427
+ removeSwiftDepsFile: removeSwiftDepsFile,
428
+ afterRestoringBadPriors: restoreBadPriors)
440
429
}
441
430
}
442
431
@@ -701,25 +690,62 @@ extension IncrementalCompilationTests {
701
690
private func checkNonincrementalAfterRemoving(
702
691
removedInput: String ,
703
692
defining topLevelName: String ,
704
- includeInputInInvocation: Bool
693
+ removeInputFromInvocation: Bool ,
694
+ removeSwiftDepsFile: Bool
705
695
) 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 = [
714
712
. remarks(
715
713
" Incremental compilation: Incremental compilation has been disabled, because the following inputs were used in the previous compilation but not in this one: \( removedInput) .swift " ) ,
716
714
. findingBatchingCompiling( " main " , " other " ) ,
717
715
. 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,
719
737
whenAutolinking: autolinkLifecycleExpectations)
720
- . verifyNoGraph ( )
721
738
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
+ }
723
749
}
724
750
725
751
/// Ensure that incremental builds happen after a removal.
@@ -731,34 +757,57 @@ extension IncrementalCompilationTests {
731
757
private func checkRestorationOfIncrementalityAfterRemoval(
732
758
removedInput: String ,
733
759
defining topLevelName: String ,
734
- includeInputInInvocation: Bool ,
760
+ removeInputFromInvocation: Bool ,
761
+ removeSwiftDepsFile: Bool ,
735
762
afterRestoringBadPriors: Bool
736
763
) 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
+
751
789
let graph = try doABuild (
752
- " after after removal of \( removedInput) " ,
790
+ " restoring incrementality after removal of \( removedInput) " ,
753
791
checkDiagnostics: true ,
754
792
extraArguments: extraArguments,
755
793
expecting: expectations,
756
794
whenAutolinking: autolinkLifecycleExpectations)
757
795
. moduleDependencyGraph ( )
758
796
759
797
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
+ }
762
811
763
812
return graph
764
813
}
@@ -897,12 +946,14 @@ fileprivate extension ModuleDependencyGraph {
897
946
allNodes. contains { $0. contains ( name: target) }
898
947
}
899
948
func ensureOmits( sourceBasenameWithoutExt target: String ) {
949
+ // Written this way to show the faulty node when the assertion fails
900
950
nodeFinder. forEachNode { node in
901
951
XCTAssertFalse ( node. contains ( sourceBasenameWithoutExt: target) ,
902
952
" graph should omit source: \( target) " )
903
953
}
904
954
}
905
955
func ensureOmits( name: String ) {
956
+ // Written this way to show the faulty node when the assertion fails
906
957
nodeFinder. forEachNode { node in
907
958
XCTAssertFalse ( node. contains ( name: name) ,
908
959
" graph should omit decl named: \( name) " )
@@ -1097,11 +1148,24 @@ fileprivate extension Array where Element == Diagnostic.Message {
1097
1148
static func skipped( _ inputs: String ... ) -> Self {
1098
1149
skipped ( inputs)
1099
1150
}
1100
- static func skippingAll( _ inputs: String ... ) -> Self {
1151
+ static func skippingAll( _ inputs: [ String ] ) -> Self {
1101
1152
[
1102
1153
maySkip ( inputs) , skipping ( inputs) , skippingLinking, skipped ( inputs)
1103
1154
] . flatMap { $0}
1104
1155
}
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
+ }
1105
1169
1106
1170
// MARK: - batching
1107
1171
static func addingToBatch( _ inputs: [ String ] , _ b: Int ) -> Self {
0 commit comments