OLD | NEW |
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 test.src.context.context_test; | 5 library test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
(...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 addSource("/test.dart", "library lib; part 'test-part.dart';"); | 1574 addSource("/test.dart", "library lib; part 'test-part.dart';"); |
1575 Source partSource = addSource("/test-part.dart", "part of lib;"); | 1575 Source partSource = addSource("/test-part.dart", "part of lib;"); |
1576 _analyzeAll_assertFinished(); | 1576 _analyzeAll_assertFinished(); |
1577 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 1577 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
1578 reason: "library resolved 1"); | 1578 reason: "library resolved 1"); |
1579 expect( | 1579 expect( |
1580 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 1580 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
1581 reason: "part resolved 1"); | 1581 reason: "part resolved 1"); |
1582 // update and analyze #1 | 1582 // update and analyze #1 |
1583 context.setContents(partSource, "part of lib; // 1"); | 1583 context.setContents(partSource, "part of lib; // 1"); |
1584 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | 1584 if (AnalysisEngine.instance.limitInvalidationInTaskModel) { |
1585 reason: "library changed 2"); | 1585 expect( |
1586 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | 1586 context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
1587 reason: "part changed 2"); | 1587 reason: "library changed 2"); |
1588 _analyzeAll_assertFinished(); | 1588 expect( |
1589 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 1589 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
1590 reason: "library resolved 2"); | 1590 reason: "part changed 2"); |
1591 expect( | 1591 } else { |
1592 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 1592 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
1593 reason: "part resolved 2"); | 1593 reason: "library changed 2"); |
| 1594 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1595 reason: "part changed 2"); |
| 1596 _analyzeAll_assertFinished(); |
| 1597 expect( |
| 1598 context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1599 reason: "library resolved 2"); |
| 1600 expect( |
| 1601 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1602 reason: "part resolved 2"); |
| 1603 } |
1594 // update and analyze #2 | 1604 // update and analyze #2 |
1595 context.setContents(partSource, "part of lib; // 12"); | 1605 context.setContents(partSource, "part of lib; // 12"); |
1596 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | 1606 if (AnalysisEngine.instance.limitInvalidationInTaskModel) { |
1597 reason: "library changed 3"); | 1607 expect( |
1598 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | 1608 context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
1599 reason: "part changed 3"); | 1609 reason: "library changed 3"); |
1600 _analyzeAll_assertFinished(); | 1610 expect( |
1601 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 1611 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
1602 reason: "library resolved 3"); | 1612 reason: "part changed 3"); |
1603 expect( | 1613 } else { |
1604 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 1614 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
1605 reason: "part resolved 3"); | 1615 reason: "library changed 3"); |
| 1616 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1617 reason: "part changed 3"); |
| 1618 _analyzeAll_assertFinished(); |
| 1619 expect( |
| 1620 context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1621 reason: "library resolved 3"); |
| 1622 expect( |
| 1623 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1624 reason: "part resolved 3"); |
| 1625 } |
1606 } | 1626 } |
1607 | 1627 |
1608 void test_performAnalysisTask_importedLibraryAdd() { | 1628 void test_performAnalysisTask_importedLibraryAdd() { |
1609 Source libASource = | 1629 Source libASource = |
1610 addSource("/libA.dart", "library libA; import 'libB.dart';"); | 1630 addSource("/libA.dart", "library libA; import 'libB.dart';"); |
1611 _analyzeAll_assertFinished(); | 1631 _analyzeAll_assertFinished(); |
1612 expect( | 1632 expect( |
1613 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | 1633 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
1614 reason: "libA resolved 1"); | 1634 reason: "libA resolved 1"); |
1615 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), | 1635 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)), |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 AnalysisEngine.instance.limitInvalidationInTaskModel = true; | 2082 AnalysisEngine.instance.limitInvalidationInTaskModel = true; |
2063 super.setUp(); | 2083 super.setUp(); |
2064 } | 2084 } |
2065 | 2085 |
2066 @override | 2086 @override |
2067 void tearDown() { | 2087 void tearDown() { |
2068 AnalysisEngine.instance.limitInvalidationInTaskModel = false; | 2088 AnalysisEngine.instance.limitInvalidationInTaskModel = false; |
2069 super.tearDown(); | 2089 super.tearDown(); |
2070 } | 2090 } |
2071 | 2091 |
| 2092 void test_noChange_thenChange() { |
| 2093 Source sourceA = addSource("/a.dart", r''' |
| 2094 library lib_a; |
| 2095 |
| 2096 class A { |
| 2097 A(); |
| 2098 } |
| 2099 class B { |
| 2100 B(); |
| 2101 } |
| 2102 '''); |
| 2103 Source sourceB = addSource("/b.dart", r''' |
| 2104 library lib_b; |
| 2105 import 'a.dart'; |
| 2106 main() { |
| 2107 new A(); |
| 2108 } |
| 2109 '''); |
| 2110 _performPendingAnalysisTasks(); |
| 2111 expect(context.getErrors(sourceA).errors, hasLength(0)); |
| 2112 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2113 var unitA = context.getResolvedCompilationUnit2(sourceA, sourceA); |
| 2114 var unitElementA = unitA.element; |
| 2115 var libraryElementA = unitElementA.library; |
| 2116 // Update a.dart, no declaration changes. |
| 2117 context.setContents(sourceA, r''' |
| 2118 library lib_a; |
| 2119 class A { |
| 2120 A(); |
| 2121 } |
| 2122 class B { |
| 2123 B(); |
| 2124 } |
| 2125 '''); |
| 2126 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2127 _assertValid(sourceB, LIBRARY_ERRORS_READY); |
| 2128 // The a.dart's unit and element are updated incrementally. |
| 2129 // They are the same instances as initially. |
| 2130 // So, all the references from other units are still valid. |
| 2131 { |
| 2132 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); |
| 2133 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); |
| 2134 expect(unitA.element, same(unitElementA)); |
| 2135 expect(unitElementA.library, same(libraryElementA)); |
| 2136 } |
| 2137 // Analyze. |
| 2138 _performPendingAnalysisTasks(); |
| 2139 expect(context.getErrors(sourceA).errors, hasLength(0)); |
| 2140 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2141 // The a.dart's unit and element are the same. |
| 2142 { |
| 2143 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); |
| 2144 expect(analysisCache.getValue(target, RESOLVED_UNIT), same(unitA)); |
| 2145 expect(unitA.element, same(unitElementA)); |
| 2146 expect(unitElementA.library, same(libraryElementA)); |
| 2147 } |
| 2148 // Update a.dart, rename A to A2, invalidates b.dart, so |
| 2149 // we know that the previous update did not damage dependencies. |
| 2150 context.setContents(sourceA, r''' |
| 2151 library lib_a; |
| 2152 class A { |
| 2153 A(); |
| 2154 m() {} |
| 2155 } |
| 2156 class B { |
| 2157 B(); |
| 2158 } |
| 2159 '''); |
| 2160 _assertInvalid(sourceA, LIBRARY_ERRORS_READY); |
| 2161 _assertInvalid(sourceB, LIBRARY_ERRORS_READY); |
| 2162 // The a.dart's unit and element are the same. |
| 2163 { |
| 2164 LibrarySpecificUnit target = new LibrarySpecificUnit(sourceA, sourceA); |
| 2165 expect(analysisCache.getValue(target, RESOLVED_UNIT1), same(unitA)); |
| 2166 expect(unitA.element, same(unitElementA)); |
| 2167 expect(unitElementA.library, same(libraryElementA)); |
| 2168 } |
| 2169 // Analyze. |
| 2170 _performPendingAnalysisTasks(); |
| 2171 expect(context.getErrors(sourceA).errors, hasLength(0)); |
| 2172 expect(context.getErrors(sourceB).errors, hasLength(0)); |
| 2173 } |
| 2174 |
2072 void test_unusedName() { | 2175 void test_unusedName() { |
2073 Source sourceA = addSource("/a.dart", r''' | 2176 Source sourceA = addSource("/a.dart", r''' |
2074 library lib_a; | 2177 library lib_a; |
2075 class A {} | 2178 class A {} |
2076 class B {} | 2179 class B {} |
2077 class C {} | 2180 class C {} |
2078 '''); | 2181 '''); |
2079 Source sourceB = addSource("/b.dart", r''' | 2182 Source sourceB = addSource("/b.dart", r''' |
2080 library lib_b; | 2183 library lib_b; |
2081 import 'a.dart'; | 2184 import 'a.dart'; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2213 } | 2316 } |
2214 } | 2317 } |
2215 | 2318 |
2216 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2319 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
2217 implements SourceContainer { | 2320 implements SourceContainer { |
2218 Source libB; | 2321 Source libB; |
2219 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2322 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
2220 @override | 2323 @override |
2221 bool contains(Source source) => source == libB; | 2324 bool contains(Source source) => source == libB; |
2222 } | 2325 } |
OLD | NEW |