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_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:test/test.dart'; | 28 import 'package:test/test.dart'; |
29 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 29 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
30 import 'package:typed_mock/typed_mock.dart'; | 30 import 'package:typed_mock/typed_mock.dart'; |
31 | 31 |
32 import '../../generated/test_support.dart'; | 32 import '../../generated/test_support.dart'; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 524 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); |
525 } | 525 } |
526 | 526 |
527 void test_getNextResultPriority_nothingToDo() { | 527 void test_getNextResultPriority_nothingToDo() { |
528 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 528 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); |
529 } | 529 } |
530 | 530 |
531 void test_onAnalysisOptionsChanged() { | 531 void test_onAnalysisOptionsChanged() { |
532 when(context.exists(anyObject)).thenReturn(true); | 532 when(context.exists(anyObject)).thenReturn(true); |
533 // set cache values | 533 // set cache values |
534 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); | 534 entry1.setValue(PARSED_UNIT, AstTestFactory.compilationUnit(), []); |
535 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 535 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
536 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 536 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
537 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 537 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
538 entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 538 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
539 // configure LibrarySpecificUnit | 539 // configure LibrarySpecificUnit |
540 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 540 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
541 CacheEntry unitEntry = new CacheEntry(unitTarget); | 541 CacheEntry unitEntry = new CacheEntry(unitTarget); |
542 cache.put(unitEntry); | 542 cache.put(unitEntry); |
543 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); | 543 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); |
544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); | 544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); |
(...skipping 23 matching lines...) Expand all Loading... |
568 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 568 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); |
569 expect_librarySourceQueue([source1]); | 569 expect_librarySourceQueue([source1]); |
570 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled | 570 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled |
571 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 571 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); |
572 expect_librarySourceQueue([source1]); | 572 expect_librarySourceQueue([source1]); |
573 } | 573 } |
574 | 574 |
575 void test_onSourceFactoryChanged() { | 575 void test_onSourceFactoryChanged() { |
576 when(context.exists(anyObject)).thenReturn(true); | 576 when(context.exists(anyObject)).thenReturn(true); |
577 // set cache values | 577 // set cache values |
578 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); | 578 entry1.setValue(PARSED_UNIT, AstTestFactory.compilationUnit(), []); |
579 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 579 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
580 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 580 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
581 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 581 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
582 entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 582 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
583 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []); | 583 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []); |
584 entry1.setValue(UNITS, <Source>[], []); | 584 entry1.setValue(UNITS, <Source>[], []); |
585 // configure LibrarySpecificUnit | 585 // configure LibrarySpecificUnit |
586 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 586 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
587 CacheEntry unitEntry = new CacheEntry(unitTarget); | 587 CacheEntry unitEntry = new CacheEntry(unitTarget); |
588 cache.put(unitEntry); | 588 cache.put(unitEntry); |
(...skipping 23 matching lines...) Expand all Loading... |
612 when(context.getErrors(source1)) | 612 when(context.getErrors(source1)) |
613 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); | 613 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); |
614 entry1.setValue(LINE_INFO, lineInfo, []); | 614 entry1.setValue(LINE_INFO, lineInfo, []); |
615 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 615 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
616 AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); | 616 AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); |
617 context | 617 context |
618 .getCacheEntry(unitTarget) | 618 .getCacheEntry(unitTarget) |
619 .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); | 619 .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); |
620 // RESOLVED_UNIT is ready, set errors | 620 // RESOLVED_UNIT is ready, set errors |
621 manager.resultsComputed( | 621 manager.resultsComputed( |
622 unitTarget, {RESOLVED_UNIT: AstFactory.compilationUnit()}); | 622 unitTarget, {RESOLVED_UNIT: AstTestFactory.compilationUnit()}); |
623 // all of the errors are included | 623 // all of the errors are included |
624 ChangeNoticeImpl notice = context.getNotice(source1); | 624 ChangeNoticeImpl notice = context.getNotice(source1); |
625 expect(notice.errors, unorderedEquals([error1, error2])); | 625 expect(notice.errors, unorderedEquals([error1, error2])); |
626 expect(notice.lineInfo, lineInfo); | 626 expect(notice.lineInfo, lineInfo); |
627 } | 627 } |
628 | 628 |
629 void test_resultsComputed_errors_forSource() { | 629 void test_resultsComputed_errors_forSource() { |
630 LineInfo lineInfo = new LineInfo([0]); | 630 LineInfo lineInfo = new LineInfo([0]); |
631 AnalysisError error1 = | 631 AnalysisError error1 = |
632 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 632 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
633 AnalysisError error2 = | 633 AnalysisError error2 = |
634 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 634 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
635 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 635 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
636 when(context.getErrors(source1)) | 636 when(context.getErrors(source1)) |
637 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); | 637 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); |
638 entry1.setValue(LINE_INFO, lineInfo, []); | 638 entry1.setValue(LINE_INFO, lineInfo, []); |
639 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 639 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
640 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); | 640 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); |
641 // PARSED_UNIT is ready, set errors | 641 // PARSED_UNIT is ready, set errors |
642 manager | 642 manager.resultsComputed( |
643 .resultsComputed(source1, {PARSED_UNIT: AstFactory.compilationUnit()}); | 643 source1, {PARSED_UNIT: AstTestFactory.compilationUnit()}); |
644 // all of the errors are included | 644 // all of the errors are included |
645 ChangeNoticeImpl notice = context.getNotice(source1); | 645 ChangeNoticeImpl notice = context.getNotice(source1); |
646 expect(notice.errors, unorderedEquals([error1, error2])); | 646 expect(notice.errors, unorderedEquals([error1, error2])); |
647 expect(notice.lineInfo, lineInfo); | 647 expect(notice.lineInfo, lineInfo); |
648 } | 648 } |
649 | 649 |
650 void test_resultsComputed_includedParts_updatePartLibraries() { | 650 void test_resultsComputed_includedParts_updatePartLibraries() { |
651 Source part1 = new TestSource('part1.dart'); | 651 Source part1 = new TestSource('part1.dart'); |
652 Source part2 = new TestSource('part2.dart'); | 652 Source part2 = new TestSource('part2.dart'); |
653 Source part3 = new TestSource('part3.dart'); | 653 Source part3 = new TestSource('part3.dart'); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 expect_librarySourceQueue([]); | 717 expect_librarySourceQueue([]); |
718 expect_unknownSourceQueue([source1, source2]); | 718 expect_unknownSourceQueue([source1, source2]); |
719 } | 719 } |
720 | 720 |
721 void test_resultsComputed_parsedUnit() { | 721 void test_resultsComputed_parsedUnit() { |
722 LineInfo lineInfo = new LineInfo([0]); | 722 LineInfo lineInfo = new LineInfo([0]); |
723 when(context.getLibrariesContaining(source1)).thenReturn([]); | 723 when(context.getLibrariesContaining(source1)).thenReturn([]); |
724 when(context.getErrors(source1)) | 724 when(context.getErrors(source1)) |
725 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); | 725 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); |
726 entry1.setValue(LINE_INFO, lineInfo, []); | 726 entry1.setValue(LINE_INFO, lineInfo, []); |
727 CompilationUnit unit = AstFactory.compilationUnit(); | 727 CompilationUnit unit = AstTestFactory.compilationUnit(); |
728 manager.resultsComputed(source1, {PARSED_UNIT: unit}); | 728 manager.resultsComputed(source1, {PARSED_UNIT: unit}); |
729 ChangeNoticeImpl notice = context.getNotice(source1); | 729 ChangeNoticeImpl notice = context.getNotice(source1); |
730 expect(notice.parsedDartUnit, unit); | 730 expect(notice.parsedDartUnit, unit); |
731 expect(notice.resolvedDartUnit, isNull); | 731 expect(notice.resolvedDartUnit, isNull); |
732 expect(notice.lineInfo, lineInfo); | 732 expect(notice.lineInfo, lineInfo); |
733 } | 733 } |
734 | 734 |
735 void test_resultsComputed_resolvedUnit() { | 735 void test_resultsComputed_resolvedUnit() { |
736 LineInfo lineInfo = new LineInfo([0]); | 736 LineInfo lineInfo = new LineInfo([0]); |
737 when(context.getLibrariesContaining(source2)).thenReturn([]); | 737 when(context.getLibrariesContaining(source2)).thenReturn([]); |
738 when(context.getErrors(source2)) | 738 when(context.getErrors(source2)) |
739 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); | 739 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); |
740 entry2.setValue(LINE_INFO, lineInfo, []); | 740 entry2.setValue(LINE_INFO, lineInfo, []); |
741 CompilationUnit unit = AstFactory.compilationUnit(); | 741 CompilationUnit unit = AstTestFactory.compilationUnit(); |
742 manager.resultsComputed( | 742 manager.resultsComputed( |
743 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); | 743 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); |
744 ChangeNoticeImpl notice = context.getNotice(source2); | 744 ChangeNoticeImpl notice = context.getNotice(source2); |
745 expect(notice.parsedDartUnit, isNull); | 745 expect(notice.parsedDartUnit, isNull); |
746 expect(notice.resolvedDartUnit, unit); | 746 expect(notice.resolvedDartUnit, unit); |
747 expect(notice.lineInfo, lineInfo); | 747 expect(notice.lineInfo, lineInfo); |
748 } | 748 } |
749 | 749 |
750 void test_resultsComputed_sourceKind_isLibrary() { | 750 void test_resultsComputed_sourceKind_isLibrary() { |
751 manager.unknownSourceQueue.addAll([source1, source2, source3]); | 751 manager.unknownSourceQueue.addAll([source1, source2, source3]); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | 863 class _SourceFactoryMock extends TypedMock implements SourceFactory {} |
864 | 864 |
865 class _SourceMock extends TypedMock implements Source { | 865 class _SourceMock extends TypedMock implements Source { |
866 final String shortName; | 866 final String shortName; |
867 _SourceMock(this.shortName); | 867 _SourceMock(this.shortName); |
868 @override | 868 @override |
869 String get fullName => '/' + shortName; | 869 String get fullName => '/' + shortName; |
870 @override | 870 @override |
871 String toString() => fullName; | 871 String toString() => fullName; |
872 } | 872 } |
OLD | NEW |