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

Side by Side Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 1693243002: Validate cache results in incremental resolution tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | 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.generated.incremental_resolver_test; 5 library analyzer.test.generated.incremental_resolver_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/dart/ast/utilities.dart'; 10 import 'package:analyzer/src/dart/ast/utilities.dart';
(...skipping 3593 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 } 3604 }
3605 3605
3606 void test_computeConstants() { 3606 void test_computeConstants() {
3607 _resolveUnit(r''' 3607 _resolveUnit(r'''
3608 int f() => 0; 3608 int f() => 0;
3609 main() { 3609 main() {
3610 const x = f(); 3610 const x = f();
3611 print(x + 1); 3611 print(x + 1);
3612 } 3612 }
3613 '''); 3613 ''');
3614 _updateAndValidate(r''' 3614 _updateAndValidate(
3615 r'''
3615 int f() => 0; 3616 int f() => 0;
3616 main() { 3617 main() {
3617 const x = f(); 3618 const x = f();
3618 print(x + 2); 3619 print(x + 2);
3619 } 3620 }
3620 '''); 3621 ''',
3622 expectCachePostConstantsValid: false);
3621 } 3623 }
3622 3624
3623 void test_dartDoc_beforeField() { 3625 void test_dartDoc_beforeField() {
3624 _resolveUnit(r''' 3626 _resolveUnit(r'''
3625 class A { 3627 class A {
3626 /** 3628 /**
3627 * A field [field] of type [int] in class [A]. 3629 * A field [field] of type [int] in class [A].
3628 */ 3630 */
3629 int field; 3631 int field;
3630 } 3632 }
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
4199 const B(); 4201 const B();
4200 } 4202 }
4201 4203
4202 main() { 4204 main() {
4203 print(123); 4205 print(123);
4204 A.b; 4206 A.b;
4205 } 4207 }
4206 '''); 4208 ''');
4207 } 4209 }
4208 4210
4211 void test_hasElementAfter_defaultParameter() {
4212 _resolveUnit(r'''
4213 main() {
4214 print(1);
4215 }
4216 otherFunction([p = 0]) {}
4217 ''');
4218 _updateAndValidate(r'''
4219 main() {
4220 print(2);
4221 }
4222 otherFunction([p = 0]) {}
4223 ''');
4224 }
4225
4209 void test_inBody_expression() { 4226 void test_inBody_expression() {
4210 _resolveUnit(r''' 4227 _resolveUnit(r'''
4211 class A { 4228 class A {
4212 m() { 4229 m() {
4213 print(1); 4230 print(1);
4214 } 4231 }
4215 } 4232 }
4216 '''); 4233 ''');
4217 _updateAndValidate(r''' 4234 _updateAndValidate(r'''
4218 class A { 4235 class A {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
4543 List<AnalysisError> errors = analysisContext.getErrors(source).errors; 4560 List<AnalysisError> errors = analysisContext.getErrors(source).errors;
4544 expect(errors, isEmpty); 4561 expect(errors, isEmpty);
4545 } 4562 }
4546 4563
4547 void test_updateConstantInitializer() { 4564 void test_updateConstantInitializer() {
4548 _resolveUnit(r''' 4565 _resolveUnit(r'''
4549 main() { 4566 main() {
4550 const v = const [Unknown]; 4567 const v = const [Unknown];
4551 } 4568 }
4552 '''); 4569 ''');
4553 _updateAndValidate(r''' 4570 _updateAndValidate(
4571 r'''
4554 main() { 4572 main() {
4555 const v = const [Unknown]; 4573 const v = const [Unknown];
4556 } 4574 }
4557 '''); 4575 ''',
4576 expectCachePostConstantsValid: false);
4558 } 4577 }
4559 4578
4560 void test_updateErrors_addNew_hint1() { 4579 void test_updateErrors_addNew_hint1() {
4561 _resolveUnit(r''' 4580 _resolveUnit(r'''
4562 int main() { 4581 int main() {
4563 return 42; 4582 return 42;
4564 } 4583 }
4565 '''); 4584 ''');
4566 _updateAndValidate(r''' 4585 _updateAndValidate(r'''
4567 int main() { 4586 int main() {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
4821 { 4840 {
4822 ClassElement typeA = oldUnitElement.getType('A'); 4841 ClassElement typeA = oldUnitElement.getType('A');
4823 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA); 4842 expect(oldUnitElement.getElementAt(typeA.nameOffset), typeA);
4824 } 4843 }
4825 { 4844 {
4826 ClassElement typeB = oldUnitElement.getType('B'); 4845 ClassElement typeB = oldUnitElement.getType('B');
4827 expect(oldUnitElement.getElementAt(typeB.nameOffset), typeB); 4846 expect(oldUnitElement.getElementAt(typeB.nameOffset), typeB);
4828 } 4847 }
4829 } 4848 }
4830 4849
4850 void _assertCacheResults({bool expectCachePostConstantsValid: true}) {
4851 _assertCacheSourceResult(PARSED_UNIT);
4852 _assertCacheSourceResult(PARSE_ERRORS);
4853 _assertCacheSourceResult(LIBRARY_ELEMENT1);
4854 _assertCacheSourceResult(LIBRARY_ELEMENT2);
4855 _assertCacheSourceResult(LIBRARY_ELEMENT3);
4856 _assertCacheSourceResult(LIBRARY_ELEMENT4);
4857 _assertCacheSourceResult(LIBRARY_ELEMENT5);
4858 _assertCacheSourceResult(LIBRARY_ELEMENT6);
4859 _assertCacheSourceResult(LIBRARY_ELEMENT7);
4860 _assertCacheSourceResult(LIBRARY_ELEMENT8);
4861 if (expectCachePostConstantsValid) {
4862 _assertCacheSourceResult(LIBRARY_ELEMENT);
4863 }
4864 _assertCacheUnitResult(RESOLVED_UNIT1);
4865 _assertCacheUnitResult(RESOLVED_UNIT2);
4866 _assertCacheUnitResult(RESOLVED_UNIT3);
4867 _assertCacheUnitResult(RESOLVED_UNIT4);
4868 _assertCacheUnitResult(RESOLVED_UNIT5);
4869 _assertCacheUnitResult(RESOLVED_UNIT6);
4870 _assertCacheUnitResult(RESOLVED_UNIT7);
4871 _assertCacheUnitResult(RESOLVED_UNIT8);
4872 _assertCacheUnitResult(RESOLVED_UNIT9);
4873 _assertCacheUnitResult(RESOLVED_UNIT10);
4874 if (expectCachePostConstantsValid) {
4875 _assertCacheUnitResult(RESOLVED_UNIT11);
4876 _assertCacheUnitResult(RESOLVED_UNIT);
4877 }
4878 }
4879
4880 /**
4881 * Assert that the [result] of [source] is not INVALID.
4882 */
4883 void _assertCacheSourceResult(ResultDescriptor result) {
4884 AnalysisCache cache = analysisContext2.analysisCache;
4885 CacheState state = cache.getState(source, result);
4886 expect(state, isNot(CacheState.INVALID), reason: result.toString());
4887 }
4888
4889 /**
4890 * Assert that the [result] of the defining unit [source] is not INVALID.
4891 */
4892 void _assertCacheUnitResult(ResultDescriptor result) {
4893 AnalysisCache cache = analysisContext2.analysisCache;
4894 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4895 CacheState state = cache.getState(target, result);
4896 expect(state, isNot(CacheState.INVALID), reason: result.toString());
4897 }
4898
4831 void _assertEqualLineInfo(LineInfo incrLineInfo, LineInfo fullLineInfo) { 4899 void _assertEqualLineInfo(LineInfo incrLineInfo, LineInfo fullLineInfo) {
4832 for (int offset = 0; offset < 1000; offset++) { 4900 for (int offset = 0; offset < 1000; offset++) {
4833 LineInfo_Location incrLocation = incrLineInfo.getLocation(offset); 4901 LineInfo_Location incrLocation = incrLineInfo.getLocation(offset);
4834 LineInfo_Location fullLocation = fullLineInfo.getLocation(offset); 4902 LineInfo_Location fullLocation = fullLineInfo.getLocation(offset);
4835 if (incrLocation.lineNumber != fullLocation.lineNumber || 4903 if (incrLocation.lineNumber != fullLocation.lineNumber ||
4836 incrLocation.columnNumber != fullLocation.columnNumber) { 4904 incrLocation.columnNumber != fullLocation.columnNumber) {
4837 fail('At offset $offset ' + 4905 fail('At offset $offset ' +
4838 '(${incrLocation.lineNumber}, ${incrLocation.columnNumber})' + 4906 '(${incrLocation.lineNumber}, ${incrLocation.columnNumber})' +
4839 ' != ' + 4907 ' != ' +
4840 '(${fullLocation.lineNumber}, ${fullLocation.columnNumber})'); 4908 '(${fullLocation.lineNumber}, ${fullLocation.columnNumber})');
(...skipping 23 matching lines...) Expand all
4864 4932
4865 void _runTasks() { 4933 void _runTasks() {
4866 AnalysisResult result = analysisContext.performAnalysisTask(); 4934 AnalysisResult result = analysisContext.performAnalysisTask();
4867 while (result.changeNotices != null) { 4935 while (result.changeNotices != null) {
4868 result = analysisContext.performAnalysisTask(); 4936 result = analysisContext.performAnalysisTask();
4869 } 4937 }
4870 } 4938 }
4871 4939
4872 void _updateAndValidate(String newCode, 4940 void _updateAndValidate(String newCode,
4873 {bool expectedSuccess: true, 4941 {bool expectedSuccess: true,
4942 bool expectCachePostConstantsValid: true,
4874 bool compareWithFull: true, 4943 bool compareWithFull: true,
4875 bool runTasksBeforeIncremental: true}) { 4944 bool runTasksBeforeIncremental: true}) {
4876 // Run any pending tasks tasks. 4945 // Run any pending tasks tasks.
4877 if (runTasksBeforeIncremental) { 4946 if (runTasksBeforeIncremental) {
4878 _runTasks(); 4947 _runTasks();
4879 } 4948 }
4880 // Update the source - currently this may cause incremental resolution. 4949 // Update the source - currently this may cause incremental resolution.
4881 // Then request the updated resolved unit. 4950 // Then request the updated resolved unit.
4882 _resetWithIncremental(true); 4951 _resetWithIncremental(true);
4883 analysisContext2.setContents(source, newCode); 4952 analysisContext2.setContents(source, newCode);
4884 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); 4953 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary);
4885 expect(logger.hasError, isFalse); 4954 expect(logger.hasError, isFalse);
4886 List<AnalysisError> newErrors = analysisContext.computeErrors(source); 4955 List<AnalysisError> newErrors = analysisContext.computeErrors(source);
4887 LineInfo newLineInfo = analysisContext.getLineInfo(source); 4956 LineInfo newLineInfo = analysisContext.getLineInfo(source);
4888 // check for expected failure 4957 // check for expected failure
4889 if (!expectedSuccess) { 4958 if (!expectedSuccess) {
4890 expect(newUnit.element, isNot(same(oldUnitElement))); 4959 expect(newUnit.element, isNot(same(oldUnitElement)));
4891 return; 4960 return;
4892 } 4961 }
4962 // The cache must still have enough results to make the incremental
4963 // resolution useful.
4964 _assertCacheResults(
4965 expectCachePostConstantsValid: expectCachePostConstantsValid);
4893 // The existing CompilationUnit[Element] should be updated. 4966 // The existing CompilationUnit[Element] should be updated.
4894 expect(newUnit, same(oldUnit)); 4967 expect(newUnit, same(oldUnit));
4895 expect(newUnit.element, same(oldUnitElement)); 4968 expect(newUnit.element, same(oldUnitElement));
4896 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary), 4969 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary),
4897 same(oldUnit)); 4970 same(oldUnit));
4898 // The only expected pending task should return the same resolved 4971 // The only expected pending task should return the same resolved
4899 // "newUnit", so all clients will get it using the usual way. 4972 // "newUnit", so all clients will get it using the usual way.
4900 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); 4973 AnalysisResult analysisResult = analysisContext.performAnalysisTask();
4901 ChangeNotice notice = analysisResult.changeNotices[0]; 4974 ChangeNotice notice = analysisResult.changeNotices[0];
4902 expect(notice.resolvedDartUnit, same(newUnit)); 4975 expect(notice.resolvedDartUnit, same(newUnit));
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
5192 @override 5265 @override
5193 void logException(Object exception, [Object stackTrace]) { 5266 void logException(Object exception, [Object stackTrace]) {
5194 hasError = true; 5267 hasError = true;
5195 } 5268 }
5196 5269
5197 @override 5270 @override
5198 logging.LoggingTimer startTimer() { 5271 logging.LoggingTimer startTimer() {
5199 return new logging.LoggingTimer(this); 5272 return new logging.LoggingTimer(this);
5200 } 5273 }
5201 } 5274 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698