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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/context/context_test.dart
diff --git a/pkg/analyzer/test/src/context/context_test.dart b/pkg/analyzer/test/src/context/context_test.dart
index ab34174b595213b47f9da5e80d3f79bd1347dbfe..f5b695f5b5c4128002d38fb3e84f5cf7bbddbd46 100644
--- a/pkg/analyzer/test/src/context/context_test.dart
+++ b/pkg/analyzer/test/src/context/context_test.dart
@@ -455,8 +455,79 @@ import 'libB.dart';''';
});
}
- void test_cacheConsistencyValidator_computed() {
+ void test_applyChanges_removeUsedLibrary_addAgain() {
+ String codeA = r'''
+import 'b.dart';
+B b = null;
+''';
+ String codeB = r'''
+class B {}
+''';
+ Source a = addSource('/a.dart', codeA);
+ Source b = addSource('/b.dart', codeB);
+ CacheState getErrorsState(Source source) =>
+ context.analysisCache.getState(source, LIBRARY_ERRORS_READY);
+ _performPendingAnalysisTasks();
+ expect(context.getErrors(a).errors, hasLength(0));
+ // Remove b.dart - errors in a.dart are invalidated and recomputed.
+ // Now a.dart has an error.
+ _removeSource(b);
+ expect(getErrorsState(a), CacheState.INVALID);
+ _performPendingAnalysisTasks();
+ expect(getErrorsState(a), CacheState.VALID);
+ expect(context.getErrors(a).errors, hasLength(isPositive));
+ // Add b.dart - errors in a.dart are invalidated and recomputed.
+ // The reason is that a.dart adds dependencies on (not existing) b.dart
+ // results in cache.
+ // Now a.dart does not have errors.
+ addSource('/b.dart', codeB);
+ expect(getErrorsState(a), CacheState.INVALID);
+ _performPendingAnalysisTasks();
+ expect(getErrorsState(a), CacheState.VALID);
+ expect(context.getErrors(a).errors, hasLength(0));
+ }
+
+ void test_cacheConsistencyValidator_computed_deleted() {
+ CacheConsistencyValidator validator = context.cacheConsistencyValidator;
+ var stat = PerformanceStatistics.cacheConsistencyValidationStatistics;
+ stat.reset();
+ // Add sources.
+ MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
+ String path1 = '/test1.dart';
+ String path2 = '/test2.dart';
+ Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
+ Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
+ context.applyChanges(
+ new ChangeSet()..addedSource(source1)..addedSource(source2));
+ // Same modification times.
+ expect(
+ validator.sourceModificationTimesComputed([source1, source2],
+ [source1.modificationStamp, source2.modificationStamp]),
+ isFalse);
+ expect(stat.numOfChanged, 0);
+ expect(stat.numOfRemoved, 0);
+ // Add overlay
+ context.setContents(source1, '// 1-2');
+ expect(
+ validator.sourceModificationTimesComputed(
+ [source1, source2], [-1, source2.modificationStamp]),
+ isFalse);
+ context.setContents(source1, null);
+ expect(stat.numOfChanged, 0);
+ expect(stat.numOfRemoved, 0);
+ // Different modification times.
+ expect(
+ validator.sourceModificationTimesComputed(
+ [source1, source2], [-1, source2.modificationStamp]),
+ isTrue);
+ expect(stat.numOfChanged, 0);
+ expect(stat.numOfRemoved, 1);
+ }
+
+ void test_cacheConsistencyValidator_computed_modified() {
CacheConsistencyValidator validator = context.cacheConsistencyValidator;
+ var stat = PerformanceStatistics.cacheConsistencyValidationStatistics;
+ stat.reset();
// Add sources.
MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
String path1 = '/test1.dart';
@@ -470,6 +541,8 @@ import 'libB.dart';''';
validator.sourceModificationTimesComputed([source1, source2],
[source1.modificationStamp, source2.modificationStamp]),
isFalse);
+ expect(stat.numOfChanged, 0);
+ expect(stat.numOfRemoved, 0);
// Add overlay
context.setContents(source1, '// 1-2');
expect(
@@ -477,11 +550,15 @@ import 'libB.dart';''';
[source1.modificationStamp + 1, source2.modificationStamp]),
isFalse);
context.setContents(source1, null);
+ expect(stat.numOfChanged, 0);
+ expect(stat.numOfRemoved, 0);
// Different modification times.
expect(
validator.sourceModificationTimesComputed([source1, source2],
[source1.modificationStamp + 1, source2.modificationStamp]),
isTrue);
+ expect(stat.numOfChanged, 1);
+ expect(stat.numOfRemoved, 0);
}
void test_cacheConsistencyValidator_getSources() {
@@ -2821,9 +2898,8 @@ List<A> foo() => [];
_performPendingAnalysisTasks();
expect(context.getErrors(b).errors, hasLength(0));
// Add @deprecated annotation.
- // b.dart could have valid resolution, because A is still A,
- // but deprecated hints are reported in resolved. So, everything in b.dart
- // is invalid.
+ // b.dart has valid resolution, because A is still A, so only errors are
+ // invalidated.
context.setContents(
a,
r'''
@@ -2860,9 +2936,8 @@ List<A> foo() => [];
_performPendingAnalysisTasks();
expect(context.getErrors(b).errors, hasLength(1));
// Add @deprecated annotation.
- // b.dart could have valid resolution, because A is still A,
- // but deprecated hints are reported in resolved. So, everything in b.dart
- // is invalid.
+ // b.dart has valid resolution, because A is still A, so only errors are
+ // invalidated.
context.setContents(
a,
r'''
« 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