| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.src.task.dart_work_manager_test; | 5 library test.src.task.dart_work_manager_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show | 10 show |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 import '../../reflective_tests.dart'; | 30 import '../../reflective_tests.dart'; |
| 31 | 31 |
| 32 main() { | 32 main() { |
| 33 groupSep = ' | '; | 33 groupSep = ' | '; |
| 34 runReflectiveTests(DartWorkManagerTest); | 34 runReflectiveTests(DartWorkManagerTest); |
| 35 } | 35 } |
| 36 | 36 |
| 37 @reflectiveTest | 37 @reflectiveTest |
| 38 class DartWorkManagerTest { | 38 class DartWorkManagerTest { |
| 39 InternalAnalysisContext context = new _InternalAnalysisContextMock(); | 39 InternalAnalysisContext context = new _InternalAnalysisContextMock(); |
| 40 AnalysisCache cache; |
| 40 DartWorkManager manager; | 41 DartWorkManager manager; |
| 41 | 42 |
| 42 CaughtException caughtException = new CaughtException(null, null); | 43 CaughtException caughtException = new CaughtException(null, null); |
| 43 | 44 |
| 44 Source source1 = new TestSource('1.dart'); | 45 Source source1 = new TestSource('1.dart'); |
| 45 Source source2 = new TestSource('2.dart'); | 46 Source source2 = new TestSource('2.dart'); |
| 46 Source source3 = new TestSource('3.dart'); | 47 Source source3 = new TestSource('3.dart'); |
| 47 Source source4 = new TestSource('4.dart'); | 48 Source source4 = new TestSource('4.dart'); |
| 48 CacheEntry entry1; | 49 CacheEntry entry1; |
| 49 CacheEntry entry2; | 50 CacheEntry entry2; |
| 50 CacheEntry entry3; | 51 CacheEntry entry3; |
| 51 CacheEntry entry4; | 52 CacheEntry entry4; |
| 52 | 53 |
| 53 void expect_librarySourceQueue(List<Source> sources) { | 54 void expect_librarySourceQueue(List<Source> sources) { |
| 54 expect(manager.librarySourceQueue, unorderedEquals(sources)); | 55 expect(manager.librarySourceQueue, unorderedEquals(sources)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void expect_unknownSourceQueue(List<Source> sources) { | 58 void expect_unknownSourceQueue(List<Source> sources) { |
| 58 expect(manager.unknownSourceQueue, unorderedEquals(sources)); | 59 expect(manager.unknownSourceQueue, unorderedEquals(sources)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void setUp() { | 62 void setUp() { |
| 63 cache = context.analysisCache; |
| 62 manager = new DartWorkManager(context); | 64 manager = new DartWorkManager(context); |
| 63 entry1 = context.getCacheEntry(source1); | 65 entry1 = context.getCacheEntry(source1); |
| 64 entry2 = context.getCacheEntry(source2); | 66 entry2 = context.getCacheEntry(source2); |
| 65 entry3 = context.getCacheEntry(source3); | 67 entry3 = context.getCacheEntry(source3); |
| 66 entry4 = context.getCacheEntry(source4); | 68 entry4 = context.getCacheEntry(source4); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void test_applyChange_add() { | 71 void test_applyChange_add() { |
| 70 // add source1 | 72 // add source1 |
| 71 manager.applyChange([source1], [], []); | 73 manager.applyChange([source1], [], []); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); | 438 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); |
| 437 // PARSED_UNIT is ready, set errors | 439 // PARSED_UNIT is ready, set errors |
| 438 manager.resultsComputed( | 440 manager.resultsComputed( |
| 439 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); | 441 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); |
| 440 // all of the errors are included | 442 // all of the errors are included |
| 441 ChangeNoticeImpl notice = context.getNotice(source1); | 443 ChangeNoticeImpl notice = context.getNotice(source1); |
| 442 expect(notice.errors, unorderedEquals([error1, error2])); | 444 expect(notice.errors, unorderedEquals([error1, error2])); |
| 443 expect(notice.lineInfo, lineInfo); | 445 expect(notice.lineInfo, lineInfo); |
| 444 } | 446 } |
| 445 | 447 |
| 446 void test_resultsComputed_includedParts() { | 448 void test_resultsComputed_includedParts_turnLibraryIntoPart() { |
| 449 when(context.shouldErrorsBeAnalyzed(anyObject, null)).thenReturn(true); |
| 450 Source library = new TestSource('library.dart'); |
| 451 Source part = new TestSource('part.dart'); |
| 452 // library "library" (real) |
| 453 manager.resultsComputed(library, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 454 CacheEntry libraryEntry = new CacheEntry(library); |
| 455 cache.put(libraryEntry); |
| 456 libraryEntry.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 457 // library "part" (speculative) |
| 458 manager.resultsComputed(part, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 459 CacheEntry partEntry = new CacheEntry(part); |
| 460 cache.put(partEntry); |
| 461 partEntry.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 462 // unit "part in part" (speculative) |
| 463 AnalysisTarget partInPartTarget = new LibrarySpecificUnit(part, part); |
| 464 CacheEntry partInPartEntry = new CacheEntry(partInPartTarget); |
| 465 cache.put(partInPartEntry); |
| 466 // so far we consider "part" a library |
| 467 expect(manager.librarySourceQueue, contains(part)); |
| 468 expect(partEntry.getValue(SOURCE_KIND), SourceKind.LIBRARY); |
| 469 expect(cache.get(partInPartTarget), isNotNull); |
| 470 // "part" is used as a part in "library" |
| 471 manager.resultsComputed(library, {INCLUDED_PARTS: [part]}); |
| 472 expect(manager.partLibrariesMap[part], [library]); |
| 473 expect(manager.libraryPartsMap[library], [part]); |
| 474 // now we know that "part" is not a library |
| 475 expect(manager.librarySourceQueue, isNot(contains(part))); |
| 476 expect(partEntry.getValue(SOURCE_KIND), SourceKind.PART); |
| 477 expect(cache.get(partInPartTarget), isNull); |
| 478 } |
| 479 |
| 480 void test_resultsComputed_includedParts_updatePartLibraries() { |
| 447 Source part1 = new TestSource('part1.dart'); | 481 Source part1 = new TestSource('part1.dart'); |
| 448 Source part2 = new TestSource('part2.dart'); | 482 Source part2 = new TestSource('part2.dart'); |
| 449 Source part3 = new TestSource('part3.dart'); | 483 Source part3 = new TestSource('part3.dart'); |
| 450 Source library1 = new TestSource('library1.dart'); | 484 Source library1 = new TestSource('library1.dart'); |
| 451 Source library2 = new TestSource('library2.dart'); | 485 Source library2 = new TestSource('library2.dart'); |
| 452 // library1 parts | 486 // library1 parts |
| 453 manager.resultsComputed(library1, {INCLUDED_PARTS: [part1, part2]}); | 487 manager.resultsComputed(library1, {INCLUDED_PARTS: [part1, part2]}); |
| 454 expect(manager.partLibrariesMap[part1], [library1]); | 488 expect(manager.partLibrariesMap[part1], [library1]); |
| 455 expect(manager.partLibrariesMap[part2], [library1]); | 489 expect(manager.partLibrariesMap[part2], [library1]); |
| 456 expect(manager.partLibrariesMap[part3], isNull); | 490 expect(manager.partLibrariesMap[part3], isNull); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 } | 576 } |
| 543 | 577 |
| 544 @override | 578 @override |
| 545 ChangeNoticeImpl getNotice(Source source) { | 579 ChangeNoticeImpl getNotice(Source source) { |
| 546 return _pendingNotices.putIfAbsent( | 580 return _pendingNotices.putIfAbsent( |
| 547 source, () => new ChangeNoticeImpl(source)); | 581 source, () => new ChangeNoticeImpl(source)); |
| 548 } | 582 } |
| 549 | 583 |
| 550 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 584 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 551 } | 585 } |
| OLD | NEW |