@@ -1200,10 +1200,10 @@ TEST_F(TUSchedulerTests, IncluderCache) {
1200
1200
Unreliable = testPath (" unreliable.h" ),
1201
1201
OK = testPath (" ok.h" ),
1202
1202
NotIncluded = testPath (" not_included.h" );
1203
- class NoHeadersCDB : public GlobalCompilationDatabase {
1203
+ struct NoHeadersCDB : public GlobalCompilationDatabase {
1204
1204
llvm::Optional<tooling::CompileCommand>
1205
1205
getCompileCommand (PathRef File) const override {
1206
- if (File == NoCmd || File == NotIncluded)
1206
+ if (File == NoCmd || File == NotIncluded || FailAll )
1207
1207
return llvm::None;
1208
1208
auto Basic = getFallbackCommand (File);
1209
1209
Basic.Heuristic .clear ();
@@ -1218,6 +1218,8 @@ TEST_F(TUSchedulerTests, IncluderCache) {
1218
1218
}
1219
1219
return Basic;
1220
1220
}
1221
+
1222
+ std::atomic<bool > FailAll{false };
1221
1223
} CDB;
1222
1224
TUScheduler S (CDB, optsForTest ());
1223
1225
auto GetFlags = [&](PathRef Header) {
@@ -1288,6 +1290,21 @@ TEST_F(TUSchedulerTests, IncluderCache) {
1288
1290
<< " association invalidated but not reclaimed" ;
1289
1291
EXPECT_THAT (GetFlags (NotIncluded), Contains (" -DMAIN2" ))
1290
1292
<< " association still valid" ;
1293
+
1294
+ // Delete the file from CDB, it should invalidate the associations.
1295
+ CDB.FailAll = true ;
1296
+ EXPECT_THAT (GetFlags (NoCmd), Not (Contains (" -DMAIN3" )))
1297
+ << " association should've been invalidated." ;
1298
+ // Also run update for Main3 to invalidate the preeamble to make sure next
1299
+ // update populates include cache associations.
1300
+ S.update (Main3, getInputs (Main3, SomeIncludes), WantDiagnostics::Yes);
1301
+ EXPECT_TRUE (S.blockUntilIdle (timeoutSeconds (10 )));
1302
+ // Re-add the file and make sure nothing crashes.
1303
+ CDB.FailAll = false ;
1304
+ S.update (Main3, getInputs (Main3, SomeIncludes), WantDiagnostics::Yes);
1305
+ EXPECT_TRUE (S.blockUntilIdle (timeoutSeconds (10 )));
1306
+ EXPECT_THAT (GetFlags (NoCmd), Contains (" -DMAIN3" ))
1307
+ << " association invalidated and then claimed by main3" ;
1291
1308
}
1292
1309
1293
1310
TEST_F (TUSchedulerTests, PreservesLastActiveFile) {
0 commit comments