@@ -286,6 +286,61 @@ final class BuildSystemManagerTests: XCTestCase {
286
286
bsm. fileBuildSettingsChanged ( Set ( [ cpp] ) )
287
287
288
288
wait ( for: [ changed1, changed2] , timeout: 10 , enforceOrder: false )
289
+
290
+ bs. map [ cpp] = FileBuildSettings ( compilerArguments: [ " Third C++ Main File " ] , language: . cpp)
291
+ let changed3 = expectation ( description: " third settings h1 via cpp " )
292
+ let changed4 = expectation ( description: " third settings h2 via cpp " )
293
+ del. expected = [
294
+ ( h1, bs. map [ cpp] !, changed3, #file, #line) ,
295
+ ( h2, bs. map [ cpp] !, changed4, #file, #line) ,
296
+ ]
297
+ bsm. fileBuildSettingsChanged ( Set ( [ ] ) ) // Empty => all
298
+ wait ( for: [ changed3, changed4] , timeout: 10 , enforceOrder: false )
299
+ }
300
+
301
+ func testSettingsChangedAfterUnregister( ) {
302
+ let a = DocumentURI ( string: " bsm:a.swift " )
303
+ let b = DocumentURI ( string: " bsm:b.swift " )
304
+ let c = DocumentURI ( string: " bsm:c.swift " )
305
+ let mainFiles = ManualMainFilesProvider ( )
306
+ mainFiles. mainFiles = [ a: Set ( [ a] ) , b: Set ( [ b] ) , c: Set ( [ c] ) ]
307
+ let bs = ManualBuildSystem ( )
308
+ let bsm = BuildSystemManager ( buildSystem: bs, mainFilesProvider: mainFiles)
309
+ let del = BSMDelegate ( bsm)
310
+
311
+ bs. map [ a] = FileBuildSettings ( compilerArguments: [ " a " ] , language: . swift)
312
+ bs. map [ b] = FileBuildSettings ( compilerArguments: [ " b " ] , language: . swift)
313
+ bs. map [ c] = FileBuildSettings ( compilerArguments: [ " c " ] , language: . swift)
314
+
315
+ let initialA = expectation ( description: " initial settings a " )
316
+ let initialB = expectation ( description: " initial settings b " )
317
+ let initialC = expectation ( description: " initial settings c " )
318
+ del. expected = [
319
+ ( a, bs. map [ a] !, initialA, #file, #line) ,
320
+ ( b, bs. map [ b] !, initialB, #file, #line) ,
321
+ ( c, bs. map [ c] !, initialC, #file, #line) ,
322
+ ]
323
+ bsm. registerForChangeNotifications ( for: a, language: . swift)
324
+ bsm. registerForChangeNotifications ( for: b, language: . swift)
325
+ bsm. registerForChangeNotifications ( for: c, language: . swift)
326
+ wait ( for: [ initialA, initialB, initialC] , timeout: 10 , enforceOrder: false )
327
+
328
+ bs. map [ a] = FileBuildSettings ( compilerArguments: [ " new-a " ] , language: . swift)
329
+ bs. map [ b] = FileBuildSettings ( compilerArguments: [ " new-b " ] , language: . swift)
330
+ bs. map [ c] = FileBuildSettings ( compilerArguments: [ " new-c " ] , language: . swift)
331
+
332
+ let changedB = expectation ( description: " changed settings b " )
333
+ del. expected = [
334
+ ( b, bs. map [ b] !, changedB, #file, #line) ,
335
+ ]
336
+
337
+ bsm. unregisterForChangeNotifications ( for: a)
338
+ bsm. unregisterForChangeNotifications ( for: c)
339
+ // At this point only b is registered, but that can race with notifications,
340
+ // so ensure nothing bad happens and we still get the notification for b.
341
+ bsm. fileBuildSettingsChanged ( [ a, b, c] )
342
+
343
+ wait ( for: [ changedB] , timeout: 10 , enforceOrder: false )
289
344
}
290
345
}
291
346
0 commit comments