Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: pkg/analyzer/test/src/task/dart_work_manager_test.dart

Issue 1441013003: Issue 24812. Fix for detached CompilationUnitElement(s) after package version switch. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/src/context/context_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 expect(manager.librarySourceQueue, unorderedEquals(sources)); 57 expect(manager.librarySourceQueue, unorderedEquals(sources));
58 } 58 }
59 59
60 void expect_unknownSourceQueue(List<Source> sources) { 60 void expect_unknownSourceQueue(List<Source> sources) {
61 expect(manager.unknownSourceQueue, unorderedEquals(sources)); 61 expect(manager.unknownSourceQueue, unorderedEquals(sources));
62 } 62 }
63 63
64 void setUp() { 64 void setUp() {
65 cache = context.analysisCache; 65 cache = context.analysisCache;
66 manager = new DartWorkManager(context); 66 manager = new DartWorkManager(context);
67 entry1 = context.getCacheEntry(source1); 67 entry1 = _getOrCreateEntry(source1);
68 entry2 = context.getCacheEntry(source2); 68 entry2 = _getOrCreateEntry(source2);
69 entry3 = context.getCacheEntry(source3); 69 entry3 = _getOrCreateEntry(source3);
70 entry4 = context.getCacheEntry(source4); 70 entry4 = _getOrCreateEntry(source4);
71 } 71 }
72 72
73 void test_applyChange_add() { 73 void test_applyChange_add() {
74 // add source1 74 // add source1
75 manager.applyChange([source1], [], []); 75 manager.applyChange([source1], [], []);
76 expect_unknownSourceQueue([source1]); 76 expect_unknownSourceQueue([source1]);
77 expect_librarySourceQueue([]); 77 expect_librarySourceQueue([]);
78 // add source2 78 // add source2
79 manager.applyChange([source2], [], []); 79 manager.applyChange([source2], [], []);
80 expect_librarySourceQueue([]); 80 expect_librarySourceQueue([]);
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); 502 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID);
503 // ...but URIs are still value 503 // ...but URIs are still value
504 expect(entry1.getState(PARSED_UNIT), CacheState.VALID); 504 expect(entry1.getState(PARSED_UNIT), CacheState.VALID);
505 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID); 505 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID);
506 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID); 506 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID);
507 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID); 507 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID);
508 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID); 508 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID);
509 } 509 }
510 510
511 void test_onResultInvalidated_scheduleInvalidatedLibraries() { 511 void test_onResultInvalidated_scheduleInvalidatedLibraries() {
512 // make source3 implicit
513 entry3.explicitlyAdded = false;
512 // set SOURCE_KIND 514 // set SOURCE_KIND
513 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 515 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
514 entry2.setValue(SOURCE_KIND, SourceKind.PART, []); 516 entry2.setValue(SOURCE_KIND, SourceKind.PART, []);
515 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 517 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
516 // set LIBRARY_ERRORS_READY for source1 and source3 518 // set LIBRARY_ERRORS_READY for source1 and source3
517 entry1.setValue(LIBRARY_ERRORS_READY, true, []); 519 entry1.setValue(LIBRARY_ERRORS_READY, true, []);
518 entry3.setValue(LIBRARY_ERRORS_READY, true, []); 520 entry3.setValue(LIBRARY_ERRORS_READY, true, []);
519 // invalidate LIBRARY_ERRORS_READY for source1, schedule it 521 // invalidate LIBRARY_ERRORS_READY for source1, schedule it
520 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); 522 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
521 expect_librarySourceQueue([source1]); 523 expect_librarySourceQueue([source1]);
522 // invalidate LIBRARY_ERRORS_READY for source3, schedule it 524 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled
523 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); 525 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
524 expect_librarySourceQueue([source1, source3]); 526 expect_librarySourceQueue([source1]);
525 } 527 }
526 528
527 void test_onSourceFactoryChanged() { 529 void test_onSourceFactoryChanged() {
528 when(context.exists(anyObject)).thenReturn(true); 530 when(context.exists(anyObject)).thenReturn(true);
529 // set cache values 531 // set cache values
530 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); 532 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []);
531 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); 533 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []);
532 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); 534 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []);
533 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); 535 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []);
534 entry1.setValue(INCLUDED_PARTS, <Source>[], []); 536 entry1.setValue(INCLUDED_PARTS, <Source>[], []);
537 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []);
538 entry1.setValue(UNITS, <Source>[], []);
535 // configure LibrarySpecificUnit 539 // configure LibrarySpecificUnit
536 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); 540 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3);
537 CacheEntry unitEntry = new CacheEntry(unitTarget); 541 CacheEntry unitEntry = new CacheEntry(unitTarget);
538 cache.put(unitEntry); 542 cache.put(unitEntry);
539 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); 543 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []);
540 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); 544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID);
541 // notify 545 // notify
542 manager.onSourceFactoryChanged(); 546 manager.onSourceFactoryChanged();
543 // resolution is invalidated 547 // resolution is invalidated
544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); 548 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID);
545 // ...and URIs resolution too 549 // ...and URIs resolution too
546 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); 550 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID);
547 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); 551 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID);
548 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); 552 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID);
549 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); 553 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID);
550 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); 554 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID);
555 expect(entry1.getState(LIBRARY_SPECIFIC_UNITS), CacheState.INVALID);
556 expect(entry1.getState(UNITS), CacheState.INVALID);
551 } 557 }
552 558
553 void test_resultsComputed_errors_forLibrarySpecificUnit() { 559 void test_resultsComputed_errors_forLibrarySpecificUnit() {
554 LineInfo lineInfo = new LineInfo([0]); 560 LineInfo lineInfo = new LineInfo([0]);
555 AnalysisError error1 = 561 AnalysisError error1 =
556 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); 562 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT);
557 AnalysisError error2 = 563 AnalysisError error2 =
558 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); 564 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT);
559 when(context.getLibrariesContaining(source1)).thenReturn([source2]); 565 when(context.getLibrariesContaining(source1)).thenReturn([source2]);
560 when(context.getErrors(source1)) 566 when(context.getErrors(source1))
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 744
739 void test_resultsComputed_updatePartsLibraries_partParsed() { 745 void test_resultsComputed_updatePartsLibraries_partParsed() {
740 Source part = new TestSource('part.dart'); 746 Source part = new TestSource('part.dart');
741 expect(manager.libraryPartsMap, isEmpty); 747 expect(manager.libraryPartsMap, isEmpty);
742 // part.dart parsed, no changes is the map of libraries 748 // part.dart parsed, no changes is the map of libraries
743 manager.resultsComputed( 749 manager.resultsComputed(
744 part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]}); 750 part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]});
745 expect(manager.libraryPartsMap, isEmpty); 751 expect(manager.libraryPartsMap, isEmpty);
746 } 752 }
747 753
748 CacheEntry _getOrCreateEntry(Source source) { 754 CacheEntry _getOrCreateEntry(Source source, [bool explicit = true]) {
749 CacheEntry entry = cache.get(source); 755 CacheEntry entry = cache.get(source);
750 if (entry == null) { 756 if (entry == null) {
751 entry = new CacheEntry(source); 757 entry = new CacheEntry(source);
758 entry.explicitlyAdded = explicit;
752 cache.put(entry); 759 cache.put(entry);
753 } 760 }
754 return entry; 761 return entry;
755 } 762 }
756 } 763 }
757 764
758 class _DartSdkMock extends TypedMock implements DartSdk { 765 class _DartSdkMock extends TypedMock implements DartSdk {
759 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 766 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
760 } 767 }
761 768
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 810
804 class _SourceMock extends TypedMock implements Source { 811 class _SourceMock extends TypedMock implements Source {
805 final String shortName; 812 final String shortName;
806 _SourceMock(this.shortName); 813 _SourceMock(this.shortName);
807 @override 814 @override
808 String get fullName => '/' + shortName; 815 String get fullName => '/' + shortName;
809 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 816 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
810 @override 817 @override
811 String toString() => fullName; 818 String toString() => fullName;
812 } 819 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/context_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698