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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months 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
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 analyzer.test.src.task.dart_work_manager_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/error/error.dart' show AnalysisError;
9 import 'package:analyzer/exception/exception.dart';
7 import 'package:analyzer/src/context/cache.dart'; 10 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 11 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode;
9 import 'package:analyzer/src/generated/engine.dart' 12 import 'package:analyzer/src/generated/engine.dart'
10 show 13 show
11 AnalysisErrorInfo,
12 AnalysisErrorInfoImpl, 14 AnalysisErrorInfoImpl,
15 AnalysisOptions,
16 AnalysisOptionsImpl,
13 CacheState, 17 CacheState,
14 ChangeNoticeImpl, 18 ChangeNoticeImpl,
15 InternalAnalysisContext; 19 InternalAnalysisContext;
16 import 'package:analyzer/src/generated/error.dart' show AnalysisError;
17 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
18 import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode;
19 import 'package:analyzer/src/generated/sdk.dart'; 20 import 'package:analyzer/src/generated/sdk.dart';
20 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 22 import 'package:analyzer/src/generated/testing/ast_factory.dart';
22 import 'package:analyzer/src/task/dart.dart'; 23 import 'package:analyzer/src/task/dart.dart';
23 import 'package:analyzer/src/task/dart_work_manager.dart'; 24 import 'package:analyzer/src/task/dart_work_manager.dart';
24 import 'package:analyzer/task/dart.dart'; 25 import 'package:analyzer/task/dart.dart';
25 import 'package:analyzer/task/general.dart'; 26 import 'package:analyzer/task/general.dart';
26 import 'package:analyzer/task/model.dart'; 27 import 'package:analyzer/task/model.dart';
28 import 'package:test_reflective_loader/test_reflective_loader.dart';
27 import 'package:typed_mock/typed_mock.dart'; 29 import 'package:typed_mock/typed_mock.dart';
28 import 'package:unittest/unittest.dart'; 30 import 'package:unittest/unittest.dart';
29 31
30 import '../../generated/test_support.dart'; 32 import '../../generated/test_support.dart';
31 import '../../reflective_tests.dart';
32 import '../../utils.dart'; 33 import '../../utils.dart';
33 34
34 main() { 35 main() {
35 initializeTestEnvironment(); 36 initializeTestEnvironment();
36 runReflectiveTests(DartWorkManagerTest); 37 defineReflectiveTests(DartWorkManagerTest);
37 } 38 }
38 39
39 @reflectiveTest 40 @reflectiveTest
40 class DartWorkManagerTest { 41 class DartWorkManagerTest {
41 InternalAnalysisContext context = new _InternalAnalysisContextMock(); 42 InternalAnalysisContext context = new _InternalAnalysisContextMock();
42 AnalysisCache cache; 43 AnalysisCache cache;
43 DartWorkManager manager; 44 DartWorkManager manager;
44 45
45 CaughtException caughtException = new CaughtException(null, null); 46 CaughtException caughtException = new CaughtException(null, null);
46 47
(...skipping 10 matching lines...) Expand all
57 expect(manager.librarySourceQueue, unorderedEquals(sources)); 58 expect(manager.librarySourceQueue, unorderedEquals(sources));
58 } 59 }
59 60
60 void expect_unknownSourceQueue(List<Source> sources) { 61 void expect_unknownSourceQueue(List<Source> sources) {
61 expect(manager.unknownSourceQueue, unorderedEquals(sources)); 62 expect(manager.unknownSourceQueue, unorderedEquals(sources));
62 } 63 }
63 64
64 void setUp() { 65 void setUp() {
65 cache = context.analysisCache; 66 cache = context.analysisCache;
66 manager = new DartWorkManager(context); 67 manager = new DartWorkManager(context);
67 entry1 = context.getCacheEntry(source1); 68 entry1 = _getOrCreateEntry(source1);
68 entry2 = context.getCacheEntry(source2); 69 entry2 = _getOrCreateEntry(source2);
69 entry3 = context.getCacheEntry(source3); 70 entry3 = _getOrCreateEntry(source3);
70 entry4 = context.getCacheEntry(source4); 71 entry4 = _getOrCreateEntry(source4);
71 } 72 }
72 73
73 void test_applyChange_add() { 74 void test_applyChange_add() {
74 // add source1 75 // add source1
75 manager.applyChange([source1], [], []); 76 manager.applyChange([source1], [], []);
76 expect_unknownSourceQueue([source1]); 77 expect_unknownSourceQueue([source1]);
77 expect_librarySourceQueue([]); 78 expect_librarySourceQueue([]);
78 // add source2 79 // add source2
79 manager.applyChange([source2], [], []); 80 manager.applyChange([source2], [], []);
80 expect_librarySourceQueue([]); 81 expect_librarySourceQueue([]);
(...skipping 19 matching lines...) Expand all
100 101
101 void test_applyChange_change() { 102 void test_applyChange_change() {
102 manager.librarySourceQueue.addAll([source1, source3]); 103 manager.librarySourceQueue.addAll([source1, source3]);
103 manager.unknownSourceQueue.addAll([source4]); 104 manager.unknownSourceQueue.addAll([source4]);
104 // change source1 105 // change source1
105 manager.applyChange([], [source1], []); 106 manager.applyChange([], [source1], []);
106 expect_librarySourceQueue([source3]); 107 expect_librarySourceQueue([source3]);
107 expect_unknownSourceQueue([source4, source1]); 108 expect_unknownSourceQueue([source4, source1]);
108 } 109 }
109 110
111 /**
112 * When we perform limited invalidation, we keep [SOURCE_KIND] valid. So, we
113 * don't need to put such sources into [DartWorkManager.unknownSourceQueue],
114 * and remove from [DartWorkManager.librarySourceQueue].
115 */
116 void test_applyChange_change_hasSourceKind() {
117 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
118 manager.librarySourceQueue.addAll([source1, source2]);
119 manager.unknownSourceQueue.addAll([source3]);
120 // change source1
121 manager.applyChange([], [source1, source2], []);
122 expect_librarySourceQueue([source1]);
123 expect_unknownSourceQueue([source2, source3]);
124 }
125
110 void test_applyChange_remove() { 126 void test_applyChange_remove() {
111 manager.librarySourceQueue.addAll([source1, source3]); 127 manager.librarySourceQueue.addAll([source1, source3]);
112 manager.unknownSourceQueue.addAll([source4]); 128 manager.unknownSourceQueue.addAll([source4]);
113 // remove source1 129 // remove source1
114 manager.applyChange([], [], [source1]); 130 manager.applyChange([], [], [source1]);
115 expect_librarySourceQueue([source3]); 131 expect_librarySourceQueue([source3]);
116 expect_unknownSourceQueue([source4]); 132 expect_unknownSourceQueue([source4]);
117 // remove source3 133 // remove source3
118 manager.applyChange([], [], [source3]); 134 manager.applyChange([], [], [source3]);
119 expect_librarySourceQueue([]); 135 expect_librarySourceQueue([]);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // remove part1 219 // remove part1
204 manager.applyChange([], [], [part1]); 220 manager.applyChange([], [], [part1]);
205 expect(manager.partLibrariesMap[part1], isNull); 221 expect(manager.partLibrariesMap[part1], isNull);
206 expect(manager.partLibrariesMap[part2], unorderedEquals([library2])); 222 expect(manager.partLibrariesMap[part2], unorderedEquals([library2]));
207 expect(manager.partLibrariesMap[part3], unorderedEquals([library1])); 223 expect(manager.partLibrariesMap[part3], unorderedEquals([library1]));
208 expect(manager.libraryPartsMap[library1], [part1, part3]); 224 expect(manager.libraryPartsMap[library1], [part1, part3]);
209 expect(manager.libraryPartsMap[library2], [part1, part2]); 225 expect(manager.libraryPartsMap[library2], [part1, part2]);
210 } 226 }
211 227
212 void test_applyPriorityTargets_isLibrary_computeErrors() { 228 void test_applyPriorityTargets_isLibrary_computeErrors() {
213 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); 229 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true);
214 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true); 230 when(context.shouldErrorsBeAnalyzed(source3)).thenReturn(true);
215 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 231 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
216 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 232 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
217 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 233 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
218 manager.priorityResultQueue 234 manager.priorityResultQueue
219 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); 235 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY));
220 manager.priorityResultQueue 236 manager.priorityResultQueue
221 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); 237 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY));
222 // -source1 +source3 238 // -source1 +source3
223 manager.applyPriorityTargets([source2, source3]); 239 manager.applyPriorityTargets([source2, source3]);
224 expect( 240 expect(
225 manager.priorityResultQueue, 241 manager.priorityResultQueue,
226 unorderedEquals([ 242 unorderedEquals([
227 new TargetedResult(source2, LIBRARY_ERRORS_READY), 243 new TargetedResult(source2, LIBRARY_ERRORS_READY),
228 new TargetedResult(source3, LIBRARY_ERRORS_READY) 244 new TargetedResult(source3, LIBRARY_ERRORS_READY)
229 ])); 245 ]));
230 // get next request 246 // get next request
231 TargetedResult request = manager.getNextResult(); 247 TargetedResult request = manager.getNextResult();
232 expect(request.target, source2); 248 expect(request.target, source2);
233 expect(request.result, LIBRARY_ERRORS_READY); 249 expect(request.result, LIBRARY_ERRORS_READY);
234 } 250 }
235 251
236 void test_applyPriorityTargets_isLibrary_computeUnit() { 252 void test_applyPriorityTargets_isLibrary_computeUnit() {
237 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); 253 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(false);
238 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(false); 254 when(context.shouldErrorsBeAnalyzed(source3)).thenReturn(false);
239 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 255 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
240 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 256 entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
241 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 257 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
242 manager.priorityResultQueue 258 manager.priorityResultQueue
243 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY)); 259 .add(new TargetedResult(source1, LIBRARY_ERRORS_READY));
244 manager.priorityResultQueue 260 manager.priorityResultQueue
245 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY)); 261 .add(new TargetedResult(source2, LIBRARY_ERRORS_READY));
246 // -source1 +source3 262 // -source1 +source3
247 manager.applyPriorityTargets([source2, source3]); 263 manager.applyPriorityTargets([source2, source3]);
248 expect( 264 expect(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); 324 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT);
309 AnalysisError error2 = 325 AnalysisError error2 =
310 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); 326 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT);
311 when(context.getLibrariesContaining(source1)).thenReturn([source2]); 327 when(context.getLibrariesContaining(source1)).thenReturn([source2]);
312 entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []); 328 entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []);
313 List<AnalysisError> errors = manager.getErrors(source1); 329 List<AnalysisError> errors = manager.getErrors(source1);
314 expect(errors, unorderedEquals([error1, error2])); 330 expect(errors, unorderedEquals([error1, error2]));
315 } 331 }
316 332
317 void test_getLibrariesContainingPart() { 333 void test_getLibrariesContainingPart() {
334 when(context.aboutToComputeResult(anyObject, anyObject)).thenReturn(false);
318 Source part1 = new TestSource('part1.dart'); 335 Source part1 = new TestSource('part1.dart');
319 Source part2 = new TestSource('part2.dart'); 336 Source part2 = new TestSource('part2.dart');
320 Source part3 = new TestSource('part3.dart'); 337 Source part3 = new TestSource('part3.dart');
321 Source library1 = new TestSource('library1.dart'); 338 Source library1 = new TestSource('library1.dart');
322 Source library2 = new TestSource('library2.dart'); 339 Source library2 = new TestSource('library2.dart');
323 manager.partLibrariesMap[part1] = [library1, library2]; 340 manager.partLibrariesMap[part1] = [library1, library2];
324 manager.partLibrariesMap[part2] = [library2]; 341 manager.partLibrariesMap[part2] = [library2];
325 manager.libraryPartsMap[library1] = [part1]; 342 manager.libraryPartsMap[library1] = [part1];
326 manager.libraryPartsMap[library2] = [part1, part2]; 343 manager.libraryPartsMap[library2] = [part1, part2];
327 // getLibrariesContainingPart 344 // getLibrariesContainingPart
328 expect(manager.getLibrariesContainingPart(part1), 345 expect(manager.getLibrariesContainingPart(part1),
329 unorderedEquals([library1, library2])); 346 unorderedEquals([library1, library2]));
330 expect( 347 expect(
331 manager.getLibrariesContainingPart(part2), unorderedEquals([library2])); 348 manager.getLibrariesContainingPart(part2), unorderedEquals([library2]));
332 expect(manager.getLibrariesContainingPart(part3), isEmpty); 349 expect(manager.getLibrariesContainingPart(part3), isEmpty);
333 } 350 }
334 351
352 void test_getLibrariesContainingPart_askResultProvider() {
353 Source part1 = new TestSource('part1.dart');
354 Source part2 = new TestSource('part2.dart');
355 Source part3 = new TestSource('part3.dart');
356 Source library1 = new TestSource('library1.dart');
357 Source library2 = new TestSource('library2.dart');
358 // configure AnalysisContext mock
359 when(context.aboutToComputeResult(anyObject, CONTAINING_LIBRARIES))
360 .thenInvoke((CacheEntry entry, ResultDescriptor result) {
361 if (entry.target == part1) {
362 entry.setValue(result as ResultDescriptor<List<Source>>,
363 <Source>[library1, library2], []);
364 return true;
365 }
366 if (entry.target == part2) {
367 entry.setValue(
368 result as ResultDescriptor<List<Source>>, <Source>[library2], []);
369 return true;
370 }
371 return false;
372 });
373 // getLibrariesContainingPart
374 expect(manager.getLibrariesContainingPart(part1),
375 unorderedEquals([library1, library2]));
376 expect(
377 manager.getLibrariesContainingPart(part2), unorderedEquals([library2]));
378 expect(manager.getLibrariesContainingPart(part3), isEmpty);
379 }
380
335 void test_getLibrariesContainingPart_inSDK() { 381 void test_getLibrariesContainingPart_inSDK() {
336 Source part = new _SourceMock('part.dart'); 382 Source part = new _SourceMock('part.dart');
337 when(part.isInSystemLibrary).thenReturn(true); 383 when(part.isInSystemLibrary).thenReturn(true);
338 // SDK work manager 384 // SDK work manager
339 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock(); 385 DartWorkManager sdkDartWorkManagerMock = new _DartWorkManagerMock();
340 when(sdkDartWorkManagerMock.getLibrariesContainingPart(part)) 386 when(sdkDartWorkManagerMock.getLibrariesContainingPart(part))
341 .thenReturn([source2, source3]); 387 .thenReturn([source2, source3]);
342 // SDK context mock 388 // SDK context mock
343 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock(); 389 InternalAnalysisContext sdkContextMock = new _InternalAnalysisContextMock();
344 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]); 390 when(sdkContextMock.workManagers).thenReturn([sdkDartWorkManagerMock]);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); 548 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID);
503 // ...but URIs are still value 549 // ...but URIs are still value
504 expect(entry1.getState(PARSED_UNIT), CacheState.VALID); 550 expect(entry1.getState(PARSED_UNIT), CacheState.VALID);
505 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID); 551 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.VALID);
506 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID); 552 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.VALID);
507 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID); 553 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.VALID);
508 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID); 554 expect(entry1.getState(INCLUDED_PARTS), CacheState.VALID);
509 } 555 }
510 556
511 void test_onResultInvalidated_scheduleInvalidatedLibraries() { 557 void test_onResultInvalidated_scheduleInvalidatedLibraries() {
558 // make source3 implicit
559 entry3.explicitlyAdded = false;
512 // set SOURCE_KIND 560 // set SOURCE_KIND
513 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 561 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
514 entry2.setValue(SOURCE_KIND, SourceKind.PART, []); 562 entry2.setValue(SOURCE_KIND, SourceKind.PART, []);
515 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []); 563 entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
516 // set LIBRARY_ERRORS_READY for source1 and source3 564 // set LIBRARY_ERRORS_READY for source1 and source3
517 entry1.setValue(LIBRARY_ERRORS_READY, true, []); 565 entry1.setValue(LIBRARY_ERRORS_READY, true, []);
518 entry3.setValue(LIBRARY_ERRORS_READY, true, []); 566 entry3.setValue(LIBRARY_ERRORS_READY, true, []);
519 // invalidate LIBRARY_ERRORS_READY for source1, schedule it 567 // invalidate LIBRARY_ERRORS_READY for source1, schedule it
520 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); 568 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
521 expect_librarySourceQueue([source1]); 569 expect_librarySourceQueue([source1]);
522 // invalidate LIBRARY_ERRORS_READY for source3, schedule it 570 // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled
523 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID); 571 entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
524 expect_librarySourceQueue([source1, source3]); 572 expect_librarySourceQueue([source1]);
525 } 573 }
526 574
527 void test_onSourceFactoryChanged() { 575 void test_onSourceFactoryChanged() {
528 when(context.exists(anyObject)).thenReturn(true); 576 when(context.exists(anyObject)).thenReturn(true);
529 // set cache values 577 // set cache values
530 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []); 578 entry1.setValue(PARSED_UNIT, AstFactory.compilationUnit(), []);
531 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []); 579 entry1.setValue(IMPORTED_LIBRARIES, <Source>[], []);
532 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []); 580 entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []);
533 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []); 581 entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []);
534 entry1.setValue(INCLUDED_PARTS, <Source>[], []); 582 entry1.setValue(INCLUDED_PARTS, <Source>[], []);
583 entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []);
584 entry1.setValue(UNITS, <Source>[], []);
535 // configure LibrarySpecificUnit 585 // configure LibrarySpecificUnit
536 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3); 586 LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3);
537 CacheEntry unitEntry = new CacheEntry(unitTarget); 587 CacheEntry unitEntry = new CacheEntry(unitTarget);
538 cache.put(unitEntry); 588 cache.put(unitEntry);
539 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []); 589 unitEntry.setValue(BUILD_LIBRARY_ERRORS, <AnalysisError>[], []);
540 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID); 590 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.VALID);
541 // notify 591 // notify
542 manager.onSourceFactoryChanged(); 592 manager.onSourceFactoryChanged();
543 // resolution is invalidated 593 // resolution is invalidated
544 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); 594 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID);
545 // ...and URIs resolution too 595 // ...and URIs resolution too
546 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); 596 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID);
547 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); 597 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID);
548 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); 598 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID);
549 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); 599 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID);
550 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); 600 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID);
601 expect(entry1.getState(LIBRARY_SPECIFIC_UNITS), CacheState.INVALID);
602 expect(entry1.getState(UNITS), CacheState.INVALID);
551 } 603 }
552 604
553 void test_resultsComputed_errors_forLibrarySpecificUnit() { 605 void test_resultsComputed_errors_forLibrarySpecificUnit() {
554 LineInfo lineInfo = new LineInfo([0]); 606 LineInfo lineInfo = new LineInfo([0]);
555 AnalysisError error1 = 607 AnalysisError error1 =
556 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); 608 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT);
557 AnalysisError error2 = 609 AnalysisError error2 =
558 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); 610 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT);
559 when(context.getLibrariesContaining(source1)).thenReturn([source2]); 611 when(context.getLibrariesContaining(source1)).thenReturn([source2]);
560 when(context.getErrors(source1)) 612 when(context.getErrors(source1))
(...skipping 19 matching lines...) Expand all
580 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); 632 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT);
581 AnalysisError error2 = 633 AnalysisError error2 =
582 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); 634 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT);
583 when(context.getLibrariesContaining(source1)).thenReturn([source2]); 635 when(context.getLibrariesContaining(source1)).thenReturn([source2]);
584 when(context.getErrors(source1)) 636 when(context.getErrors(source1))
585 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); 637 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo));
586 entry1.setValue(LINE_INFO, lineInfo, []); 638 entry1.setValue(LINE_INFO, lineInfo, []);
587 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); 639 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []);
588 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); 640 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []);
589 // PARSED_UNIT is ready, set errors 641 // PARSED_UNIT is ready, set errors
590 manager.resultsComputed( 642 manager
591 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); 643 .resultsComputed(source1, {PARSED_UNIT: AstFactory.compilationUnit()});
592 // all of the errors are included 644 // all of the errors are included
593 ChangeNoticeImpl notice = context.getNotice(source1); 645 ChangeNoticeImpl notice = context.getNotice(source1);
594 expect(notice.errors, unorderedEquals([error1, error2])); 646 expect(notice.errors, unorderedEquals([error1, error2]));
595 expect(notice.lineInfo, lineInfo); 647 expect(notice.lineInfo, lineInfo);
596 } 648 }
597 649
598 void test_resultsComputed_includedParts_updatePartLibraries() { 650 void test_resultsComputed_includedParts_updatePartLibraries() {
599 Source part1 = new TestSource('part1.dart'); 651 Source part1 = new TestSource('part1.dart');
600 Source part2 = new TestSource('part2.dart'); 652 Source part2 = new TestSource('part2.dart');
601 Source part3 = new TestSource('part3.dart'); 653 Source part3 = new TestSource('part3.dart');
602 Source library1 = new TestSource('library1.dart'); 654 Source library1 = new TestSource('library1.dart');
603 Source library2 = new TestSource('library2.dart'); 655 Source library2 = new TestSource('library2.dart');
604 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []); 656 _getOrCreateEntry(part1).setValue(CONTAINING_LIBRARIES, [], []);
605 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID); 657 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID);
606 // configure AnalysisContext mock 658 // configure AnalysisContext mock
607 when(context.prioritySources).thenReturn(<Source>[]); 659 when(context.prioritySources).thenReturn(<Source>[]);
608 when(context.shouldErrorsBeAnalyzed(anyObject, anyObject)) 660 when(context.shouldErrorsBeAnalyzed(anyObject)).thenReturn(false);
609 .thenReturn(false);
610 // library1 parts 661 // library1 parts
611 manager.resultsComputed(library1, { 662 manager.resultsComputed(library1, <ResultDescriptor, dynamic>{
612 INCLUDED_PARTS: [part1, part2], 663 INCLUDED_PARTS: [part1, part2],
613 SOURCE_KIND: SourceKind.LIBRARY 664 SOURCE_KIND: SourceKind.LIBRARY
614 }); 665 });
615 expect(manager.partLibrariesMap[part1], [library1]); 666 expect(manager.partLibrariesMap[part1], [library1]);
616 expect(manager.partLibrariesMap[part2], [library1]); 667 expect(manager.partLibrariesMap[part2], [library1]);
617 expect(manager.partLibrariesMap[part3], isNull); 668 expect(manager.partLibrariesMap[part3], isNull);
618 expect(manager.libraryPartsMap[library1], [part1, part2]); 669 expect(manager.libraryPartsMap[library1], [part1, part2]);
619 expect(manager.libraryPartsMap[library2], isNull); 670 expect(manager.libraryPartsMap[library2], isNull);
620 // library2 parts 671 // library2 parts
621 manager.resultsComputed(library2, { 672 manager.resultsComputed(library2, <ResultDescriptor, dynamic>{
622 INCLUDED_PARTS: [part2, part3], 673 INCLUDED_PARTS: [part2, part3],
623 SOURCE_KIND: SourceKind.LIBRARY 674 SOURCE_KIND: SourceKind.LIBRARY
624 }); 675 });
625 expect(manager.partLibrariesMap[part1], [library1]); 676 expect(manager.partLibrariesMap[part1], [library1]);
626 expect(manager.partLibrariesMap[part2], [library1, library2]); 677 expect(manager.partLibrariesMap[part2], [library1, library2]);
627 expect(manager.partLibrariesMap[part3], [library2]); 678 expect(manager.partLibrariesMap[part3], [library2]);
628 expect(manager.libraryPartsMap[library1], [part1, part2]); 679 expect(manager.libraryPartsMap[library1], [part1, part2]);
629 expect(manager.libraryPartsMap[library2], [part2, part3]); 680 expect(manager.libraryPartsMap[library2], [part2, part3]);
630 // part1 CONTAINING_LIBRARIES 681 // part1 CONTAINING_LIBRARIES
631 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID); 682 expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.INVALID);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); 743 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit});
693 ChangeNoticeImpl notice = context.getNotice(source2); 744 ChangeNoticeImpl notice = context.getNotice(source2);
694 expect(notice.parsedDartUnit, isNull); 745 expect(notice.parsedDartUnit, isNull);
695 expect(notice.resolvedDartUnit, unit); 746 expect(notice.resolvedDartUnit, unit);
696 expect(notice.lineInfo, lineInfo); 747 expect(notice.lineInfo, lineInfo);
697 } 748 }
698 749
699 void test_resultsComputed_sourceKind_isLibrary() { 750 void test_resultsComputed_sourceKind_isLibrary() {
700 manager.unknownSourceQueue.addAll([source1, source2, source3]); 751 manager.unknownSourceQueue.addAll([source1, source2, source3]);
701 when(context.prioritySources).thenReturn(<Source>[]); 752 when(context.prioritySources).thenReturn(<Source>[]);
702 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); 753 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true);
703 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); 754 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
704 expect_librarySourceQueue([source2]); 755 expect_librarySourceQueue([source2]);
705 expect_unknownSourceQueue([source1, source3]); 756 expect_unknownSourceQueue([source1, source3]);
706 } 757 }
707 758
708 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() { 759 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() {
709 manager.unknownSourceQueue.addAll([source1, source2, source3]); 760 manager.unknownSourceQueue.addAll([source1, source2, source3]);
710 when(context.prioritySources).thenReturn(<Source>[source2]); 761 when(context.prioritySources).thenReturn(<Source>[source2]);
711 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); 762 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true);
712 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); 763 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
713 expect_unknownSourceQueue([source1, source3]); 764 expect_unknownSourceQueue([source1, source3]);
714 expect(manager.priorityResultQueue, 765 expect(manager.priorityResultQueue,
715 unorderedEquals([new TargetedResult(source2, LIBRARY_ERRORS_READY)])); 766 unorderedEquals([new TargetedResult(source2, LIBRARY_ERRORS_READY)]));
716 } 767 }
717 768
718 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() { 769 void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() {
719 manager.unknownSourceQueue.addAll([source1, source2, source3]); 770 manager.unknownSourceQueue.addAll([source1, source2, source3]);
720 when(context.prioritySources).thenReturn(<Source>[source2]); 771 when(context.prioritySources).thenReturn(<Source>[source2]);
721 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false); 772 when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(false);
722 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY}); 773 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
723 expect_unknownSourceQueue([source1, source3]); 774 expect_unknownSourceQueue([source1, source3]);
724 expect( 775 expect(
725 manager.priorityResultQueue, 776 manager.priorityResultQueue,
726 unorderedEquals([ 777 unorderedEquals([
727 new TargetedResult( 778 new TargetedResult(
728 new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT) 779 new LibrarySpecificUnit(source2, source2), RESOLVED_UNIT)
729 ])); 780 ]));
730 } 781 }
731 782
732 void test_resultsComputed_sourceKind_isPart() { 783 void test_resultsComputed_sourceKind_isPart() {
733 manager.unknownSourceQueue.addAll([source1, source2, source3]); 784 manager.unknownSourceQueue.addAll([source1, source2, source3]);
734 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART}); 785 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART});
735 expect_librarySourceQueue([]); 786 expect_librarySourceQueue([]);
736 expect_unknownSourceQueue([source1, source3]); 787 expect_unknownSourceQueue([source1, source3]);
737 } 788 }
738 789
739 void test_resultsComputed_updatePartsLibraries_partParsed() { 790 void test_resultsComputed_updatePartsLibraries_partParsed() {
740 Source part = new TestSource('part.dart'); 791 Source part = new TestSource('part.dart');
741 expect(manager.libraryPartsMap, isEmpty); 792 expect(manager.libraryPartsMap, isEmpty);
742 // part.dart parsed, no changes is the map of libraries 793 // part.dart parsed, no changes is the map of libraries
743 manager.resultsComputed( 794 manager.resultsComputed(part, <ResultDescriptor, dynamic>{
744 part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]}); 795 SOURCE_KIND: SourceKind.PART,
796 INCLUDED_PARTS: <Source>[]
797 });
745 expect(manager.libraryPartsMap, isEmpty); 798 expect(manager.libraryPartsMap, isEmpty);
746 } 799 }
747 800
748 CacheEntry _getOrCreateEntry(Source source) { 801 void test_unitIncrementallyResolved() {
802 manager.unitIncrementallyResolved(source1, source2);
803 expect_librarySourceQueue([source1]);
804 }
805
806 CacheEntry _getOrCreateEntry(Source source, [bool explicit = true]) {
749 CacheEntry entry = cache.get(source); 807 CacheEntry entry = cache.get(source);
750 if (entry == null) { 808 if (entry == null) {
751 entry = new CacheEntry(source); 809 entry = new CacheEntry(source);
810 entry.explicitlyAdded = explicit;
752 cache.put(entry); 811 cache.put(entry);
753 } 812 }
754 return entry; 813 return entry;
755 } 814 }
756 } 815 }
757 816
758 class _DartSdkMock extends TypedMock implements DartSdk { 817 class _DartSdkMock extends TypedMock implements DartSdk {}
759 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
760 }
761 818
762 class _DartWorkManagerMock extends TypedMock implements DartWorkManager { 819 class _DartWorkManagerMock extends TypedMock implements DartWorkManager {}
763 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
764 }
765 820
766 class _InternalAnalysisContextMock extends TypedMock 821 class _InternalAnalysisContextMock extends TypedMock
767 implements InternalAnalysisContext { 822 implements InternalAnalysisContext {
768 @override 823 @override
769 CachePartition privateAnalysisCachePartition; 824 CachePartition privateAnalysisCachePartition;
770 825
771 @override 826 @override
772 AnalysisCache analysisCache; 827 AnalysisCache analysisCache;
773 828
774 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{}; 829 Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{};
775 830
831 @override
832 final AnalysisOptions analysisOptions = new AnalysisOptionsImpl();
833
834 @override
835 final ReentrantSynchronousStream<InvalidatedResult> onResultInvalidated =
836 new ReentrantSynchronousStream<InvalidatedResult>();
837
776 _InternalAnalysisContextMock() { 838 _InternalAnalysisContextMock() {
777 privateAnalysisCachePartition = new UniversalCachePartition(this); 839 privateAnalysisCachePartition = new UniversalCachePartition(this);
778 analysisCache = new AnalysisCache([privateAnalysisCachePartition]); 840 analysisCache = new AnalysisCache([privateAnalysisCachePartition]);
841 analysisCache.onResultInvalidated.listen((InvalidatedResult event) {
842 onResultInvalidated.add(event);
843 });
779 } 844 }
780 845
781 @override 846 @override
782 CacheEntry getCacheEntry(AnalysisTarget target) { 847 CacheEntry getCacheEntry(AnalysisTarget target) {
783 CacheEntry entry = analysisCache.get(target); 848 CacheEntry entry = analysisCache.get(target);
784 if (entry == null) { 849 if (entry == null) {
785 entry = new CacheEntry(target); 850 entry = new CacheEntry(target);
786 analysisCache.put(entry); 851 analysisCache.put(entry);
787 } 852 }
788 return entry; 853 return entry;
789 } 854 }
790 855
791 @override 856 @override
792 ChangeNoticeImpl getNotice(Source source) { 857 ChangeNoticeImpl getNotice(Source source) {
793 return _pendingNotices.putIfAbsent( 858 return _pendingNotices.putIfAbsent(
794 source, () => new ChangeNoticeImpl(source)); 859 source, () => new ChangeNoticeImpl(source));
795 } 860 }
796
797 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
798 } 861 }
799 862
800 class _SourceFactoryMock extends TypedMock implements SourceFactory { 863 class _SourceFactoryMock extends TypedMock implements SourceFactory {}
801 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
802 }
803 864
804 class _SourceMock extends TypedMock implements Source { 865 class _SourceMock extends TypedMock implements Source {
805 final String shortName; 866 final String shortName;
806 _SourceMock(this.shortName); 867 _SourceMock(this.shortName);
807 @override 868 @override
808 String get fullName => '/' + shortName; 869 String get fullName => '/' + shortName;
809 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
810 @override 870 @override
811 String toString() => fullName; 871 String toString() => fullName;
812 } 872 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/src/task/dart_test.dart ('k') | packages/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698