| 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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 }); | 598 }); |
| 598 expect(manager.partLibrariesMap[part1], [library1]); | 599 expect(manager.partLibrariesMap[part1], [library1]); |
| 599 expect(manager.partLibrariesMap[part2], [library1, library2]); | 600 expect(manager.partLibrariesMap[part2], [library1, library2]); |
| 600 expect(manager.partLibrariesMap[part3], [library2]); | 601 expect(manager.partLibrariesMap[part3], [library2]); |
| 601 expect(manager.libraryPartsMap[library1], [part1, part2]); | 602 expect(manager.libraryPartsMap[library1], [part1, part2]); |
| 602 expect(manager.libraryPartsMap[library2], [part2, part3]); | 603 expect(manager.libraryPartsMap[library2], [part2, part3]); |
| 603 // part1 CONTAINING_LIBRARIES | 604 // part1 CONTAINING_LIBRARIES |
| 604 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); | 605 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); |
| 605 } | 606 } |
| 606 | 607 |
| 608 void test_resultsComputed_inSDK() { |
| 609 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock(); |
| 610 // SDK context mock |
| 611 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock(); |
| 612 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]); |
| 613 // SDK mock |
| 614 DartSdk sdkMock = new _DartSdkMock(); |
| 615 when(sdkMock.context).thenReturn(sdkContextMock); |
| 616 // SourceFactory mock |
| 617 SourceFactory sourceFactory = new _SourceFactoryMock(); |
| 618 when(sourceFactory.dartSdk).thenReturn(sdkMock); |
| 619 when(context.sourceFactory).thenReturn(sourceFactory); |
| 620 // SDK source mock |
| 621 Source source = new _SourceMock('test.dart'); |
| 622 when(source.source).thenReturn(source); |
| 623 when(source.isInSystemLibrary).thenReturn(true); |
| 624 // notify and validate |
| 625 Map<ResultDescriptor, dynamic> outputs = <ResultDescriptor, dynamic>{}; |
| 626 manager.resultsComputed(source, outputs); |
| 627 verify(sdkDartWorkManagerMock.resultsComputed(source, outputs)).once(); |
| 628 } |
| 629 |
| 607 void test_resultsComputed_noSourceKind() { | 630 void test_resultsComputed_noSourceKind() { |
| 608 manager.unknownSourceQueue.addAll([source1, source2]); | 631 manager.unknownSourceQueue.addAll([source1, source2]); |
| 609 manager.resultsComputed(source1, {}); | 632 manager.resultsComputed(source1, {}); |
| 610 expect_librarySourceQueue([]); | 633 expect_librarySourceQueue([]); |
| 611 expect_unknownSourceQueue([source1, source2]); | 634 expect_unknownSourceQueue([source1, source2]); |
| 612 } | 635 } |
| 613 | 636 |
| 614 void test_resultsComputed_notDart() { | 637 void test_resultsComputed_notDart() { |
| 615 manager.unknownSourceQueue.addAll([source1, source2]); | 638 manager.unknownSourceQueue.addAll([source1, source2]); |
| 616 manager.resultsComputed(new TestSource('test.html'), {}); | 639 manager.resultsComputed(new TestSource('test.html'), {}); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 CacheEntry _getOrCreateEntry(Source source) { | 722 CacheEntry _getOrCreateEntry(Source source) { |
| 700 CacheEntry entry = cache.get(source); | 723 CacheEntry entry = cache.get(source); |
| 701 if (entry == null) { | 724 if (entry == null) { |
| 702 entry = new CacheEntry(source); | 725 entry = new CacheEntry(source); |
| 703 cache.put(entry); | 726 cache.put(entry); |
| 704 } | 727 } |
| 705 return entry; | 728 return entry; |
| 706 } | 729 } |
| 707 } | 730 } |
| 708 | 731 |
| 732 class _DartSdkMock extends TypedMock implements DartSdk { |
| 733 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 734 } |
| 735 |
| 736 class _DartWorkManagerMock extends TypedMock implements DartWorkManager { |
| 737 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 738 } |
| 739 |
| 709 class _InternalAnalysisContextMock extends TypedMock | 740 class _InternalAnalysisContextMock extends TypedMock |
| 710 implements InternalAnalysisContext { | 741 implements InternalAnalysisContext { |
| 711 @override | 742 @override |
| 712 CachePartition privateAnalysisCachePartition; | 743 CachePartition privateAnalysisCachePartition; |
| 713 | 744 |
| 714 @override | 745 @override |
| 715 AnalysisCache analysisCache; | 746 AnalysisCache analysisCache; |
| 716 | 747 |
| 717 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; | 748 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; |
| 718 | 749 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 732 } | 763 } |
| 733 | 764 |
| 734 @override | 765 @override |
| 735 ChangeNoticeImpl getNotice(Source source) { | 766 ChangeNoticeImpl getNotice(Source source) { |
| 736 return _pendingNotices.putIfAbsent( | 767 return _pendingNotices.putIfAbsent( |
| 737 source, () => new ChangeNoticeImpl(source)); | 768 source, () => new ChangeNoticeImpl(source)); |
| 738 } | 769 } |
| 739 | 770 |
| 740 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 771 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 741 } | 772 } |
| 773 |
| 774 class _SourceFactoryMock extends TypedMock implements SourceFactory { |
| 775 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 776 } |
| 777 |
| 778 class _SourceMock extends TypedMock implements Source { |
| 779 final String shortName; |
| 780 _SourceMock(this.shortName); |
| 781 @override |
| 782 String get fullName => '/' + shortName; |
| 783 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 784 @override |
| 785 String toString() => fullName; |
| 786 } |
| OLD | NEW |