| 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 |
| 11 AnalysisErrorInfo, | 11 AnalysisErrorInfo, |
| 12 AnalysisErrorInfoImpl, | 12 AnalysisErrorInfoImpl, |
| 13 CacheState, | 13 CacheState, |
| 14 ChangeNoticeImpl, | 14 ChangeNoticeImpl, |
| 15 InternalAnalysisContext; | 15 InternalAnalysisContext; |
| 16 import 'package:analyzer/src/generated/error.dart' show AnalysisError; | 16 import 'package:analyzer/src/generated/error.dart' show AnalysisError; |
| 17 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 17 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
| 18 import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode; | 18 import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode; |
| 19 import 'package:analyzer/src/generated/sdk.dart'; |
| 19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 21 import 'package:analyzer/src/task/dart.dart'; | 22 import 'package:analyzer/src/task/dart.dart'; |
| 22 import 'package:analyzer/src/task/dart_work_manager.dart'; | 23 import 'package:analyzer/src/task/dart_work_manager.dart'; |
| 23 import 'package:analyzer/task/dart.dart'; | 24 import 'package:analyzer/task/dart.dart'; |
| 24 import 'package:analyzer/task/general.dart'; | 25 import 'package:analyzer/task/general.dart'; |
| 25 import 'package:analyzer/task/model.dart'; | 26 import 'package:analyzer/task/model.dart'; |
| 26 import 'package:typed_mock/typed_mock.dart'; | 27 import 'package:typed_mock/typed_mock.dart'; |
| 27 import 'package:unittest/unittest.dart'; | 28 import 'package:unittest/unittest.dart'; |
| 28 | 29 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 manager.libraryPartsMap[library1] = [part1]; | 325 manager.libraryPartsMap[library1] = [part1]; |
| 325 manager.libraryPartsMap[library2] = [part1, part2]; | 326 manager.libraryPartsMap[library2] = [part1, part2]; |
| 326 // getLibrariesContainingPart | 327 // getLibrariesContainingPart |
| 327 expect(manager.getLibrariesContainingPart(part1), | 328 expect(manager.getLibrariesContainingPart(part1), |
| 328 unorderedEquals([library1, library2])); | 329 unorderedEquals([library1, library2])); |
| 329 expect( | 330 expect( |
| 330 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); | 331 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); |
| 331 expect(manager.getLibrariesContainingPart(part3), isEmpty); | 332 expect(manager.getLibrariesContainingPart(part3), isEmpty); |
| 332 } | 333 } |
| 333 | 334 |
| 335 void test_getLibrariesContainingPart_inSDK() { |
| 336 Source part = new _SourceMock('part.dart'); |
| 337 when(part.isInSystemLibrary).thenReturn(true); |
| 338 // SDK work manager |
| 339 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock(); |
| 340 when(sdkDartWorkManagerMock.getLibrariesContainingPart(part)) |
| 341 .thenReturn([source2, source3]); |
| 342 // SDK context mock |
| 343 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock(); |
| 344 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]); |
| 345 // SDK mock |
| 346 DartSdk sdkMock = new _DartSdkMock(); |
| 347 when(sdkMock.context).thenReturn(sdkContextMock); |
| 348 // SourceFactory mock |
| 349 SourceFactory sourceFactory = new _SourceFactoryMock(); |
| 350 when(sourceFactory.dartSdk).thenReturn(sdkMock); |
| 351 when(context.sourceFactory).thenReturn(sourceFactory); |
| 352 // SDK source mock |
| 353 Source source = new _SourceMock('test.dart'); |
| 354 when(source.source).thenReturn(source); |
| 355 when(source.isInSystemLibrary).thenReturn(true); |
| 356 // validate |
| 357 expect(manager.getLibrariesContainingPart(part), |
| 358 unorderedEquals([source2, source3])); |
| 359 } |
| 360 |
| 334 void test_getNextResult_hasLibraries_firstIsError() { | 361 void test_getNextResult_hasLibraries_firstIsError() { |
| 335 entry1.setErrorState(caughtException, [LIBRARY_ERRORS_READY]); | 362 entry1.setErrorState(caughtException, [LIBRARY_ERRORS_READY]); |
| 336 manager.librarySourceQueue.addAll([source1, source2]); | 363 manager.librarySourceQueue.addAll([source1, source2]); |
| 337 TargetedResult request = manager.getNextResult(); | 364 TargetedResult request = manager.getNextResult(); |
| 338 expect(request.target, source2); | 365 expect(request.target, source2); |
| 339 expect(request.result, LIBRARY_ERRORS_READY); | 366 expect(request.result, LIBRARY_ERRORS_READY); |
| 340 // source1 is out, source2 is waiting | 367 // source1 is out, source2 is waiting |
| 341 expect_librarySourceQueue([source2]); | 368 expect_librarySourceQueue([source2]); |
| 342 } | 369 } |
| 343 | 370 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 }); | 624 }); |
| 598 expect(manager.partLibrariesMap[part1], [library1]); | 625 expect(manager.partLibrariesMap[part1], [library1]); |
| 599 expect(manager.partLibrariesMap[part2], [library1, library2]); | 626 expect(manager.partLibrariesMap[part2], [library1, library2]); |
| 600 expect(manager.partLibrariesMap[part3], [library2]); | 627 expect(manager.partLibrariesMap[part3], [library2]); |
| 601 expect(manager.libraryPartsMap[library1], [part1, part2]); | 628 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 602 expect(manager.libraryPartsMap[library2], [part2, part3]); | 629 expect(manager.libraryPartsMap[library2], [part2, part3]); |
| 603 // part1 CONTAINING_LIBRARIES | 630 // part1 CONTAINING_LIBRARIES |
| 604 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); | 631 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); |
| 605 } | 632 } |
| 606 | 633 |
| 634 void test_resultsComputed_inSDK() { |
| 635 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock(); |
| 636 // SDK context mock |
| 637 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock(); |
| 638 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]); |
| 639 // SDK mock |
| 640 DartSdk sdkMock = new _DartSdkMock(); |
| 641 when(sdkMock.context).thenReturn(sdkContextMock); |
| 642 // SourceFactory mock |
| 643 SourceFactory sourceFactory = new _SourceFactoryMock(); |
| 644 when(sourceFactory.dartSdk).thenReturn(sdkMock); |
| 645 when(context.sourceFactory).thenReturn(sourceFactory); |
| 646 // SDK source mock |
| 647 Source source = new _SourceMock('test.dart'); |
| 648 when(source.source).thenReturn(source); |
| 649 when(source.isInSystemLibrary).thenReturn(true); |
| 650 // notify and validate |
| 651 Map<ResultDescriptor, dynamic> outputs = <ResultDescriptor, dynamic>{}; |
| 652 manager.resultsComputed(source, outputs); |
| 653 verify(sdkDartWorkManagerMock.resultsComputed(source, outputs)).once(); |
| 654 } |
| 655 |
| 607 void test_resultsComputed_noSourceKind() { | 656 void test_resultsComputed_noSourceKind() { |
| 608 manager.unknownSourceQueue.addAll([source1, source2]); | 657 manager.unknownSourceQueue.addAll([source1, source2]); |
| 609 manager.resultsComputed(source1, {}); | 658 manager.resultsComputed(source1, {}); |
| 610 expect_librarySourceQueue([]); | 659 expect_librarySourceQueue([]); |
| 611 expect_unknownSourceQueue([source1, source2]); | 660 expect_unknownSourceQueue([source1, source2]); |
| 612 } | 661 } |
| 613 | 662 |
| 614 void test_resultsComputed_notDart() { | 663 void test_resultsComputed_notDart() { |
| 615 manager.unknownSourceQueue.addAll([source1, source2]); | 664 manager.unknownSourceQueue.addAll([source1, source2]); |
| 616 manager.resultsComputed(new TestSource('test.html'), {}); | 665 manager.resultsComputed(new TestSource('test.html'), {}); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 CacheEntry _getOrCreateEntry(Source source) { | 748 CacheEntry _getOrCreateEntry(Source source) { |
| 700 CacheEntry entry = cache.get(source); | 749 CacheEntry entry = cache.get(source); |
| 701 if (entry == null) { | 750 if (entry == null) { |
| 702 entry = new CacheEntry(source); | 751 entry = new CacheEntry(source); |
| 703 cache.put(entry); | 752 cache.put(entry); |
| 704 } | 753 } |
| 705 return entry; | 754 return entry; |
| 706 } | 755 } |
| 707 } | 756 } |
| 708 | 757 |
| 758 class _DartSdkMock extends TypedMock implements DartSdk { |
| 759 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 760 } |
| 761 |
| 762 class _DartWorkManagerMock extends TypedMock implements DartWorkManager { |
| 763 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 764 } |
| 765 |
| 709 class _InternalAnalysisContextMock extends TypedMock | 766 class _InternalAnalysisContextMock extends TypedMock |
| 710 implements InternalAnalysisContext { | 767 implements InternalAnalysisContext { |
| 711 @override | 768 @override |
| 712 CachePartition privateAnalysisCachePartition; | 769 CachePartition privateAnalysisCachePartition; |
| 713 | 770 |
| 714 @override | 771 @override |
| 715 AnalysisCache analysisCache; | 772 AnalysisCache analysisCache; |
| 716 | 773 |
| 717 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; | 774 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; |
| 718 | 775 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 732 } | 789 } |
| 733 | 790 |
| 734 @override | 791 @override |
| 735 ChangeNoticeImpl getNotice(Source source) { | 792 ChangeNoticeImpl getNotice(Source source) { |
| 736 return _pendingNotices.putIfAbsent( | 793 return _pendingNotices.putIfAbsent( |
| 737 source, () => new ChangeNoticeImpl(source)); | 794 source, () => new ChangeNoticeImpl(source)); |
| 738 } | 795 } |
| 739 | 796 |
| 740 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 797 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 741 } | 798 } |
| 799 |
| 800 class _SourceFactoryMock extends TypedMock implements SourceFactory { |
| 801 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 802 } |
| 803 |
| 804 class _SourceMock extends TypedMock implements Source { |
| 805 final String shortName; |
| 806 _SourceMock(this.shortName); |
| 807 @override |
| 808 String get fullName => '/' + shortName; |
| 809 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 810 @override |
| 811 String toString() => fullName; |
| 812 } |
| OLD | NEW |