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

Unified Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1218503003: Don't remove ResultData(s) for incrementally updated results. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Disable 'limitInvalidationInTaskModel' Created 5 years, 6 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
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 69250b12de975dd38338e62da8aa07cda6a78ce4..dfe4880f444effa276b26b605fdf93e9582c799e 100644
--- a/pkg/analyzer/test/src/context/context_test.dart
+++ b/pkg/analyzer/test/src/context/context_test.dart
@@ -1581,28 +1581,48 @@ void g() { f(null); }''');
reason: "part resolved 1");
// update and analyze #1
context.setContents(partSource, "part of lib; // 1");
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
- reason: "library changed 2");
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
- reason: "part changed 2");
- _analyzeAll_assertFinished();
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
- reason: "library resolved 2");
- expect(
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
- reason: "part resolved 2");
+ if (AnalysisEngine.instance.limitInvalidationInTaskModel) {
+ expect(
+ context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
+ reason: "library changed 2");
+ expect(
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
+ reason: "part changed 2");
+ } else {
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
+ reason: "library changed 2");
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
+ reason: "part changed 2");
+ _analyzeAll_assertFinished();
+ expect(
+ context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
+ reason: "library resolved 2");
+ expect(
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
+ reason: "part resolved 2");
+ }
// update and analyze #2
context.setContents(partSource, "part of lib; // 12");
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
- reason: "library changed 3");
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
- reason: "part changed 3");
- _analyzeAll_assertFinished();
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
- reason: "library resolved 3");
- expect(
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
- reason: "part resolved 3");
+ if (AnalysisEngine.instance.limitInvalidationInTaskModel) {
+ expect(
+ context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
+ reason: "library changed 3");
+ expect(
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
+ reason: "part changed 3");
+ } else {
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
+ reason: "library changed 3");
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
+ reason: "part changed 3");
+ _analyzeAll_assertFinished();
+ expect(
+ context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
+ reason: "library resolved 3");
+ expect(
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
+ reason: "part resolved 3");
+ }
}
void test_performAnalysisTask_importedLibraryAdd() {
@@ -2069,6 +2089,89 @@ class LimitedInvalidateTest extends AbstractContextTest {
super.tearDown();
}
+ void test_noChange_thenChange() {
+ Source sourceA = addSource("/a.dart", r'''
+library lib_a;
+
+class A {
+ A();
+}
+class B {
+ B();
+}
+''');
+ Source sourceB = addSource("/b.dart", r'''
+library lib_b;
+import 'a.dart';
+main() {
+ new A();
+}
+''');
+ _performPendingAnalysisTasks();
+ expect(context.getErrors(sourceA).errors, hasLength(0));
+ expect(context.getErrors(sourceB).errors, hasLength(0));
+ var unitA = context.getResolvedCompilationUnit2(sourceA, sourceA);
+ var unitElementA = unitA.element;
+ var libraryElementA = unitElementA.library;
+ // Update a.dart, no declaration changes.
+ context.setContents(sourceA, r'''
+library lib_a;
+class A {
+ A();
+}
+class B {
+ B();
+}
+''');
+ _assertInvalid(sourceA, LIBRARY_ERRORS_READY);
+ _assertValid(sourceB, LIBRARY_ERRORS_READY);
+ // The a.dart's unit and element are updated incrementally.
+ // They are the same instances as initially.
+ // So, all the references from other units are still valid.
+ {
+ LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA);
+ expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA));
+ expect(unitA.element, same(unitElementA));
+ expect(unitElementA.library, same(libraryElementA));
+ }
+ // Analyze.
+ _performPendingAnalysisTasks();
+ expect(context.getErrors(sourceA).errors, hasLength(0));
+ expect(context.getErrors(sourceB).errors, hasLength(0));
+ // The a.dart's unit and element are the same.
+ {
+ LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA);
+ expect(analysisCache.getValue(target, RESOLVED_UNIT), same(unitA));
+ expect(unitA.element, same(unitElementA));
+ expect(unitElementA.library, same(libraryElementA));
+ }
+ // Update a.dart, rename A to A2, invalidates b.dart, so
+ // we know that the previous update did not damage dependencies.
+ context.setContents(sourceA, r'''
+library lib_a;
+class A {
+ A();
+ m() {}
+}
+class B {
+ B();
+}
+''');
+ _assertInvalid(sourceA, LIBRARY_ERRORS_READY);
+ _assertInvalid(sourceB, LIBRARY_ERRORS_READY);
+ // The a.dart's unit and element are the same.
+ {
+ LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA);
+ expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA));
+ expect(unitA.element, same(unitElementA));
+ expect(unitElementA.library, same(libraryElementA));
+ }
+ // Analyze.
+ _performPendingAnalysisTasks();
+ expect(context.getErrors(sourceA).errors, hasLength(0));
+ expect(context.getErrors(sourceB).errors, hasLength(0));
+ }
+
void test_unusedName() {
Source sourceA = addSource("/a.dart", r'''
library lib_a;
« pkg/analyzer/lib/src/context/context.dart ('K') | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698