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

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

Issue 1463833003: Don't update incrementally invalid results. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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 engine.incremental_resolver_test; 5 library engine.incremental_resolver_test;
6 6
7 import 'package:analyzer/src/context/cache.dart' as task; 7 import 'package:analyzer/src/context/cache.dart' as task;
8 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 11 import 'package:analyzer/src/generated/engine.dart' hide AnalysisCache;
11 import 'package:analyzer/src/generated/error.dart'; 12 import 'package:analyzer/src/generated/error.dart';
12 import 'package:analyzer/src/generated/incremental_logger.dart' as log; 13 import 'package:analyzer/src/generated/incremental_logger.dart' as log;
13 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; 14 import 'package:analyzer/src/generated/incremental_resolution_validator.dart';
14 import 'package:analyzer/src/generated/incremental_resolver.dart'; 15 import 'package:analyzer/src/generated/incremental_resolver.dart';
15 import 'package:analyzer/src/generated/java_engine.dart'; 16 import 'package:analyzer/src/generated/java_engine.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 17 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/resolver.dart'; 18 import 'package:analyzer/src/generated/resolver.dart';
18 import 'package:analyzer/src/generated/scanner.dart'; 19 import 'package:analyzer/src/generated/scanner.dart';
19 import 'package:analyzer/src/generated/source_io.dart'; 20 import 'package:analyzer/src/generated/source_io.dart';
20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 21 import 'package:analyzer/src/generated/testing/ast_factory.dart';
21 import 'package:analyzer/src/generated/testing/element_factory.dart'; 22 import 'package:analyzer/src/generated/testing/element_factory.dart';
23 import 'package:analyzer/src/task/dart.dart';
22 import 'package:analyzer/task/dart.dart'; 24 import 'package:analyzer/task/dart.dart';
23 import 'package:unittest/unittest.dart'; 25 import 'package:unittest/unittest.dart';
24 26
25 import '../reflective_tests.dart'; 27 import '../reflective_tests.dart';
26 import 'parser_test.dart'; 28 import 'parser_test.dart';
27 import 'resolver_test.dart'; 29 import 'resolver_test.dart';
28 import 'test_support.dart'; 30 import 'test_support.dart';
29 31
30 main() { 32 main() {
31 initializeTestEnvironment(); 33 initializeTestEnvironment();
(...skipping 4421 matching lines...) Expand 10 before | Expand all | Expand 10 after
4453 foo(int p) {} 4455 foo(int p) {}
4454 '''); 4456 ''');
4455 _updateAndValidate(r''' 4457 _updateAndValidate(r'''
4456 main() { 4458 main() {
4457 foo('abc'); 4459 foo('abc');
4458 } 4460 }
4459 foo(int p) {} 4461 foo(int p) {}
4460 '''); 4462 ''');
4461 } 4463 }
4462 4464
4465 void test_updateErrors_invalidVerifyErrors() {
4466 _resolveUnit(r'''
4467 main() {
4468 foo('aaa');
4469 }
4470 main2() {
4471 foo('bbb');
4472 }
4473 foo(int p) {}
4474 ''');
4475 // Complete analysis, e.g. compute VERIFY_ERRORS.
4476 _runTasks();
4477 // Invalidate VERIFY_ERRORS.
4478 AnalysisCache cache = analysisContext2.analysisCache;
4479 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4480 task.CacheEntry cacheEntry = cache.get(target);
4481 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(2));
4482 cacheEntry.setState(VERIFY_ERRORS, CacheState.INVALID);
4483 // Don't run tasks, so don't recompute VERIFY_ERRORS before incremental.
4484 _updateAndValidate(
4485 r'''
4486 main() {
4487 foo(0);
4488 }
4489 main2() {
4490 foo('bbb');
4491 }
4492 foo(int p) {}
4493 ''',
4494 runTasksBeforeIncremental: false);
4495 // Incremental analysis should have left VERIFY_ERRORS invalid,
4496 // so it was correctly recomputed later during the full analysis.
4497 expect(cacheEntry.getValue(VERIFY_ERRORS), hasLength(1));
4498 }
4499
4463 void test_updateErrors_removeExisting_hint() { 4500 void test_updateErrors_removeExisting_hint() {
4464 _resolveUnit(r''' 4501 _resolveUnit(r'''
4465 int main() { 4502 int main() {
4466 } 4503 }
4467 '''); 4504 ''');
4468 _updateAndValidate(r''' 4505 _updateAndValidate(r'''
4469 int main() { 4506 int main() {
4470 return 42; 4507 return 42;
4471 } 4508 }
4472 '''); 4509 ''');
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
4588 } 4625 }
4589 4626
4590 void _runTasks() { 4627 void _runTasks() {
4591 AnalysisResult result = analysisContext.performAnalysisTask(); 4628 AnalysisResult result = analysisContext.performAnalysisTask();
4592 while (result.changeNotices != null) { 4629 while (result.changeNotices != null) {
4593 result = analysisContext.performAnalysisTask(); 4630 result = analysisContext.performAnalysisTask();
4594 } 4631 }
4595 } 4632 }
4596 4633
4597 void _updateAndValidate(String newCode, 4634 void _updateAndValidate(String newCode,
4598 {bool expectedSuccess: true, bool compareWithFull: true}) { 4635 {bool expectedSuccess: true,
4636 bool compareWithFull: true,
4637 bool runTasksBeforeIncremental: true}) {
4599 // Run any pending tasks tasks. 4638 // Run any pending tasks tasks.
4600 _runTasks(); 4639 if (runTasksBeforeIncremental) {
4640 _runTasks();
4641 }
4601 // Update the source - currently this may cause incremental resolution. 4642 // Update the source - currently this may cause incremental resolution.
4602 // Then request the updated resolved unit. 4643 // Then request the updated resolved unit.
4603 _resetWithIncremental(true); 4644 _resetWithIncremental(true);
4604 analysisContext2.setContents(source, newCode); 4645 analysisContext2.setContents(source, newCode);
4605 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); 4646 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary);
4606 List<AnalysisError> newErrors = analysisContext.computeErrors(source); 4647 List<AnalysisError> newErrors = analysisContext.computeErrors(source);
4607 LineInfo newLineInfo = analysisContext.getLineInfo(source); 4648 LineInfo newLineInfo = analysisContext.getLineInfo(source);
4608 // check for expected failure 4649 // check for expected failure
4609 if (!expectedSuccess) { 4650 if (!expectedSuccess) {
4610 expect(newUnit.element, isNot(same(oldUnitElement))); 4651 expect(newUnit.element, isNot(same(oldUnitElement)));
4611 return; 4652 return;
4612 } 4653 }
4613 // The existing CompilationUnit[Element] should be updated. 4654 // The existing CompilationUnit[Element] should be updated.
4614 expect(newUnit, same(oldUnit)); 4655 expect(newUnit, same(oldUnit));
4615 expect(newUnit.element, same(oldUnitElement)); 4656 expect(newUnit.element, same(oldUnitElement));
4616 expect(analysisContext.parseCompilationUnit(source), same(oldUnit)); 4657 expect(analysisContext.getResolvedCompilationUnit(source, oldLibrary),
4658 same(oldUnit));
4617 // The only expected pending task should return the same resolved 4659 // The only expected pending task should return the same resolved
4618 // "newUnit", so all clients will get it using the usual way. 4660 // "newUnit", so all clients will get it using the usual way.
4619 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); 4661 AnalysisResult analysisResult = analysisContext.performAnalysisTask();
4620 ChangeNotice notice = analysisResult.changeNotices[0]; 4662 ChangeNotice notice = analysisResult.changeNotices[0];
4621 expect(notice.resolvedDartUnit, same(newUnit)); 4663 expect(notice.resolvedDartUnit, same(newUnit));
4622 // Resolve "newCode" from scratch. 4664 // Resolve "newCode" from scratch.
4623 if (compareWithFull) { 4665 if (compareWithFull) {
4624 _resetWithIncremental(false); 4666 _resetWithIncremental(false);
4625 changeSource(source, newCode); 4667 changeSource(source, newCode);
4626 _runTasks(); 4668 _runTasks();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
4886 return ResolutionContextBuilder.contextFor(node, listener).scope; 4928 return ResolutionContextBuilder.contextFor(node, listener).scope;
4887 } 4929 }
4888 } 4930 }
4889 4931
4890 class _Edit { 4932 class _Edit {
4891 final int offset; 4933 final int offset;
4892 final int length; 4934 final int length;
4893 final String replacement; 4935 final String replacement;
4894 _Edit(this.offset, this.length, this.replacement); 4936 _Edit(this.offset, this.length, this.replacement);
4895 } 4937 }
OLDNEW
« pkg/analyzer/lib/src/context/cache.dart ('K') | « pkg/analyzer/lib/src/context/cache.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698