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 analyzer.test.src.task.dart_work_manager_test; | 5 library analyzer.test.src.task.dart_work_manager_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/error/error.dart' show AnalysisError; | 8 import 'package:analyzer/error/error.dart' show AnalysisError; |
9 import 'package:analyzer/exception/exception.dart'; | 9 import 'package:analyzer/exception/exception.dart'; |
10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
11 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; | 11 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; |
12 import 'package:analyzer/src/generated/engine.dart' | 12 import 'package:analyzer/src/generated/engine.dart' |
13 show | 13 show |
14 AnalysisErrorInfoImpl, | 14 AnalysisErrorInfoImpl, |
15 AnalysisOptions, | 15 AnalysisOptions, |
16 AnalysisOptionsImpl, | 16 AnalysisOptionsImpl, |
17 CacheState, | 17 CacheState, |
18 ChangeNoticeImpl, | 18 ChangeNoticeImpl, |
19 InternalAnalysisContext; | 19 InternalAnalysisContext; |
20 import 'package:analyzer/src/generated/sdk.dart'; | 20 import 'package:analyzer/src/generated/sdk.dart'; |
21 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
22 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; | 22 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
23 import 'package:analyzer/src/task/dart.dart'; | 23 import 'package:analyzer/src/task/dart.dart'; |
24 import 'package:analyzer/src/task/dart_work_manager.dart'; | 24 import 'package:analyzer/src/task/dart_work_manager.dart'; |
25 import 'package:analyzer/task/dart.dart'; | 25 import 'package:analyzer/task/dart.dart'; |
26 import 'package:analyzer/task/general.dart'; | 26 import 'package:analyzer/task/general.dart'; |
27 import 'package:analyzer/task/model.dart'; | 27 import 'package:analyzer/task/model.dart'; |
| 28 import 'package:mockito/mockito.dart'; |
28 import 'package:test/test.dart'; | 29 import 'package:test/test.dart'; |
29 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 30 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
30 import 'package:typed_mock/typed_mock.dart'; | |
31 | 31 |
32 import '../../generated/test_support.dart'; | 32 import '../../generated/test_support.dart'; |
33 | 33 |
34 main() { | 34 main() { |
35 defineReflectiveSuite(() { | 35 defineReflectiveSuite(() { |
36 defineReflectiveTests(DartWorkManagerTest); | 36 defineReflectiveTests(DartWorkManagerTest); |
37 }); | 37 }); |
38 } | 38 } |
39 | 39 |
40 @reflectiveTest | 40 @reflectiveTest |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 324 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
325 AnalysisError error2 = | 325 AnalysisError error2 = |
326 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 326 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
327 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 327 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
328 entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []); | 328 entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []); |
329 List<AnalysisError> errors = manager.getErrors(source1); | 329 List<AnalysisError> errors = manager.getErrors(source1); |
330 expect(errors, unorderedEquals([error1, error2])); | 330 expect(errors, unorderedEquals([error1, error2])); |
331 } | 331 } |
332 | 332 |
333 void test_getLibrariesContainingPart() { | 333 void test_getLibrariesContainingPart() { |
334 when(context.aboutToComputeResult(anyObject, anyObject)).thenReturn(false); | 334 when(context.aboutToComputeResult(any, any)).thenReturn(false); |
335 Source part1 = new TestSource('part1.dart'); | 335 Source part1 = new TestSource('part1.dart'); |
336 Source part2 = new TestSource('part2.dart'); | 336 Source part2 = new TestSource('part2.dart'); |
337 Source part3 = new TestSource('part3.dart'); | 337 Source part3 = new TestSource('part3.dart'); |
338 Source library1 = new TestSource('library1.dart'); | 338 Source library1 = new TestSource('library1.dart'); |
339 Source library2 = new TestSource('library2.dart'); | 339 Source library2 = new TestSource('library2.dart'); |
340 manager.partLibrariesMap[part1] = [library1, library2]; | 340 manager.partLibrariesMap[part1] = [library1, library2]; |
341 manager.partLibrariesMap[part2] = [library2]; | 341 manager.partLibrariesMap[part2] = [library2]; |
342 manager.libraryPartsMap[library1] = [part1]; | 342 manager.libraryPartsMap[library1] = [part1]; |
343 manager.libraryPartsMap[library2] = [part1, part2]; | 343 manager.libraryPartsMap[library2] = [part1, part2]; |
344 // getLibrariesContainingPart | 344 // getLibrariesContainingPart |
345 expect(manager.getLibrariesContainingPart(part1), | 345 expect(manager.getLibrariesContainingPart(part1), |
346 unorderedEquals([library1, library2])); | 346 unorderedEquals([library1, library2])); |
347 expect( | 347 expect( |
348 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); | 348 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); |
349 expect(manager.getLibrariesContainingPart(part3), isEmpty); | 349 expect(manager.getLibrariesContainingPart(part3), isEmpty); |
350 } | 350 } |
351 | 351 |
352 void test_getLibrariesContainingPart_askResultProvider() { | 352 void test_getLibrariesContainingPart_askResultProvider() { |
353 Source part1 = new TestSource('part1.dart'); | 353 Source part1 = new TestSource('part1.dart'); |
354 Source part2 = new TestSource('part2.dart'); | 354 Source part2 = new TestSource('part2.dart'); |
355 Source part3 = new TestSource('part3.dart'); | 355 Source part3 = new TestSource('part3.dart'); |
356 Source library1 = new TestSource('library1.dart'); | 356 Source library1 = new TestSource('library1.dart'); |
357 Source library2 = new TestSource('library2.dart'); | 357 Source library2 = new TestSource('library2.dart'); |
358 // configure AnalysisContext mock | 358 // configure AnalysisContext mock |
359 when(context.aboutToComputeResult(anyObject, CONTAINING_LIBRARIES)) | 359 when(context.aboutToComputeResult(any, CONTAINING_LIBRARIES)) |
360 .thenInvoke((CacheEntry entry, ResultDescriptor result) { | 360 .thenAnswer((invocation) { |
| 361 CacheEntry entry = invocation.positionalArguments[0]; |
| 362 ResultDescriptor result = invocation.positionalArguments[1]; |
361 if (entry.target == part1) { | 363 if (entry.target == part1) { |
362 entry.setValue(result as ResultDescriptor<List<Source>>, | 364 entry.setValue(result as ResultDescriptor<List<Source>>, |
363 <Source>[library1, library2], []); | 365 <Source>[library1, library2], []); |
364 return true; | 366 return true; |
365 } | 367 } |
366 if (entry.target == part2) { | 368 if (entry.target == part2) { |
367 entry.setValue( | 369 entry.setValue( |
368 result as ResultDescriptor<List<Source>>, <Source>[library2], []); | 370 result as ResultDescriptor<List<Source>>, <Source>[library2], []); |
369 return true; | 371 return true; |
370 } | 372 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 void test_getNextResultPriority_hasUnknown() { | 524 void test_getNextResultPriority_hasUnknown() { |
523 manager.unknownSourceQueue.addAll([source1]); | 525 manager.unknownSourceQueue.addAll([source1]); |
524 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 526 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); |
525 } | 527 } |
526 | 528 |
527 void test_getNextResultPriority_nothingToDo() { | 529 void test_getNextResultPriority_nothingToDo() { |
528 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 530 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); |
529 } | 531 } |
530 | 532 |
531 void test_onAnalysisOptionsChanged() { | 533 void test_onAnalysisOptionsChanged() { |
532 when(context.exists(anyObject)).thenReturn(true); | 534 when(context.exists(any)).thenReturn(true); |
533 // set cache values | 535 // set cache values |
534 entry1.setValue(PARSED_UNIT, AstTestFactory.compilationUnit(), []); | 536 entry1.setValue(PARSED_UNIT, AstTestFactory.compilationUnit(), []); |
535 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 537 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
536 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 538 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
537 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 539 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
538 entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 540 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
539 // configure LibrarySpecificUnit | 541 // configure LibrarySpecificUnit |
540 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 542 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
541 CacheEntry unitEntry = new CacheEntry(unitTarget); | 543 CacheEntry unitEntry = new CacheEntry(unitTarget); |
542 cache.put(unitEntry); | 544 cache.put(unitEntry); |
(...skipping 23 matching lines...) Expand all Loading... |
566 entry3.setValue(LIBRARY_ERRORS_READY, true, []); | 568 entry3.setValue(LIBRARY_ERRORS_READY, true, []); |
567 // invalidate LIBRARY_ERRORS_READY for source1, schedule it | 569 // invalidate LIBRARY_ERRORS_READY for source1, schedule it |
568 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 570 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); |
569 expect_librarySourceQueue([source1]); | 571 expect_librarySourceQueue([source1]); |
570 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled | 572 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled |
571 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 573 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); |
572 expect_librarySourceQueue([source1]); | 574 expect_librarySourceQueue([source1]); |
573 } | 575 } |
574 | 576 |
575 void test_onSourceFactoryChanged() { | 577 void test_onSourceFactoryChanged() { |
576 when(context.exists(anyObject)).thenReturn(true); | 578 when(context.exists(any)).thenReturn(true); |
577 // set cache values | 579 // set cache values |
578 entry1.setValue(PARSED_UNIT, AstTestFactory.compilationUnit(), []); | 580 entry1.setValue(PARSED_UNIT, AstTestFactory.compilationUnit(), []); |
579 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 581 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
580 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 582 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
581 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 583 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
582 entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 584 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
583 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []); | 585 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []); |
584 entry1.setValue(UNITS, <Source>[], []); | 586 entry1.setValue(UNITS, <Source>[], []); |
585 // configure LibrarySpecificUnit | 587 // configure LibrarySpecificUnit |
586 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 588 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 void test_resultsComputed_includedParts_updatePartLibraries() { | 652 void test_resultsComputed_includedParts_updatePartLibraries() { |
651 Source part1 = new TestSource('part1.dart'); | 653 Source part1 = new TestSource('part1.dart'); |
652 Source part2 = new TestSource('part2.dart'); | 654 Source part2 = new TestSource('part2.dart'); |
653 Source part3 = new TestSource('part3.dart'); | 655 Source part3 = new TestSource('part3.dart'); |
654 Source library1 = new TestSource('library1.dart'); | 656 Source library1 = new TestSource('library1.dart'); |
655 Source library2 = new TestSource('library2.dart'); | 657 Source library2 = new TestSource('library2.dart'); |
656 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); | 658 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); |
657 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); | 659 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); |
658 // configure AnalysisContext mock | 660 // configure AnalysisContext mock |
659 when(context.prioritySources).thenReturn(<Source>[]); | 661 when(context.prioritySources).thenReturn(<Source>[]); |
660 when(context.shouldErrorsBeAnalyzed(anyObject)).thenReturn(false); | 662 when(context.shouldErrorsBeAnalyzed(any)).thenReturn(false); |
661 // library1 parts | 663 // library1 parts |
662 manager.resultsComputed(library1, <ResultDescriptor, dynamic>{ | 664 manager.resultsComputed(library1, <ResultDescriptor, dynamic>{ |
663 INCLUDED_PARTS: [part1, part2], | 665 INCLUDED_PARTS: [part1, part2], |
664 SOURCE_KIND: SourceKind.LIBRARY | 666 SOURCE_KIND: SourceKind.LIBRARY |
665 }); | 667 }); |
666 expect(manager.partLibrariesMap[part1], [library1]); | 668 expect(manager.partLibrariesMap[part1], [library1]); |
667 expect(manager.partLibrariesMap[part2], [library1]); | 669 expect(manager.partLibrariesMap[part2], [library1]); |
668 expect(manager.partLibrariesMap[part3], isNull); | 670 expect(manager.partLibrariesMap[part3], isNull); |
669 expect(manager.libraryPartsMap[library1], [part1, part2]); | 671 expect(manager.libraryPartsMap[library1], [part1, part2]); |
670 expect(manager.libraryPartsMap[library2], isNull); | 672 expect(manager.libraryPartsMap[library2], isNull); |
(...skipping 23 matching lines...) Expand all Loading... |
694 SourceFactory sourceFactory = new _SourceFactoryMock(); | 696 SourceFactory sourceFactory = new _SourceFactoryMock(); |
695 when(sourceFactory.dartSdk).thenReturn(sdkMock); | 697 when(sourceFactory.dartSdk).thenReturn(sdkMock); |
696 when(context.sourceFactory).thenReturn(sourceFactory); | 698 when(context.sourceFactory).thenReturn(sourceFactory); |
697 // SDK source mock | 699 // SDK source mock |
698 Source source = new _SourceMock('test.dart'); | 700 Source source = new _SourceMock('test.dart'); |
699 when(source.source).thenReturn(source); | 701 when(source.source).thenReturn(source); |
700 when(source.isInSystemLibrary).thenReturn(true); | 702 when(source.isInSystemLibrary).thenReturn(true); |
701 // notify and validate | 703 // notify and validate |
702 Map<ResultDescriptor, dynamic> outputs = <ResultDescriptor, dynamic>{}; | 704 Map<ResultDescriptor, dynamic> outputs = <ResultDescriptor, dynamic>{}; |
703 manager.resultsComputed(source, outputs); | 705 manager.resultsComputed(source, outputs); |
704 verify(sdkDartWorkManagerMock.resultsComputed(source, outputs)).once(); | 706 verify(sdkDartWorkManagerMock.resultsComputed(source, outputs)).called(1); |
705 } | 707 } |
706 | 708 |
707 void test_resultsComputed_noSourceKind() { | 709 void test_resultsComputed_noSourceKind() { |
708 manager.unknownSourceQueue.addAll([source1, source2]); | 710 manager.unknownSourceQueue.addAll([source1, source2]); |
709 manager.resultsComputed(source1, {}); | 711 manager.resultsComputed(source1, {}); |
710 expect_librarySourceQueue([]); | 712 expect_librarySourceQueue([]); |
711 expect_unknownSourceQueue([source1, source2]); | 713 expect_unknownSourceQueue([source1, source2]); |
712 } | 714 } |
713 | 715 |
714 void test_resultsComputed_notDart() { | 716 void test_resultsComputed_notDart() { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 CacheEntry entry = cache.get(source); | 809 CacheEntry entry = cache.get(source); |
808 if (entry == null) { | 810 if (entry == null) { |
809 entry = new CacheEntry(source); | 811 entry = new CacheEntry(source); |
810 entry.explicitlyAdded = explicit; | 812 entry.explicitlyAdded = explicit; |
811 cache.put(entry); | 813 cache.put(entry); |
812 } | 814 } |
813 return entry; | 815 return entry; |
814 } | 816 } |
815 } | 817 } |
816 | 818 |
817 class _DartSdkMock extends TypedMock implements DartSdk {} | 819 class _DartSdkMock extends Mock implements DartSdk {} |
818 | 820 |
819 class _DartWorkManagerMock extends TypedMock implements DartWorkManager {} | 821 class _DartWorkManagerMock extends Mock implements DartWorkManager {} |
820 | 822 |
821 class _InternalAnalysisContextMock extends TypedMock | 823 class _InternalAnalysisContextMock extends Mock |
822 implements InternalAnalysisContext { | 824 implements InternalAnalysisContext { |
823 @override | 825 @override |
824 CachePartition privateAnalysisCachePartition; | 826 CachePartition privateAnalysisCachePartition; |
825 | 827 |
826 @override | 828 @override |
827 AnalysisCache analysisCache; | 829 AnalysisCache analysisCache; |
828 | 830 |
829 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; | 831 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; |
830 | 832 |
831 @override | 833 @override |
(...skipping 21 matching lines...) Expand all Loading... |
853 return entry; | 855 return entry; |
854 } | 856 } |
855 | 857 |
856 @override | 858 @override |
857 ChangeNoticeImpl getNotice(Source source) { | 859 ChangeNoticeImpl getNotice(Source source) { |
858 return _pendingNotices.putIfAbsent( | 860 return _pendingNotices.putIfAbsent( |
859 source, () => new ChangeNoticeImpl(source)); | 861 source, () => new ChangeNoticeImpl(source)); |
860 } | 862 } |
861 } | 863 } |
862 | 864 |
863 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | 865 class _SourceFactoryMock extends Mock implements SourceFactory {} |
864 | 866 |
865 class _SourceMock extends TypedMock implements Source { | 867 class _SourceMock extends Mock implements Source { |
866 final String shortName; | 868 final String shortName; |
867 _SourceMock(this.shortName); | 869 _SourceMock(this.shortName); |
868 @override | 870 @override |
869 String get fullName => '/' + shortName; | 871 String get fullName => '/' + shortName; |
870 @override | 872 @override |
871 String toString() => fullName; | 873 String toString() => fullName; |
872 } | 874 } |
OLD | NEW |