| 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 CacheState, | 13 CacheState, |
| 13 ChangeNoticeImpl, | 14 ChangeNoticeImpl, |
| 14 InternalAnalysisContext; | 15 InternalAnalysisContext; |
| 15 import 'package:analyzer/src/generated/error.dart' show AnalysisError; | 16 import 'package:analyzer/src/generated/error.dart' show AnalysisError; |
| 16 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 17 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
| 17 import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode; | 18 import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 20 import 'package:analyzer/src/task/dart.dart'; | 21 import 'package:analyzer/src/task/dart.dart'; |
| 21 import 'package:analyzer/src/task/dart_work_manager.dart'; | 22 import 'package:analyzer/src/task/dart_work_manager.dart'; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 expect(request.target, source2); | 288 expect(request.target, source2); |
| 288 expect(request.result, SOURCE_KIND); | 289 expect(request.result, SOURCE_KIND); |
| 289 } | 290 } |
| 290 | 291 |
| 291 void test_getErrors() { | 292 void test_getErrors() { |
| 292 AnalysisError error1 = | 293 AnalysisError error1 = |
| 293 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 294 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
| 294 AnalysisError error2 = | 295 AnalysisError error2 = |
| 295 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 296 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
| 296 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 297 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
| 297 LineInfo lineInfo = new LineInfo([0]); | |
| 298 entry1.setValue(LINE_INFO, lineInfo, []); | |
| 299 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 298 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
| 300 context | 299 context |
| 301 .getCacheEntry(new LibrarySpecificUnit(source2, source1)) | 300 .getCacheEntry(new LibrarySpecificUnit(source2, source1)) |
| 302 .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); | 301 .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); |
| 303 AnalysisErrorInfo errorInfo = manager.getErrors(source1); | 302 List<AnalysisError> errors = manager.getErrors(source1); |
| 304 expect(errorInfo.errors, unorderedEquals([error1, error2])); | 303 expect(errors, unorderedEquals([error1, error2])); |
| 305 expect(errorInfo.lineInfo, lineInfo); | |
| 306 } | 304 } |
| 307 | 305 |
| 308 void test_getErrors_hasFullList() { | 306 void test_getErrors_hasFullList() { |
| 309 AnalysisError error1 = | 307 AnalysisError error1 = |
| 310 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 308 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
| 311 AnalysisError error2 = | 309 AnalysisError error2 = |
| 312 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 310 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
| 313 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 311 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
| 314 LineInfo lineInfo = new LineInfo([0]); | |
| 315 entry1.setValue(LINE_INFO, lineInfo, []); | |
| 316 entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []); | 312 entry1.setValue(DART_ERRORS, <AnalysisError>[error1, error2], []); |
| 317 AnalysisErrorInfo errorInfo = manager.getErrors(source1); | 313 List<AnalysisError> errors = manager.getErrors(source1); |
| 318 expect(errorInfo.errors, unorderedEquals([error1, error2])); | 314 expect(errors, unorderedEquals([error1, error2])); |
| 319 expect(errorInfo.lineInfo, lineInfo); | |
| 320 } | 315 } |
| 321 | 316 |
| 322 void test_getLibrariesContainingPart() { | 317 void test_getLibrariesContainingPart() { |
| 323 Source part1 = new TestSource('part1.dart'); | 318 Source part1 = new TestSource('part1.dart'); |
| 324 Source part2 = new TestSource('part2.dart'); | 319 Source part2 = new TestSource('part2.dart'); |
| 325 Source part3 = new TestSource('part3.dart'); | 320 Source part3 = new TestSource('part3.dart'); |
| 326 Source library1 = new TestSource('library1.dart'); | 321 Source library1 = new TestSource('library1.dart'); |
| 327 Source library2 = new TestSource('library2.dart'); | 322 Source library2 = new TestSource('library2.dart'); |
| 328 manager.partLibrariesMap[part1] = [library1, library2]; | 323 manager.partLibrariesMap[part1] = [library1, library2]; |
| 329 manager.partLibrariesMap[part2] = [library2]; | 324 manager.partLibrariesMap[part2] = [library2]; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); | 518 expect(unitEntry.getState(BUILD_LIBRARY_ERRORS), CacheState.INVALID); |
| 524 // ...and URIs resolution too | 519 // ...and URIs resolution too |
| 525 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); | 520 expect(entry1.getState(PARSED_UNIT), CacheState.INVALID); |
| 526 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); | 521 expect(entry1.getState(IMPORTED_LIBRARIES), CacheState.INVALID); |
| 527 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); | 522 expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID); |
| 528 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); | 523 expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID); |
| 529 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); | 524 expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID); |
| 530 } | 525 } |
| 531 | 526 |
| 532 void test_resultsComputed_errors_forLibrarySpecificUnit() { | 527 void test_resultsComputed_errors_forLibrarySpecificUnit() { |
| 528 LineInfo lineInfo = new LineInfo([0]); |
| 533 AnalysisError error1 = | 529 AnalysisError error1 = |
| 534 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 530 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
| 535 AnalysisError error2 = | 531 AnalysisError error2 = |
| 536 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 532 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
| 537 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 533 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
| 538 LineInfo lineInfo = new LineInfo([0]); | 534 when(context.getErrors(source1)) |
| 535 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); |
| 539 entry1.setValue(LINE_INFO, lineInfo, []); | 536 entry1.setValue(LINE_INFO, lineInfo, []); |
| 540 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 537 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
| 541 AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); | 538 AnalysisTarget unitTarget = new LibrarySpecificUnit(source2, source1); |
| 542 context | 539 context |
| 543 .getCacheEntry(unitTarget) | 540 .getCacheEntry(unitTarget) |
| 544 .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); | 541 .setValue(VERIFY_ERRORS, <AnalysisError>[error2], []); |
| 545 // RESOLVED_UNIT is ready, set errors | 542 // RESOLVED_UNIT is ready, set errors |
| 546 manager.resultsComputed( | 543 manager.resultsComputed( |
| 547 unitTarget, {RESOLVED_UNIT: AstFactory.compilationUnit()}); | 544 unitTarget, {RESOLVED_UNIT: AstFactory.compilationUnit()}); |
| 548 // all of the errors are included | 545 // all of the errors are included |
| 549 ChangeNoticeImpl notice = context.getNotice(source1); | 546 ChangeNoticeImpl notice = context.getNotice(source1); |
| 550 expect(notice.errors, unorderedEquals([error1, error2])); | 547 expect(notice.errors, unorderedEquals([error1, error2])); |
| 551 expect(notice.lineInfo, lineInfo); | 548 expect(notice.lineInfo, lineInfo); |
| 552 } | 549 } |
| 553 | 550 |
| 554 void test_resultsComputed_errors_forSource() { | 551 void test_resultsComputed_errors_forSource() { |
| 552 LineInfo lineInfo = new LineInfo([0]); |
| 555 AnalysisError error1 = | 553 AnalysisError error1 = |
| 556 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); | 554 new AnalysisError(source1, 1, 0, ScannerErrorCode.MISSING_DIGIT); |
| 557 AnalysisError error2 = | 555 AnalysisError error2 = |
| 558 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); | 556 new AnalysisError(source1, 2, 0, ScannerErrorCode.MISSING_DIGIT); |
| 559 when(context.getLibrariesContaining(source1)).thenReturn([source2]); | 557 when(context.getLibrariesContaining(source1)).thenReturn([source2]); |
| 560 LineInfo lineInfo = new LineInfo([0]); | 558 when(context.getErrors(source1)) |
| 559 .thenReturn(new AnalysisErrorInfoImpl([error1, error2], lineInfo)); |
| 561 entry1.setValue(LINE_INFO, lineInfo, []); | 560 entry1.setValue(LINE_INFO, lineInfo, []); |
| 562 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); | 561 entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []); |
| 563 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); | 562 entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []); |
| 564 // PARSED_UNIT is ready, set errors | 563 // PARSED_UNIT is ready, set errors |
| 565 manager.resultsComputed( | 564 manager.resultsComputed( |
| 566 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); | 565 source1, {PARSED_UNIT: AstFactory.compilationUnit()}); |
| 567 // all of the errors are included | 566 // all of the errors are included |
| 568 ChangeNoticeImpl notice = context.getNotice(source1); | 567 ChangeNoticeImpl notice = context.getNotice(source1); |
| 569 expect(notice.errors, unorderedEquals([error1, error2])); | 568 expect(notice.errors, unorderedEquals([error1, error2])); |
| 570 expect(notice.lineInfo, lineInfo); | 569 expect(notice.lineInfo, lineInfo); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 } | 607 } |
| 609 | 608 |
| 610 void test_resultsComputed_notDart() { | 609 void test_resultsComputed_notDart() { |
| 611 manager.unknownSourceQueue.addAll([source1, source2]); | 610 manager.unknownSourceQueue.addAll([source1, source2]); |
| 612 manager.resultsComputed(new TestSource('test.html'), {}); | 611 manager.resultsComputed(new TestSource('test.html'), {}); |
| 613 expect_librarySourceQueue([]); | 612 expect_librarySourceQueue([]); |
| 614 expect_unknownSourceQueue([source1, source2]); | 613 expect_unknownSourceQueue([source1, source2]); |
| 615 } | 614 } |
| 616 | 615 |
| 617 void test_resultsComputed_parsedUnit() { | 616 void test_resultsComputed_parsedUnit() { |
| 617 LineInfo lineInfo = new LineInfo([0]); |
| 618 when(context.getLibrariesContaining(source1)).thenReturn([]); | 618 when(context.getLibrariesContaining(source1)).thenReturn([]); |
| 619 LineInfo lineInfo = new LineInfo([0]); | 619 when(context.getErrors(source1)) |
| 620 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); |
| 620 entry1.setValue(LINE_INFO, lineInfo, []); | 621 entry1.setValue(LINE_INFO, lineInfo, []); |
| 621 CompilationUnit unit = AstFactory.compilationUnit(); | 622 CompilationUnit unit = AstFactory.compilationUnit(); |
| 622 manager.resultsComputed(source1, {PARSED_UNIT: unit}); | 623 manager.resultsComputed(source1, {PARSED_UNIT: unit}); |
| 623 ChangeNoticeImpl notice = context.getNotice(source1); | 624 ChangeNoticeImpl notice = context.getNotice(source1); |
| 624 expect(notice.parsedDartUnit, unit); | 625 expect(notice.parsedDartUnit, unit); |
| 625 expect(notice.resolvedDartUnit, isNull); | 626 expect(notice.resolvedDartUnit, isNull); |
| 626 expect(notice.lineInfo, lineInfo); | 627 expect(notice.lineInfo, lineInfo); |
| 627 } | 628 } |
| 628 | 629 |
| 629 void test_resultsComputed_resolvedUnit() { | 630 void test_resultsComputed_resolvedUnit() { |
| 631 LineInfo lineInfo = new LineInfo([0]); |
| 630 when(context.getLibrariesContaining(source2)).thenReturn([]); | 632 when(context.getLibrariesContaining(source2)).thenReturn([]); |
| 631 LineInfo lineInfo = new LineInfo([0]); | 633 when(context.getErrors(source2)) |
| 634 .thenReturn(new AnalysisErrorInfoImpl([], lineInfo)); |
| 632 entry2.setValue(LINE_INFO, lineInfo, []); | 635 entry2.setValue(LINE_INFO, lineInfo, []); |
| 633 CompilationUnit unit = AstFactory.compilationUnit(); | 636 CompilationUnit unit = AstFactory.compilationUnit(); |
| 634 manager.resultsComputed( | 637 manager.resultsComputed( |
| 635 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); | 638 new LibrarySpecificUnit(source1, source2), {RESOLVED_UNIT: unit}); |
| 636 ChangeNoticeImpl notice = context.getNotice(source2); | 639 ChangeNoticeImpl notice = context.getNotice(source2); |
| 637 expect(notice.parsedDartUnit, isNull); | 640 expect(notice.parsedDartUnit, isNull); |
| 638 expect(notice.resolvedDartUnit, unit); | 641 expect(notice.resolvedDartUnit, unit); |
| 639 expect(notice.lineInfo, lineInfo); | 642 expect(notice.lineInfo, lineInfo); |
| 640 } | 643 } |
| 641 | 644 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 } | 718 } |
| 716 | 719 |
| 717 @override | 720 @override |
| 718 ChangeNoticeImpl getNotice(Source source) { | 721 ChangeNoticeImpl getNotice(Source source) { |
| 719 return _pendingNotices.putIfAbsent( | 722 return _pendingNotices.putIfAbsent( |
| 720 source, () => new ChangeNoticeImpl(source)); | 723 source, () => new ChangeNoticeImpl(source)); |
| 721 } | 724 } |
| 722 | 725 |
| 723 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 726 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 724 } | 727 } |
| OLD | NEW |