| 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/src/context/cache.dart'; | 8 import 'package:analyzer/src/context/cache.dart'; |
| 9 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; | 9 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; |
| 10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); | 520 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void test_getNextResultPriority_nothingToDo() { | 523 void test_getNextResultPriority_nothingToDo() { |
| 524 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); | 524 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); |
| 525 } | 525 } |
| 526 | 526 |
| 527 void test_onAnalysisOptionsChanged() { | 527 void test_onAnalysisOptionsChanged() { |
| 528 when(context.exists(anyObject)).thenReturn(true); | 528 when(context.exists(anyObject)).thenReturn(true); |
| 529 // set cache values | 529 // set cache values |
| 530 entry1.setValue(PARSED_UNIT1, AstFactory.compilationUnit(), []); | 530 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); |
| 531 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 531 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
| 532 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 532 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
| 533 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 533 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
| 534 entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 534 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
| 535 // configure LibrarySpecificUnit | 535 // configure LibrarySpecificUnit |
| 536 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 536 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
| 537 CacheEntry unitEntry = new CacheEntry(unitTarget); | 537 CacheEntry unitEntry = new CacheEntry(unitTarget); |
| 538 cache.put(unitEntry); | 538 cache.put(unitEntry); |
| 539 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); | 539 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); |
| 540 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); | 540 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); |
| 541 // notify | 541 // notify |
| 542 manager.onAnalysisOptionsChanged(); | 542 manager.onAnalysisOptionsChanged(); |
| 543 // resolution is invalidated | 543 // resolution is invalidated |
| 544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); | 544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); |
| 545 // ...but URIs are still value | 545 // ...but URIs are still value |
| 546 expect(entry1.getState(PARSED_UNIT1), CacheState.VALID); | 546 expect(entry1.getState(PARSED_UNIT), CacheState.VALID); |
| 547 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID); | 547 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID); |
| 548 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID); | 548 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID); |
| 549 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID); | 549 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID); |
| 550 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID); | 550 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID); |
| 551 } | 551 } |
| 552 | 552 |
| 553 void test_onResultInvalidated_scheduleInvalidatedLibraries() { | 553 void test_onResultInvalidated_scheduleInvalidatedLibraries() { |
| 554 // make source3 implicit | 554 // make source3 implicit |
| 555 entry3.explicitlyAdded = false; | 555 entry3.explicitlyAdded = false; |
| 556 // set SOURCE_KIND | 556 // set SOURCE_KIND |
| 557 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 557 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 558 entry2.setValue(SOURCE_KIND, SourceKind.PART, []); | 558 entry2.setValue(SOURCE_KIND, SourceKind.PART, []); |
| 559 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); | 559 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); |
| 560 // set LIBRARY_ERRORS_READY for source1 and source3 | 560 // set LIBRARY_ERRORS_READY for source1 and source3 |
| 561 entry1.setValue(LIBRARY_ERRORS_READY, true, []); | 561 entry1.setValue(LIBRARY_ERRORS_READY, true, []); |
| 562 entry3.setValue(LIBRARY_ERRORS_READY, true, []); | 562 entry3.setValue(LIBRARY_ERRORS_READY, true, []); |
| 563 // invalidate LIBRARY_ERRORS_READY for source1, schedule it | 563 // invalidate LIBRARY_ERRORS_READY for source1, schedule it |
| 564 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 564 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); |
| 565 expect_librarySourceQueue([source1]); | 565 expect_librarySourceQueue([source1]); |
| 566 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled | 566 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled |
| 567 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); | 567 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); |
| 568 expect_librarySourceQueue([source1]); | 568 expect_librarySourceQueue([source1]); |
| 569 } | 569 } |
| 570 | 570 |
| 571 void test_onSourceFactoryChanged() { | 571 void test_onSourceFactoryChanged() { |
| 572 when(context.exists(anyObject)).thenReturn(true); | 572 when(context.exists(anyObject)).thenReturn(true); |
| 573 // set cache values | 573 // set cache values |
| 574 CompilationUnit unit = AstFactory.compilationUnit(); | 574 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); |
| 575 entry1.setValue(PARSED_UNIT1, unit, []); | |
| 576 entry1.setValue(PARSED_UNIT, unit, []); | |
| 577 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); | 575 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); |
| 578 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); | 576 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); |
| 579 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); | 577 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); |
| 580 entry1.setValue(INCLUDED_PARTS, <Source>[], []); | 578 entry1.setValue(INCLUDED_PARTS, <Source>[], []); |
| 581 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []); | 579 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []); |
| 582 entry1.setValue(UNITS, <Source>[], []); | 580 entry1.setValue(UNITS, <Source>[], []); |
| 583 // configure LibrarySpecificUnit | 581 // configure LibrarySpecificUnit |
| 584 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); | 582 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); |
| 585 CacheEntry unitEntry = new CacheEntry(unitTarget); | 583 CacheEntry unitEntry = new CacheEntry(unitTarget); |
| 586 cache.put(unitEntry); | 584 cache.put(unitEntry); |
| 587 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); | 585 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); |
| 588 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); | 586 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); |
| 589 // notify | 587 // notify |
| 590 manager.onSourceFactoryChanged(); | 588 manager.onSourceFactoryChanged(); |
| 591 // resolution is invalidated | 589 // resolution is invalidated |
| 592 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); | 590 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); |
| 593 // ...and URIs resolution too | 591 // ...and URIs resolution too |
| 594 expect(entry1.getState(PARSED_UNIT1), CacheState.INVALID); | |
| 595 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); | 592 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); |
| 596 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); | 593 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); |
| 597 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); | 594 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); |
| 598 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); | 595 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); |
| 599 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); | 596 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); |
| 600 expect(entry1.getState(LIBRARY_SPECIFIC_UNITS), CacheState.INVALID); | 597 expect(entry1.getState(LIBRARY_SPECIFIC_UNITS), CacheState.INVALID); |
| 601 expect(entry1.getState(UNITS), CacheState.INVALID); | 598 expect(entry1.getState(UNITS), CacheState.INVALID); |
| 602 } | 599 } |
| 603 | 600 |
| 604 void test_resultsComputed_errors_forLibrarySpecificUnit() { | 601 void test_resultsComputed_errors_forLibrarySpecificUnit() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 632 AnalysisError error2 = | 629 AnalysisError error2 = |
| 633 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 630 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
| 634 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 631 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
| 635 when(context.getErrors(source1)) | 632 when(context.getErrors(source1)) |
| 636 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); | 633 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); |
| 637 entry1.setValue(LINE_INFO, lineInfo, []); | 634 entry1.setValue(LINE_INFO, lineInfo, []); |
| 638 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 635 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
| 639 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); | 636 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); |
| 640 // PARSED_UNIT is ready, set errors | 637 // PARSED_UNIT is ready, set errors |
| 641 manager | 638 manager |
| 642 .resultsComputed(source1, {PARSED_UNIT1: AstFactory.compilationUnit()}); | 639 .resultsComputed(source1, {PARSED_UNIT: AstFactory.compilationUnit()}); |
| 643 // all of the errors are included | 640 // all of the errors are included |
| 644 ChangeNoticeImpl notice = context.getNotice(source1); | 641 ChangeNoticeImpl notice = context.getNotice(source1); |
| 645 expect(notice.errors, unorderedEquals([error1, error2])); | 642 expect(notice.errors, unorderedEquals([error1, error2])); |
| 646 expect(notice.lineInfo, lineInfo); | 643 expect(notice.lineInfo, lineInfo); |
| 647 } | 644 } |
| 648 | 645 |
| 649 void test_resultsComputed_includedParts_updatePartLibraries() { | 646 void test_resultsComputed_includedParts_updatePartLibraries() { |
| 650 Source part1 = new TestSource('part1.dart'); | 647 Source part1 = new TestSource('part1.dart'); |
| 651 Source part2 = new TestSource('part2.dart'); | 648 Source part2 = new TestSource('part2.dart'); |
| 652 Source part3 = new TestSource('part3.dart'); | 649 Source part3 = new TestSource('part3.dart'); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 expect_unknownSourceQueue([source1, source2]); | 714 expect_unknownSourceQueue([source1, source2]); |
| 718 } | 715 } |
| 719 | 716 |
| 720 void test_resultsComputed_parsedUnit() { | 717 void test_resultsComputed_parsedUnit() { |
| 721 LineInfo lineInfo = new LineInfo([0]); | 718 LineInfo lineInfo = new LineInfo([0]); |
| 722 when(context.getLibrariesContaining(source1)).thenReturn([]); | 719 when(context.getLibrariesContaining(source1)).thenReturn([]); |
| 723 when(context.getErrors(source1)) | 720 when(context.getErrors(source1)) |
| 724 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); | 721 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); |
| 725 entry1.setValue(LINE_INFO, lineInfo, []); | 722 entry1.setValue(LINE_INFO, lineInfo, []); |
| 726 CompilationUnit unit = AstFactory.compilationUnit(); | 723 CompilationUnit unit = AstFactory.compilationUnit(); |
| 727 manager.resultsComputed(source1, {PARSED_UNIT1: unit}); | 724 manager.resultsComputed(source1, {PARSED_UNIT: unit}); |
| 728 ChangeNoticeImpl notice = context.getNotice(source1); | 725 ChangeNoticeImpl notice = context.getNotice(source1); |
| 729 expect(notice.parsedDartUnit, unit); | 726 expect(notice.parsedDartUnit, unit); |
| 730 expect(notice.resolvedDartUnit, isNull); | 727 expect(notice.resolvedDartUnit, isNull); |
| 731 expect(notice.lineInfo, lineInfo); | 728 expect(notice.lineInfo, lineInfo); |
| 732 } | 729 } |
| 733 | 730 |
| 734 void test_resultsComputed_resolvedUnit() { | 731 void test_resultsComputed_resolvedUnit() { |
| 735 LineInfo lineInfo = new LineInfo([0]); | 732 LineInfo lineInfo = new LineInfo([0]); |
| 736 when(context.getLibrariesContaining(source2)).thenReturn([]); | 733 when(context.getLibrariesContaining(source2)).thenReturn([]); |
| 737 when(context.getErrors(source2)) | 734 when(context.getErrors(source2)) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 class _SourceFactoryMock extends TypedMock implements SourceFactory {} | 854 class _SourceFactoryMock extends TypedMock implements SourceFactory {} |
| 858 | 855 |
| 859 class _SourceMock extends TypedMock implements Source { | 856 class _SourceMock extends TypedMock implements Source { |
| 860 final String shortName; | 857 final String shortName; |
| 861 _SourceMock(this.shortName); | 858 _SourceMock(this.shortName); |
| 862 @override | 859 @override |
| 863 String get fullName => '/' + shortName; | 860 String get fullName => '/' + shortName; |
| 864 @override | 861 @override |
| 865 String toString() => fullName; | 862 String toString() => fullName; |
| 866 } | 863 } |
| OLD | NEW |