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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 2209493003: Don't report removed sources as changed in CacheConsistencyValidatorImpl. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.context.context_test; 5 library analyzer.test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 expect(sources, hasLength(1)); 448 expect(sources, hasLength(1));
449 expect(sources[0], same(libA)); 449 expect(sources[0], same(libA));
450 return pumpEventQueue().then((_) { 450 return pumpEventQueue().then((_) {
451 listener.assertEvent(wereSourcesAdded: true); 451 listener.assertEvent(wereSourcesAdded: true);
452 listener.assertEvent(wereSourcesAdded: true); 452 listener.assertEvent(wereSourcesAdded: true);
453 listener.assertEvent(wereSourcesRemovedOrDeleted: true); 453 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
454 listener.assertNoMoreEvents(); 454 listener.assertNoMoreEvents();
455 }); 455 });
456 } 456 }
457 457
458 void test_cacheConsistencyValidator_computed() { 458 void test_applyChanges_removeUsedLibrary_addAgain() {
459 String codeA = r'''
460 import 'b.dart';
461 B b = null;
462 ''';
463 String codeB = r'''
464 class B {}
465 ''';
466 Source a = addSource('/a.dart', codeA);
467 Source b = addSource('/b.dart', codeB);
468 CacheState getErrorsState(Source source) =>
469 context.analysisCache.getState(source, LIBRARY_ERRORS_READY);
470 _performPendingAnalysisTasks();
471 expect(context.getErrors(a).errors, hasLength(0));
472 // Remove b.dart - errors in a.dart are invalidated and recomputed.
473 // Now a.dart has an error.
474 _removeSource(b);
475 expect(getErrorsState(a), CacheState.INVALID);
476 _performPendingAnalysisTasks();
477 expect(getErrorsState(a), CacheState.VALID);
478 expect(context.getErrors(a).errors, hasLength(isPositive));
479 // Add b.dart - errors in a.dart are invalidated and recomputed.
480 // The reason is that a.dart adds dependencies on (not existing) b.dart
481 // results in cache.
482 // Now a.dart does not have errors.
483 addSource('/b.dart', codeB);
484 expect(getErrorsState(a), CacheState.INVALID);
485 _performPendingAnalysisTasks();
486 expect(getErrorsState(a), CacheState.VALID);
487 expect(context.getErrors(a).errors, hasLength(0));
488 }
489
490 void test_cacheConsistencyValidator_computed_deleted() {
459 CacheConsistencyValidator validator = context.cacheConsistencyValidator; 491 CacheConsistencyValidator validator = context.cacheConsistencyValidator;
492 var stat = PerformanceStatistics.cacheConsistencyValidationStatistics;
493 stat.reset();
460 // Add sources. 494 // Add sources.
461 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); 495 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
462 String path1 = '/test1.dart'; 496 String path1 = '/test1.dart';
497 String path2 = '/test2.dart';
498 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
499 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
500 context.applyChanges(
501 new ChangeSet()..addedSource(source1)..addedSource(source2));
502 // Same modification times.
503 expect(
504 validator.sourceModificationTimesComputed([source1, source2],
505 [source1.modificationStamp, source2.modificationStamp]),
506 isFalse);
507 expect(stat.numOfChanged, 0);
508 expect(stat.numOfRemoved, 0);
509 // Add overlay
510 context.setContents(source1, '// 1-2');
511 expect(
512 validator.sourceModificationTimesComputed(
513 [source1, source2], [-1, source2.modificationStamp]),
514 isFalse);
515 context.setContents(source1, null);
516 expect(stat.numOfChanged, 0);
517 expect(stat.numOfRemoved, 0);
518 // Different modification times.
519 expect(
520 validator.sourceModificationTimesComputed(
521 [source1, source2], [-1, source2.modificationStamp]),
522 isTrue);
523 expect(stat.numOfChanged, 0);
524 expect(stat.numOfRemoved, 1);
525 }
526
527 void test_cacheConsistencyValidator_computed_modified() {
528 CacheConsistencyValidator validator = context.cacheConsistencyValidator;
529 var stat = PerformanceStatistics.cacheConsistencyValidationStatistics;
530 stat.reset();
531 // Add sources.
532 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
533 String path1 = '/test1.dart';
463 String path2 = '/test2.dart'; 534 String path2 = '/test2.dart';
464 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource(); 535 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
465 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource(); 536 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
466 context.applyChanges( 537 context.applyChanges(
467 new ChangeSet()..addedSource(source1)..addedSource(source2)); 538 new ChangeSet()..addedSource(source1)..addedSource(source2));
468 // Same modification times. 539 // Same modification times.
469 expect( 540 expect(
470 validator.sourceModificationTimesComputed([source1, source2], 541 validator.sourceModificationTimesComputed([source1, source2],
471 [source1.modificationStamp, source2.modificationStamp]), 542 [source1.modificationStamp, source2.modificationStamp]),
472 isFalse); 543 isFalse);
544 expect(stat.numOfChanged, 0);
545 expect(stat.numOfRemoved, 0);
473 // Add overlay 546 // Add overlay
474 context.setContents(source1, '// 1-2'); 547 context.setContents(source1, '// 1-2');
475 expect( 548 expect(
476 validator.sourceModificationTimesComputed([source1, source2], 549 validator.sourceModificationTimesComputed([source1, source2],
477 [source1.modificationStamp + 1, source2.modificationStamp]), 550 [source1.modificationStamp + 1, source2.modificationStamp]),
478 isFalse); 551 isFalse);
479 context.setContents(source1, null); 552 context.setContents(source1, null);
553 expect(stat.numOfChanged, 0);
554 expect(stat.numOfRemoved, 0);
480 // Different modification times. 555 // Different modification times.
481 expect( 556 expect(
482 validator.sourceModificationTimesComputed([source1, source2], 557 validator.sourceModificationTimesComputed([source1, source2],
483 [source1.modificationStamp + 1, source2.modificationStamp]), 558 [source1.modificationStamp + 1, source2.modificationStamp]),
484 isTrue); 559 isTrue);
560 expect(stat.numOfChanged, 1);
561 expect(stat.numOfRemoved, 0);
485 } 562 }
486 563
487 void test_cacheConsistencyValidator_getSources() { 564 void test_cacheConsistencyValidator_getSources() {
488 CacheConsistencyValidator validator = context.cacheConsistencyValidator; 565 CacheConsistencyValidator validator = context.cacheConsistencyValidator;
489 // Add sources. 566 // Add sources.
490 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); 567 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
491 String path1 = '/test1.dart'; 568 String path1 = '/test1.dart';
492 String path2 = '/test2.dart'; 569 String path2 = '/test2.dart';
493 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource(); 570 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
494 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource(); 571 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
(...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 '''); 2891 ''');
2815 Source b = addSource( 2892 Source b = addSource(
2816 '/b.dart', 2893 '/b.dart',
2817 r''' 2894 r'''
2818 import 'a.dart'; 2895 import 'a.dart';
2819 List<A> foo() => []; 2896 List<A> foo() => [];
2820 '''); 2897 ''');
2821 _performPendingAnalysisTasks(); 2898 _performPendingAnalysisTasks();
2822 expect(context.getErrors(b).errors, hasLength(0)); 2899 expect(context.getErrors(b).errors, hasLength(0));
2823 // Add @deprecated annotation. 2900 // Add @deprecated annotation.
2824 // b.dart could have valid resolution, because A is still A, 2901 // b.dart has valid resolution, because A is still A, so only errors are
2825 // but deprecated hints are reported in resolved. So, everything in b.dart 2902 // invalidated.
2826 // is invalid.
2827 context.setContents( 2903 context.setContents(
2828 a, 2904 a,
2829 r''' 2905 r'''
2830 @deprecated 2906 @deprecated
2831 class A {} 2907 class A {}
2832 '''); 2908 ''');
2833 _assertValidForChangedLibrary(a); 2909 _assertValidForChangedLibrary(a);
2834 _assertInvalid(a, LIBRARY_ERRORS_READY); 2910 _assertInvalid(a, LIBRARY_ERRORS_READY);
2835 _assertValidForDependentLibrary(b); 2911 _assertValidForDependentLibrary(b);
2836 _assertInvalid(b, LIBRARY_ERRORS_READY); 2912 _assertInvalid(b, LIBRARY_ERRORS_READY);
(...skipping 16 matching lines...) Expand all
2853 '''); 2929 ''');
2854 Source b = addSource( 2930 Source b = addSource(
2855 '/b.dart', 2931 '/b.dart',
2856 r''' 2932 r'''
2857 import 'a.dart'; 2933 import 'a.dart';
2858 List<A> foo() => []; 2934 List<A> foo() => [];
2859 '''); 2935 ''');
2860 _performPendingAnalysisTasks(); 2936 _performPendingAnalysisTasks();
2861 expect(context.getErrors(b).errors, hasLength(1)); 2937 expect(context.getErrors(b).errors, hasLength(1));
2862 // Add @deprecated annotation. 2938 // Add @deprecated annotation.
2863 // b.dart could have valid resolution, because A is still A, 2939 // b.dart has valid resolution, because A is still A, so only errors are
2864 // but deprecated hints are reported in resolved. So, everything in b.dart 2940 // invalidated.
2865 // is invalid.
2866 context.setContents( 2941 context.setContents(
2867 a, 2942 a,
2868 r''' 2943 r'''
2869 class A {} 2944 class A {}
2870 '''); 2945 ''');
2871 _assertValidForChangedLibrary(a); 2946 _assertValidForChangedLibrary(a);
2872 _assertInvalid(a, LIBRARY_ERRORS_READY); 2947 _assertInvalid(a, LIBRARY_ERRORS_READY);
2873 _assertValidForDependentLibrary(b); 2948 _assertValidForDependentLibrary(b);
2874 _assertInvalid(b, LIBRARY_ERRORS_READY); 2949 _assertInvalid(b, LIBRARY_ERRORS_READY);
2875 _assertValidAllResolution(b); 2950 _assertValidAllResolution(b);
(...skipping 2193 matching lines...) Expand 10 before | Expand all | Expand 10 after
5069 * Initialize the visitor. 5144 * Initialize the visitor.
5070 */ 5145 */
5071 _ElementGatherer(); 5146 _ElementGatherer();
5072 5147
5073 @override 5148 @override
5074 void visitElement(Element element) { 5149 void visitElement(Element element) {
5075 elements[element] = element; 5150 elements[element] = element;
5076 super.visitElement(element); 5151 super.visitElement(element);
5077 } 5152 }
5078 } 5153 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698