| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // remove part1 | 203 // remove part1 |
| 204 manager.applyChange([], [], [part1]); | 204 manager.applyChange([], [], [part1]); |
| 205 expect(manager.partLibrariesMap[part1], isNull); | 205 expect(manager.partLibrariesMap[part1], isNull); |
| 206 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); | 206 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); |
| 207 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); | 207 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); |
| 208 expect(manager.libraryPartsMap[library1], [part1, part3]); | 208 expect(manager.libraryPartsMap[library1], [part1, part3]); |
| 209 expect(manager.libraryPartsMap[library2], [part1, part2]); | 209 expect(manager.libraryPartsMap[library2], [part1, part2]); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void test_applyPriorityTargets_isLibrary_computeErrors() { | 212 void test_applyPriorityTargets_isLibrary_computeErrors() { |
| 213 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 213 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true); |
| 214 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true); | 214 when(context.shouldErrorsBeAnalyzed(source3)).thenReturn(true); |
| 215 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 215 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 216 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 216 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 217 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 217 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 218 manager.priorityResultQueue | 218 manager.priorityResultQueue |
| 219 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); | 219 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); |
| 220 manager.priorityResultQueue | 220 manager.priorityResultQueue |
| 221 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); | 221 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); |
| 222 // -source1 +source3 | 222 // -source1 +source3 |
| 223 manager.applyPriorityTargets([source2, source3]); | 223 manager.applyPriorityTargets([source2, source3]); |
| 224 expect( | 224 expect( |
| 225 manager.priorityResultQueue, | 225 manager.priorityResultQueue, |
| 226 unorderedEquals([ | 226 unorderedEquals([ |
| 227 new TargetedResult(source2, LIBRARY_ERRORS_READY), | 227 new TargetedResult(source2, LIBRARY_ERRORS_READY), |
| 228 new TargetedResult(source3, LIBRARY_ERRORS_READY) | 228 new TargetedResult(source3, LIBRARY_ERRORS_READY) |
| 229 ])); | 229 ])); |
| 230 // get next request | 230 // get next request |
| 231 TargetedResult request = manager.getNextResult(); | 231 TargetedResult request = manager.getNextResult(); |
| 232 expect(request.target, source2); | 232 expect(request.target, source2); |
| 233 expect(request.result, LIBRARY_ERRORS_READY); | 233 expect(request.result, LIBRARY_ERRORS_READY); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void test_applyPriorityTargets_isLibrary_computeUnit() { | 236 void test_applyPriorityTargets_isLibrary_computeUnit() { |
| 237 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); | 237 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(false); |
| 238 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(false); | 238 when(context.shouldErrorsBeAnalyzed(source3)).thenReturn(false); |
| 239 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 239 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 240 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 240 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 241 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 241 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 242 manager.priorityResultQueue | 242 manager.priorityResultQueue |
| 243 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); | 243 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); |
| 244 manager.priorityResultQueue | 244 manager.priorityResultQueue |
| 245 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); | 245 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); |
| 246 // -source1 +source3 | 246 // -source1 +source3 |
| 247 manager.applyPriorityTargets([source2, source3]); | 247 manager.applyPriorityTargets([source2, source3]); |
| 248 expect( | 248 expect( |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 void test_resultsComputed_includedParts_updatePartLibraries() { | 604 void test_resultsComputed_includedParts_updatePartLibraries() { |
| 605 Source part1 = new TestSource('part1.dart'); | 605 Source part1 = new TestSource('part1.dart'); |
| 606 Source part2 = new TestSource('part2.dart'); | 606 Source part2 = new TestSource('part2.dart'); |
| 607 Source part3 = new TestSource('part3.dart'); | 607 Source part3 = new TestSource('part3.dart'); |
| 608 Source library1 = new TestSource('library1.dart'); | 608 Source library1 = new TestSource('library1.dart'); |
| 609 Source library2 = new TestSource('library2.dart'); | 609 Source library2 = new TestSource('library2.dart'); |
| 610 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); | 610 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); |
| 611 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); | 611 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); |
| 612 // configure AnalysisContext mock | 612 // configure AnalysisContext mock |
| 613 when(context.prioritySources).thenReturn(<Source>[]); | 613 when(context.prioritySources).thenReturn(<Source>[]); |
| 614 when(context.shouldErrorsBeAnalyzed(anyObject, anyObject)) | 614 when(context.shouldErrorsBeAnalyzed(anyObject)).thenReturn(false); |
| 615 .thenReturn(false); | |
| 616 // library1 parts | 615 // library1 parts |
| 617 manager.resultsComputed(library1, { | 616 manager.resultsComputed(library1, { |
| 618 INCLUDED_PARTS: [part1, part2], | 617 INCLUDED_PARTS: [part1, part2], |
| 619 SOURCE_KIND: SourceKind.LIBRARY | 618 SOURCE_KIND: SourceKind.LIBRARY |
| 620 }); | 619 }); |
| 621 expect(manager.partLibrariesMap[part1], [library1]); | 620 expect(manager.partLibrariesMap[part1], [library1]); |
| 622 expect(manager.partLibrariesMap[part2], [library1]); | 621 expect(manager.partLibrariesMap[part2], [library1]); |
| 623 expect(manager.partLibrariesMap[part3], isNull); | 622 expect(manager.partLibrariesMap[part3], isNull); |
| 624 expect(manager.libraryPartsMap[library1], [part1, part2]); | 623 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 625 expect(manager.libraryPartsMap[library2], isNull); | 624 expect(manager.libraryPartsMap[library2], isNull); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); | 697 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); |
| 699 ChangeNoticeImpl notice = context.getNotice(source2); | 698 ChangeNoticeImpl notice = context.getNotice(source2); |
| 700 expect(notice.parsedDartUnit, isNull); | 699 expect(notice.parsedDartUnit, isNull); |
| 701 expect(notice.resolvedDartUnit, unit); | 700 expect(notice.resolvedDartUnit, unit); |
| 702 expect(notice.lineInfo, lineInfo); | 701 expect(notice.lineInfo, lineInfo); |
| 703 } | 702 } |
| 704 | 703 |
| 705 void test_resultsComputed_sourceKind_isLibrary() { | 704 void test_resultsComputed_sourceKind_isLibrary() { |
| 706 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 705 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 707 when(context.prioritySources).thenReturn(<Source>[]); | 706 when(context.prioritySources).thenReturn(<Source>[]); |
| 708 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 707 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true); |
| 709 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 708 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 710 expect_librarySourceQueue([source2]); | 709 expect_librarySourceQueue([source2]); |
| 711 expect_unknownSourceQueue([source1, source3]); | 710 expect_unknownSourceQueue([source1, source3]); |
| 712 } | 711 } |
| 713 | 712 |
| 714 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() { | 713 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() { |
| 715 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 714 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 716 when(context.prioritySources).thenReturn(<Source>[source2]); | 715 when(context.prioritySources).thenReturn(<Source>[source2]); |
| 717 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); | 716 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true); |
| 718 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 717 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 719 expect_unknownSourceQueue([source1, source3]); | 718 expect_unknownSourceQueue([source1, source3]); |
| 720 expect(manager.priorityResultQueue, | 719 expect(manager.priorityResultQueue, |
| 721 unorderedEquals([new TargetedResult(source2, LIBRARY_ERRORS_READY)])); | 720 unorderedEquals([new TargetedResult(source2, LIBRARY_ERRORS_READY)])); |
| 722 } | 721 } |
| 723 | 722 |
| 724 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() { | 723 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() { |
| 725 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 724 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
| 726 when(context.prioritySources).thenReturn(<Source>[source2]); | 725 when(context.prioritySources).thenReturn(<Source>[source2]); |
| 727 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); | 726 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(false); |
| 728 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); | 727 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); |
| 729 expect_unknownSourceQueue([source1, source3]); | 728 expect_unknownSourceQueue([source1, source3]); |
| 730 expect( | 729 expect( |
| 731 manager.priorityResultQueue, | 730 manager.priorityResultQueue, |
| 732 unorderedEquals([ | 731 unorderedEquals([ |
| 733 new TargetedResult( | 732 new TargetedResult( |
| 734 new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT) | 733 new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT) |
| 735 ])); | 734 ])); |
| 736 } | 735 } |
| 737 | 736 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 809 |
| 811 class _SourceMock extends TypedMock implements Source { | 810 class _SourceMock extends TypedMock implements Source { |
| 812 final String shortName; | 811 final String shortName; |
| 813 _SourceMock(this.shortName); | 812 _SourceMock(this.shortName); |
| 814 @override | 813 @override |
| 815 String get fullName => '/' + shortName; | 814 String get fullName => '/' + shortName; |
| 816 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 815 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 817 @override | 816 @override |
| 818 String toString() => fullName; | 817 String toString() => fullName; |
| 819 } | 818 } |
| OLD | NEW |