| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file | 
|  | 2 // for details. All rights reserved. Use of this source code is governed by a | 
|  | 3 // BSD-style license that can be found in the LICENSE file. | 
|  | 4 | 
|  | 5 library test.src.task.dart_work_manager_test; | 
|  | 6 | 
|  | 7 import 'package:analyzer/src/context/cache.dart'; | 
|  | 8 import 'package:analyzer/src/generated/ast.dart'; | 
|  | 9 import 'package:analyzer/src/generated/engine.dart' | 
|  | 10     show | 
|  | 11         AnalysisErrorInfo, | 
|  | 12         AnalysisErrorInfoImpl, | 
|  | 13         CacheState, | 
|  | 14         ChangeNoticeImpl, | 
|  | 15         InternalAnalysisContext; | 
|  | 16 import 'package:analyzer/src/generated/error.dart' show AnalysisError; | 
|  | 17 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 
|  | 18 import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode; | 
|  | 19 import 'package:analyzer/src/generated/source.dart'; | 
|  | 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 
|  | 21 import 'package:analyzer/src/task/dart.dart'; | 
|  | 22 import 'package:analyzer/src/task/dart_work_manager.dart'; | 
|  | 23 import 'package:analyzer/task/dart.dart'; | 
|  | 24 import 'package:analyzer/task/general.dart'; | 
|  | 25 import 'package:analyzer/task/model.dart'; | 
|  | 26 import 'package:typed_mock/typed_mock.dart'; | 
|  | 27 import 'package:unittest/unittest.dart'; | 
|  | 28 | 
|  | 29 import '../../generated/test_support.dart'; | 
|  | 30 import '../../reflective_tests.dart'; | 
|  | 31 import '../../utils.dart'; | 
|  | 32 | 
|  | 33 main() { | 
|  | 34   initializeTestEnvironment(); | 
|  | 35   runReflectiveTests(DartWorkManagerTest); | 
|  | 36 } | 
|  | 37 | 
|  | 38 @reflectiveTest | 
|  | 39 class DartWorkManagerTest { | 
|  | 40   InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 
|  | 41   AnalysisCache cache; | 
|  | 42   DartWorkManager manager; | 
|  | 43 | 
|  | 44   CaughtException caughtException = new CaughtException(null, null); | 
|  | 45 | 
|  | 46   Source source1 = new TestSource('1.dart'); | 
|  | 47   Source source2 = new TestSource('2.dart'); | 
|  | 48   Source source3 = new TestSource('3.dart'); | 
|  | 49   Source source4 = new TestSource('4.dart'); | 
|  | 50   CacheEntry entry1; | 
|  | 51   CacheEntry entry2; | 
|  | 52   CacheEntry entry3; | 
|  | 53   CacheEntry entry4; | 
|  | 54 | 
|  | 55   void expect_librarySourceQueue(List<Source> sources) { | 
|  | 56     expect(manager.librarySourceQueue, unorderedEquals(sources)); | 
|  | 57   } | 
|  | 58 | 
|  | 59   void expect_unknownSourceQueue(List<Source> sources) { | 
|  | 60     expect(manager.unknownSourceQueue, unorderedEquals(sources)); | 
|  | 61   } | 
|  | 62 | 
|  | 63   void setUp() { | 
|  | 64     cache = context.analysisCache; | 
|  | 65     manager = new DartWorkManager(context); | 
|  | 66     entry1 = context.getCacheEntry(source1); | 
|  | 67     entry2 = context.getCacheEntry(source2); | 
|  | 68     entry3 = context.getCacheEntry(source3); | 
|  | 69     entry4 = context.getCacheEntry(source4); | 
|  | 70   } | 
|  | 71 | 
|  | 72   void test_applyChange_add() { | 
|  | 73     // add source1 | 
|  | 74     manager.applyChange([source1], [], []); | 
|  | 75     expect_unknownSourceQueue([source1]); | 
|  | 76     expect_librarySourceQueue([]); | 
|  | 77     // add source2 | 
|  | 78     manager.applyChange([source2], [], []); | 
|  | 79     expect_librarySourceQueue([]); | 
|  | 80     expect_unknownSourceQueue([source1, source2]); | 
|  | 81   } | 
|  | 82 | 
|  | 83   void test_applyChange_add_duplicate() { | 
|  | 84     // add source1 | 
|  | 85     manager.applyChange([source1], [], []); | 
|  | 86     expect_unknownSourceQueue([source1]); | 
|  | 87     expect_librarySourceQueue([]); | 
|  | 88     // add source2 | 
|  | 89     manager.applyChange([source1], [], []); | 
|  | 90     expect_librarySourceQueue([]); | 
|  | 91     expect_unknownSourceQueue([source1]); | 
|  | 92   } | 
|  | 93 | 
|  | 94   void test_applyChange_addRemove() { | 
|  | 95     manager.applyChange([source1, source2], [], [source2, source3]); | 
|  | 96     expect_unknownSourceQueue([source1]); | 
|  | 97     expect_librarySourceQueue([]); | 
|  | 98   } | 
|  | 99 | 
|  | 100   void test_applyChange_change() { | 
|  | 101     manager.librarySourceQueue.addAll([source1, source3]); | 
|  | 102     manager.unknownSourceQueue.addAll([source4]); | 
|  | 103     // change source1 | 
|  | 104     manager.applyChange([], [source1], []); | 
|  | 105     expect_librarySourceQueue([source3]); | 
|  | 106     expect_unknownSourceQueue([source4, source1]); | 
|  | 107   } | 
|  | 108 | 
|  | 109   void test_applyChange_remove() { | 
|  | 110     manager.librarySourceQueue.addAll([source1, source3]); | 
|  | 111     manager.unknownSourceQueue.addAll([source4]); | 
|  | 112     // remove source1 | 
|  | 113     manager.applyChange([], [], [source1]); | 
|  | 114     expect_librarySourceQueue([source3]); | 
|  | 115     expect_unknownSourceQueue([source4]); | 
|  | 116     // remove source3 | 
|  | 117     manager.applyChange([], [], [source3]); | 
|  | 118     expect_librarySourceQueue([]); | 
|  | 119     expect_unknownSourceQueue([source4]); | 
|  | 120     // remove source4 | 
|  | 121     manager.applyChange([], [], [source4]); | 
|  | 122     expect_librarySourceQueue([]); | 
|  | 123     expect_unknownSourceQueue([]); | 
|  | 124   } | 
|  | 125 | 
|  | 126   void test_applyChange_updatePartsLibraries_changeLibrary() { | 
|  | 127     Source part1 = new TestSource('part1.dart'); | 
|  | 128     Source part2 = new TestSource('part2.dart'); | 
|  | 129     Source part3 = new TestSource('part3.dart'); | 
|  | 130     Source library1 = new TestSource('library1.dart'); | 
|  | 131     Source library2 = new TestSource('library2.dart'); | 
|  | 132     manager.partLibrariesMap[part1] = [library1, library2]; | 
|  | 133     manager.partLibrariesMap[part2] = [library2]; | 
|  | 134     manager.partLibrariesMap[part3] = [library1]; | 
|  | 135     manager.libraryPartsMap[library1] = [part1, part3]; | 
|  | 136     manager.libraryPartsMap[library2] = [part1, part2]; | 
|  | 137     _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); | 
|  | 138     expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); | 
|  | 139     // change library1 | 
|  | 140     manager.applyChange([], [library1], []); | 
|  | 141     expect(manager.partLibrariesMap[part1], unorderedEquals([library2])); | 
|  | 142     expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 
|  | 143     expect(manager.partLibrariesMap[part3], unorderedEquals([])); | 
|  | 144     expect(manager.libraryPartsMap[library1], isNull); | 
|  | 145     expect(manager.libraryPartsMap[library2], [part1, part2]); | 
|  | 146     expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); | 
|  | 147   } | 
|  | 148 | 
|  | 149   void test_applyChange_updatePartsLibraries_changePart() { | 
|  | 150     Source part1 = new TestSource('part1.dart'); | 
|  | 151     Source part2 = new TestSource('part2.dart'); | 
|  | 152     Source part3 = new TestSource('part3.dart'); | 
|  | 153     Source library1 = new TestSource('library1.dart'); | 
|  | 154     Source library2 = new TestSource('library2.dart'); | 
|  | 155     manager.partLibrariesMap[part1] = [library1, library2]; | 
|  | 156     manager.partLibrariesMap[part2] = [library2]; | 
|  | 157     manager.partLibrariesMap[part3] = [library1]; | 
|  | 158     manager.libraryPartsMap[library1] = [part1, part3]; | 
|  | 159     manager.libraryPartsMap[library2] = [part1, part2]; | 
|  | 160     _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); | 
|  | 161     expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); | 
|  | 162     // change part1 | 
|  | 163     manager.applyChange([], [part1], []); | 
|  | 164     expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 
|  | 165     expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); | 
|  | 166     expect(manager.libraryPartsMap[library1], [part1, part3]); | 
|  | 167     expect(manager.libraryPartsMap[library2], [part1, part2]); | 
|  | 168     expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); | 
|  | 169   } | 
|  | 170 | 
|  | 171   void test_applyChange_updatePartsLibraries_removeLibrary() { | 
|  | 172     Source part1 = new TestSource('part1.dart'); | 
|  | 173     Source part2 = new TestSource('part2.dart'); | 
|  | 174     Source part3 = new TestSource('part3.dart'); | 
|  | 175     Source library1 = new TestSource('library1.dart'); | 
|  | 176     Source library2 = new TestSource('library2.dart'); | 
|  | 177     manager.partLibrariesMap[part1] = [library1, library2]; | 
|  | 178     manager.partLibrariesMap[part2] = [library2]; | 
|  | 179     manager.partLibrariesMap[part3] = [library1]; | 
|  | 180     manager.libraryPartsMap[library1] = [part1, part3]; | 
|  | 181     manager.libraryPartsMap[library2] = [part1, part2]; | 
|  | 182     // remove library1 | 
|  | 183     manager.applyChange([], [], [library1]); | 
|  | 184     expect(manager.partLibrariesMap[part1], unorderedEquals([library2])); | 
|  | 185     expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 
|  | 186     expect(manager.partLibrariesMap[part3], unorderedEquals([])); | 
|  | 187     expect(manager.libraryPartsMap[library1], isNull); | 
|  | 188     expect(manager.libraryPartsMap[library2], [part1, part2]); | 
|  | 189   } | 
|  | 190 | 
|  | 191   void test_applyChange_updatePartsLibraries_removePart() { | 
|  | 192     Source part1 = new TestSource('part1.dart'); | 
|  | 193     Source part2 = new TestSource('part2.dart'); | 
|  | 194     Source part3 = new TestSource('part3.dart'); | 
|  | 195     Source library1 = new TestSource('library1.dart'); | 
|  | 196     Source library2 = new TestSource('library2.dart'); | 
|  | 197     manager.partLibrariesMap[part1] = [library1, library2]; | 
|  | 198     manager.partLibrariesMap[part2] = [library2]; | 
|  | 199     manager.partLibrariesMap[part3] = [library1]; | 
|  | 200     manager.libraryPartsMap[library1] = [part1, part3]; | 
|  | 201     manager.libraryPartsMap[library2] = [part1, part2]; | 
|  | 202     // remove part1 | 
|  | 203     manager.applyChange([], [], [part1]); | 
|  | 204     expect(manager.partLibrariesMap[part1], isNull); | 
|  | 205     expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 
|  | 206     expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); | 
|  | 207     expect(manager.libraryPartsMap[library1], [part1, part3]); | 
|  | 208     expect(manager.libraryPartsMap[library2], [part1, part2]); | 
|  | 209   } | 
|  | 210 | 
|  | 211   void test_applyPriorityTargets_isLibrary_computeErrors() { | 
|  | 212     when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 
|  | 213     when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true); | 
|  | 214     entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 215     entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 216     entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 217     manager.priorityResultQueue | 
|  | 218         .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); | 
|  | 219     manager.priorityResultQueue | 
|  | 220         .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); | 
|  | 221     // -source1 +source3 | 
|  | 222     manager.applyPriorityTargets([source2, source3]); | 
|  | 223     expect( | 
|  | 224         manager.priorityResultQueue, | 
|  | 225         unorderedEquals([ | 
|  | 226           new TargetedResult(source2, LIBRARY_ERRORS_READY), | 
|  | 227           new TargetedResult(source3, LIBRARY_ERRORS_READY) | 
|  | 228         ])); | 
|  | 229     // get next request | 
|  | 230     TargetedResult request = manager.getNextResult(); | 
|  | 231     expect(request.target, source2); | 
|  | 232     expect(request.result, LIBRARY_ERRORS_READY); | 
|  | 233   } | 
|  | 234 | 
|  | 235   void test_applyPriorityTargets_isLibrary_computeUnit() { | 
|  | 236     when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); | 
|  | 237     when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(false); | 
|  | 238     entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 239     entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 240     entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 241     manager.priorityResultQueue | 
|  | 242         .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); | 
|  | 243     manager.priorityResultQueue | 
|  | 244         .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); | 
|  | 245     // -source1 +source3 | 
|  | 246     manager.applyPriorityTargets([source2, source3]); | 
|  | 247     expect( | 
|  | 248         manager.priorityResultQueue, | 
|  | 249         unorderedEquals([ | 
|  | 250           new TargetedResult( | 
|  | 251               new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT), | 
|  | 252           new TargetedResult( | 
|  | 253               new LibrarySpecificUnit(source3, source3), RESOLVED_UNIT), | 
|  | 254         ])); | 
|  | 255   } | 
|  | 256 | 
|  | 257   void test_applyPriorityTargets_isPart() { | 
|  | 258     entry1.setValue(SOURCE_KIND, SourceKind.PART, []); | 
|  | 259     entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 260     entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 261     // +source2 +source3 | 
|  | 262     when(context.getLibrariesContaining(source1)) | 
|  | 263         .thenReturn([source2, source3]); | 
|  | 264     manager.applyPriorityTargets([source1]); | 
|  | 265     expect( | 
|  | 266         manager.priorityResultQueue, | 
|  | 267         unorderedEquals([ | 
|  | 268           new TargetedResult(source2, LIBRARY_ERRORS_READY), | 
|  | 269           new TargetedResult(source3, LIBRARY_ERRORS_READY) | 
|  | 270         ])); | 
|  | 271     // get next request | 
|  | 272     TargetedResult request = manager.getNextResult(); | 
|  | 273     expect(request.target, source2); | 
|  | 274     expect(request.result, LIBRARY_ERRORS_READY); | 
|  | 275   } | 
|  | 276 | 
|  | 277   void test_applyPriorityTargets_isUnknown() { | 
|  | 278     manager.applyPriorityTargets([source2, source3]); | 
|  | 279     expect( | 
|  | 280         manager.priorityResultQueue, | 
|  | 281         unorderedEquals([ | 
|  | 282           new TargetedResult(source2, SOURCE_KIND), | 
|  | 283           new TargetedResult(source3, SOURCE_KIND) | 
|  | 284         ])); | 
|  | 285     // get next request | 
|  | 286     TargetedResult request = manager.getNextResult(); | 
|  | 287     expect(request.target, source2); | 
|  | 288     expect(request.result, SOURCE_KIND); | 
|  | 289   } | 
|  | 290 | 
|  | 291   void test_getErrors() { | 
|  | 292     AnalysisError error1 = | 
|  | 293         new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 294     AnalysisError error2 = | 
|  | 295         new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 296     when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 
|  | 297     entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 
|  | 298     context | 
|  | 299         .getCacheEntry(new LibrarySpecificUnit(source2, source1)) | 
|  | 300         .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); | 
|  | 301     List<AnalysisError> errors = manager.getErrors(source1); | 
|  | 302     expect(errors, unorderedEquals([error1, error2])); | 
|  | 303   } | 
|  | 304 | 
|  | 305   void test_getErrors_hasFullList() { | 
|  | 306     AnalysisError error1 = | 
|  | 307         new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 308     AnalysisError error2 = | 
|  | 309         new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 310     when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 
|  | 311     entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []); | 
|  | 312     List<AnalysisError> errors = manager.getErrors(source1); | 
|  | 313     expect(errors, unorderedEquals([error1, error2])); | 
|  | 314   } | 
|  | 315 | 
|  | 316   void test_getLibrariesContainingPart() { | 
|  | 317     Source part1 = new TestSource('part1.dart'); | 
|  | 318     Source part2 = new TestSource('part2.dart'); | 
|  | 319     Source part3 = new TestSource('part3.dart'); | 
|  | 320     Source library1 = new TestSource('library1.dart'); | 
|  | 321     Source library2 = new TestSource('library2.dart'); | 
|  | 322     manager.partLibrariesMap[part1] = [library1, library2]; | 
|  | 323     manager.partLibrariesMap[part2] = [library2]; | 
|  | 324     manager.libraryPartsMap[library1] = [part1]; | 
|  | 325     manager.libraryPartsMap[library2] = [part1, part2]; | 
|  | 326     // getLibrariesContainingPart | 
|  | 327     expect(manager.getLibrariesContainingPart(part1), | 
|  | 328         unorderedEquals([library1, library2])); | 
|  | 329     expect( | 
|  | 330         manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); | 
|  | 331     expect(manager.getLibrariesContainingPart(part3), isEmpty); | 
|  | 332   } | 
|  | 333 | 
|  | 334   void test_getNextResult_hasLibraries_firstIsError() { | 
|  | 335     entry1.setErrorState(caughtException, [LIBRARY_ERRORS_READY]); | 
|  | 336     manager.librarySourceQueue.addAll([source1, source2]); | 
|  | 337     TargetedResult request = manager.getNextResult(); | 
|  | 338     expect(request.target, source2); | 
|  | 339     expect(request.result, LIBRARY_ERRORS_READY); | 
|  | 340     // source1 is out, source2 is waiting | 
|  | 341     expect_librarySourceQueue([source2]); | 
|  | 342   } | 
|  | 343 | 
|  | 344   void test_getNextResult_hasLibraries_firstIsInvalid() { | 
|  | 345     entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 
|  | 346     manager.librarySourceQueue.addAll([source1, source2]); | 
|  | 347     TargetedResult request = manager.getNextResult(); | 
|  | 348     expect(request.target, source1); | 
|  | 349     expect(request.result, LIBRARY_ERRORS_READY); | 
|  | 350     // no changes until computed | 
|  | 351     expect_librarySourceQueue([source1, source2]); | 
|  | 352   } | 
|  | 353 | 
|  | 354   void test_getNextResult_hasLibraries_firstIsValid() { | 
|  | 355     entry1.setValue(LIBRARY_ERRORS_READY, true, []); | 
|  | 356     manager.librarySourceQueue.addAll([source1, source2]); | 
|  | 357     TargetedResult request = manager.getNextResult(); | 
|  | 358     expect(request.target, source2); | 
|  | 359     expect(request.result, LIBRARY_ERRORS_READY); | 
|  | 360     // source1 is out, source2 is waiting | 
|  | 361     expect_librarySourceQueue([source2]); | 
|  | 362   } | 
|  | 363 | 
|  | 364   void test_getNextResult_hasPriority_firstIsError() { | 
|  | 365     manager.addPriorityResult(source1, SOURCE_KIND); | 
|  | 366     manager.addPriorityResult(source2, SOURCE_KIND); | 
|  | 367     expect( | 
|  | 368         manager.priorityResultQueue, | 
|  | 369         unorderedEquals([ | 
|  | 370           new TargetedResult(source1, SOURCE_KIND), | 
|  | 371           new TargetedResult(source2, SOURCE_KIND) | 
|  | 372         ])); | 
|  | 373     // configure state and get next result | 
|  | 374     entry1.setErrorState(caughtException, [SOURCE_KIND]); | 
|  | 375     TargetedResult request = manager.getNextResult(); | 
|  | 376     expect(request.target, source2); | 
|  | 377     expect(request.result, SOURCE_KIND); | 
|  | 378     // source1 is out, source2 is waiting | 
|  | 379     expect(manager.priorityResultQueue, | 
|  | 380         unorderedEquals([new TargetedResult(source2, SOURCE_KIND)])); | 
|  | 381   } | 
|  | 382 | 
|  | 383   void test_getNextResult_hasPriority_firstIsValid() { | 
|  | 384     manager.addPriorityResult(source1, SOURCE_KIND); | 
|  | 385     manager.addPriorityResult(source2, SOURCE_KIND); | 
|  | 386     expect( | 
|  | 387         manager.priorityResultQueue, | 
|  | 388         unorderedEquals([ | 
|  | 389           new TargetedResult(source1, SOURCE_KIND), | 
|  | 390           new TargetedResult(source2, SOURCE_KIND) | 
|  | 391         ])); | 
|  | 392     // configure state and get next result | 
|  | 393     entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 394     TargetedResult request = manager.getNextResult(); | 
|  | 395     expect(request.target, source2); | 
|  | 396     expect(request.result, SOURCE_KIND); | 
|  | 397     // source1 is out, source2 is waiting | 
|  | 398     expect(manager.priorityResultQueue, | 
|  | 399         unorderedEquals([new TargetedResult(source2, SOURCE_KIND)])); | 
|  | 400   } | 
|  | 401 | 
|  | 402   void test_getNextResult_hasUnknown_firstIsError() { | 
|  | 403     entry1.setErrorState(caughtException, [SOURCE_KIND]); | 
|  | 404     manager.unknownSourceQueue.addAll([source1, source2]); | 
|  | 405     TargetedResult request = manager.getNextResult(); | 
|  | 406     expect(request.target, source2); | 
|  | 407     expect(request.result, SOURCE_KIND); | 
|  | 408     // source1 is out, source2 is waiting | 
|  | 409     expect_librarySourceQueue([]); | 
|  | 410     expect_unknownSourceQueue([source2]); | 
|  | 411   } | 
|  | 412 | 
|  | 413   void test_getNextResult_hasUnknown_firstIsInvalid() { | 
|  | 414     manager.unknownSourceQueue.addAll([source1, source2]); | 
|  | 415     TargetedResult request = manager.getNextResult(); | 
|  | 416     expect(request.target, source1); | 
|  | 417     expect(request.result, SOURCE_KIND); | 
|  | 418     // no changes until computed | 
|  | 419     expect_librarySourceQueue([]); | 
|  | 420     expect_unknownSourceQueue([source1, source2]); | 
|  | 421   } | 
|  | 422 | 
|  | 423   void test_getNextResult_hasUnknown_firstIsValid() { | 
|  | 424     entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 425     manager.unknownSourceQueue.addAll([source1, source2]); | 
|  | 426     TargetedResult request = manager.getNextResult(); | 
|  | 427     expect(request.target, source2); | 
|  | 428     expect(request.result, SOURCE_KIND); | 
|  | 429     // source1 is out, source2 is waiting | 
|  | 430     expect_librarySourceQueue([]); | 
|  | 431     expect_unknownSourceQueue([source2]); | 
|  | 432   } | 
|  | 433 | 
|  | 434   void test_getNextResult_nothingToDo() { | 
|  | 435     TargetedResult request = manager.getNextResult(); | 
|  | 436     expect(request, isNull); | 
|  | 437   } | 
|  | 438 | 
|  | 439   void test_getNextResultPriority_hasLibrary() { | 
|  | 440     manager.librarySourceQueue.addAll([source1]); | 
|  | 441     expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 
|  | 442   } | 
|  | 443 | 
|  | 444   void test_getNextResultPriority_hasPriority() { | 
|  | 445     manager.addPriorityResult(source1, SOURCE_KIND); | 
|  | 446     expect(manager.getNextResultPriority(), WorkOrderPriority.PRIORITY); | 
|  | 447   } | 
|  | 448 | 
|  | 449   void test_getNextResultPriority_hasUnknown() { | 
|  | 450     manager.unknownSourceQueue.addAll([source1]); | 
|  | 451     expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 
|  | 452   } | 
|  | 453 | 
|  | 454   void test_getNextResultPriority_nothingToDo() { | 
|  | 455     expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 
|  | 456   } | 
|  | 457 | 
|  | 458   void test_onAnalysisOptionsChanged() { | 
|  | 459     when(context.exists(anyObject)).thenReturn(true); | 
|  | 460     // set cache values | 
|  | 461     entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); | 
|  | 462     entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 
|  | 463     entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 
|  | 464     entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 
|  | 465     entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 
|  | 466     // configure LibrarySpecificUnit | 
|  | 467     LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 
|  | 468     CacheEntry unitEntry = new CacheEntry(unitTarget); | 
|  | 469     cache.put(unitEntry); | 
|  | 470     unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); | 
|  | 471     expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); | 
|  | 472     // notify | 
|  | 473     manager.onAnalysisOptionsChanged(); | 
|  | 474     // resolution is invalidated | 
|  | 475     expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); | 
|  | 476     // ...but URIs are still value | 
|  | 477     expect(entry1.getState(PARSED_UNIT), CacheState.VALID); | 
|  | 478     expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID); | 
|  | 479     expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID); | 
|  | 480     expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID); | 
|  | 481     expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID); | 
|  | 482   } | 
|  | 483 | 
|  | 484   void test_onResultInvalidated_scheduleInvalidatedLibraries() { | 
|  | 485     // set SOURCE_KIND | 
|  | 486     entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 487     entry2.setValue(SOURCE_KIND, SourceKind.PART, []); | 
|  | 488     entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 
|  | 489     // set LIBRARY_ERRORS_READY for source1 and source3 | 
|  | 490     entry1.setValue(LIBRARY_ERRORS_READY, true, []); | 
|  | 491     entry3.setValue(LIBRARY_ERRORS_READY, true, []); | 
|  | 492     // invalidate LIBRARY_ERRORS_READY for source1, schedule it | 
|  | 493     entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 
|  | 494     expect_librarySourceQueue([source1]); | 
|  | 495     // invalidate LIBRARY_ERRORS_READY for source3, schedule it | 
|  | 496     entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 
|  | 497     expect_librarySourceQueue([source1, source3]); | 
|  | 498   } | 
|  | 499 | 
|  | 500   void test_onSourceFactoryChanged() { | 
|  | 501     when(context.exists(anyObject)).thenReturn(true); | 
|  | 502     // set cache values | 
|  | 503     entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); | 
|  | 504     entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 
|  | 505     entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 
|  | 506     entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 
|  | 507     entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 
|  | 508     // configure LibrarySpecificUnit | 
|  | 509     LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 
|  | 510     CacheEntry unitEntry = new CacheEntry(unitTarget); | 
|  | 511     cache.put(unitEntry); | 
|  | 512     unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); | 
|  | 513     expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); | 
|  | 514     // notify | 
|  | 515     manager.onSourceFactoryChanged(); | 
|  | 516     // resolution is invalidated | 
|  | 517     expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); | 
|  | 518     // ...and URIs resolution too | 
|  | 519     expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); | 
|  | 520     expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); | 
|  | 521     expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); | 
|  | 522     expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); | 
|  | 523     expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); | 
|  | 524   } | 
|  | 525 | 
|  | 526   void test_resultsComputed_errors_forLibrarySpecificUnit() { | 
|  | 527     LineInfo lineInfo = new LineInfo([0]); | 
|  | 528     AnalysisError error1 = | 
|  | 529         new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 530     AnalysisError error2 = | 
|  | 531         new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 532     when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 
|  | 533     when(context.getErrors(source1)) | 
|  | 534         .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); | 
|  | 535     entry1.setValue(LINE_INFO, lineInfo, []); | 
|  | 536     entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 
|  | 537     AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); | 
|  | 538     context | 
|  | 539         .getCacheEntry(unitTarget) | 
|  | 540         .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); | 
|  | 541     // RESOLVED_UNIT is ready, set errors | 
|  | 542     manager.resultsComputed( | 
|  | 543         unitTarget, {RESOLVED_UNIT: AstFactory.compilationUnit()}); | 
|  | 544     // all of the errors are included | 
|  | 545     ChangeNoticeImpl notice = context.getNotice(source1); | 
|  | 546     expect(notice.errors, unorderedEquals([error1, error2])); | 
|  | 547     expect(notice.lineInfo, lineInfo); | 
|  | 548   } | 
|  | 549 | 
|  | 550   void test_resultsComputed_errors_forSource() { | 
|  | 551     LineInfo lineInfo = new LineInfo([0]); | 
|  | 552     AnalysisError error1 = | 
|  | 553         new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 554     AnalysisError error2 = | 
|  | 555         new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 
|  | 556     when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 
|  | 557     when(context.getErrors(source1)) | 
|  | 558         .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); | 
|  | 559     entry1.setValue(LINE_INFO, lineInfo, []); | 
|  | 560     entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 
|  | 561     entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); | 
|  | 562     // PARSED_UNIT is ready, set errors | 
|  | 563     manager.resultsComputed( | 
|  | 564         source1, {PARSED_UNIT: AstFactory.compilationUnit()}); | 
|  | 565     // all of the errors are included | 
|  | 566     ChangeNoticeImpl notice = context.getNotice(source1); | 
|  | 567     expect(notice.errors, unorderedEquals([error1, error2])); | 
|  | 568     expect(notice.lineInfo, lineInfo); | 
|  | 569   } | 
|  | 570 | 
|  | 571   void test_resultsComputed_includedParts_updatePartLibraries() { | 
|  | 572     Source part1 = new TestSource('part1.dart'); | 
|  | 573     Source part2 = new TestSource('part2.dart'); | 
|  | 574     Source part3 = new TestSource('part3.dart'); | 
|  | 575     Source library1 = new TestSource('library1.dart'); | 
|  | 576     Source library2 = new TestSource('library2.dart'); | 
|  | 577     _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); | 
|  | 578     expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); | 
|  | 579     // configure AnalysisContext mock | 
|  | 580     when(context.prioritySources).thenReturn(<Source>[]); | 
|  | 581     when(context.shouldErrorsBeAnalyzed(anyObject, anyObject)) | 
|  | 582         .thenReturn(false); | 
|  | 583     // library1 parts | 
|  | 584     manager.resultsComputed(library1, { | 
|  | 585       INCLUDED_PARTS: [part1, part2], | 
|  | 586       SOURCE_KIND: SourceKind.LIBRARY | 
|  | 587     }); | 
|  | 588     expect(manager.partLibrariesMap[part1], [library1]); | 
|  | 589     expect(manager.partLibrariesMap[part2], [library1]); | 
|  | 590     expect(manager.partLibrariesMap[part3], isNull); | 
|  | 591     expect(manager.libraryPartsMap[library1], [part1, part2]); | 
|  | 592     expect(manager.libraryPartsMap[library2], isNull); | 
|  | 593     // library2 parts | 
|  | 594     manager.resultsComputed(library2, { | 
|  | 595       INCLUDED_PARTS: [part2, part3], | 
|  | 596       SOURCE_KIND: SourceKind.LIBRARY | 
|  | 597     }); | 
|  | 598     expect(manager.partLibrariesMap[part1], [library1]); | 
|  | 599     expect(manager.partLibrariesMap[part2], [library1, library2]); | 
|  | 600     expect(manager.partLibrariesMap[part3], [library2]); | 
|  | 601     expect(manager.libraryPartsMap[library1], [part1, part2]); | 
|  | 602     expect(manager.libraryPartsMap[library2], [part2, part3]); | 
|  | 603     // part1 CONTAINING_LIBRARIES | 
|  | 604     expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); | 
|  | 605   } | 
|  | 606 | 
|  | 607   void test_resultsComputed_noSourceKind() { | 
|  | 608     manager.unknownSourceQueue.addAll([source1, source2]); | 
|  | 609     manager.resultsComputed(source1, {}); | 
|  | 610     expect_librarySourceQueue([]); | 
|  | 611     expect_unknownSourceQueue([source1, source2]); | 
|  | 612   } | 
|  | 613 | 
|  | 614   void test_resultsComputed_notDart() { | 
|  | 615     manager.unknownSourceQueue.addAll([source1, source2]); | 
|  | 616     manager.resultsComputed(new TestSource('test.html'), {}); | 
|  | 617     expect_librarySourceQueue([]); | 
|  | 618     expect_unknownSourceQueue([source1, source2]); | 
|  | 619   } | 
|  | 620 | 
|  | 621   void test_resultsComputed_parsedUnit() { | 
|  | 622     LineInfo lineInfo = new LineInfo([0]); | 
|  | 623     when(context.getLibrariesContaining(source1)).thenReturn([]); | 
|  | 624     when(context.getErrors(source1)) | 
|  | 625         .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); | 
|  | 626     entry1.setValue(LINE_INFO, lineInfo, []); | 
|  | 627     CompilationUnit unit = AstFactory.compilationUnit(); | 
|  | 628     manager.resultsComputed(source1, {PARSED_UNIT: unit}); | 
|  | 629     ChangeNoticeImpl notice = context.getNotice(source1); | 
|  | 630     expect(notice.parsedDartUnit, unit); | 
|  | 631     expect(notice.resolvedDartUnit, isNull); | 
|  | 632     expect(notice.lineInfo, lineInfo); | 
|  | 633   } | 
|  | 634 | 
|  | 635   void test_resultsComputed_resolvedUnit() { | 
|  | 636     LineInfo lineInfo = new LineInfo([0]); | 
|  | 637     when(context.getLibrariesContaining(source2)).thenReturn([]); | 
|  | 638     when(context.getErrors(source2)) | 
|  | 639         .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); | 
|  | 640     entry2.setValue(LINE_INFO, lineInfo, []); | 
|  | 641     CompilationUnit unit = AstFactory.compilationUnit(); | 
|  | 642     manager.resultsComputed( | 
|  | 643         new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); | 
|  | 644     ChangeNoticeImpl notice = context.getNotice(source2); | 
|  | 645     expect(notice.parsedDartUnit, isNull); | 
|  | 646     expect(notice.resolvedDartUnit, unit); | 
|  | 647     expect(notice.lineInfo, lineInfo); | 
|  | 648   } | 
|  | 649 | 
|  | 650   void test_resultsComputed_sourceKind_isLibrary() { | 
|  | 651     manager.unknownSourceQueue.addAll([source1, source2, source3]); | 
|  | 652     when(context.prioritySources).thenReturn(<Source>[]); | 
|  | 653     when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 
|  | 654     manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 
|  | 655     expect_librarySourceQueue([source2]); | 
|  | 656     expect_unknownSourceQueue([source1, source3]); | 
|  | 657   } | 
|  | 658 | 
|  | 659   void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() { | 
|  | 660     manager.unknownSourceQueue.addAll([source1, source2, source3]); | 
|  | 661     when(context.prioritySources).thenReturn(<Source>[source2]); | 
|  | 662     when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 
|  | 663     manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 
|  | 664     expect_unknownSourceQueue([source1, source3]); | 
|  | 665     expect(manager.priorityResultQueue, | 
|  | 666         unorderedEquals([new TargetedResult(source2, LIBRARY_ERRORS_READY)])); | 
|  | 667   } | 
|  | 668 | 
|  | 669   void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() { | 
|  | 670     manager.unknownSourceQueue.addAll([source1, source2, source3]); | 
|  | 671     when(context.prioritySources).thenReturn(<Source>[source2]); | 
|  | 672     when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); | 
|  | 673     manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 
|  | 674     expect_unknownSourceQueue([source1, source3]); | 
|  | 675     expect( | 
|  | 676         manager.priorityResultQueue, | 
|  | 677         unorderedEquals([ | 
|  | 678           new TargetedResult( | 
|  | 679               new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT) | 
|  | 680         ])); | 
|  | 681   } | 
|  | 682 | 
|  | 683   void test_resultsComputed_sourceKind_isPart() { | 
|  | 684     manager.unknownSourceQueue.addAll([source1, source2, source3]); | 
|  | 685     manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); | 
|  | 686     expect_librarySourceQueue([]); | 
|  | 687     expect_unknownSourceQueue([source1, source3]); | 
|  | 688   } | 
|  | 689 | 
|  | 690   void test_resultsComputed_updatePartsLibraries_partParsed() { | 
|  | 691     Source part = new TestSource('part.dart'); | 
|  | 692     expect(manager.libraryPartsMap, isEmpty); | 
|  | 693     // part.dart parsed, no changes is the map of libraries | 
|  | 694     manager.resultsComputed( | 
|  | 695         part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]}); | 
|  | 696     expect(manager.libraryPartsMap, isEmpty); | 
|  | 697   } | 
|  | 698 | 
|  | 699   CacheEntry _getOrCreateEntry(Source source) { | 
|  | 700     CacheEntry entry = cache.get(source); | 
|  | 701     if (entry == null) { | 
|  | 702       entry = new CacheEntry(source); | 
|  | 703       cache.put(entry); | 
|  | 704     } | 
|  | 705     return entry; | 
|  | 706   } | 
|  | 707 } | 
|  | 708 | 
|  | 709 class _InternalAnalysisContextMock extends TypedMock | 
|  | 710     implements InternalAnalysisContext { | 
|  | 711   @override | 
|  | 712   CachePartition privateAnalysisCachePartition; | 
|  | 713 | 
|  | 714   @override | 
|  | 715   AnalysisCache analysisCache; | 
|  | 716 | 
|  | 717   Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; | 
|  | 718 | 
|  | 719   _InternalAnalysisContextMock() { | 
|  | 720     privateAnalysisCachePartition = new UniversalCachePartition(this); | 
|  | 721     analysisCache = new AnalysisCache([privateAnalysisCachePartition]); | 
|  | 722   } | 
|  | 723 | 
|  | 724   @override | 
|  | 725   CacheEntry getCacheEntry(AnalysisTarget target) { | 
|  | 726     CacheEntry entry = analysisCache.get(target); | 
|  | 727     if (entry == null) { | 
|  | 728       entry = new CacheEntry(target); | 
|  | 729       analysisCache.put(entry); | 
|  | 730     } | 
|  | 731     return entry; | 
|  | 732   } | 
|  | 733 | 
|  | 734   @override | 
|  | 735   ChangeNoticeImpl getNotice(Source source) { | 
|  | 736     return _pendingNotices.putIfAbsent( | 
|  | 737         source, () => new ChangeNoticeImpl(source)); | 
|  | 738   } | 
|  | 739 | 
|  | 740   noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 
|  | 741 } | 
| OLD | NEW | 
|---|