Chromium Code Reviews| Index: pkg/analyzer/test/generated/constant_test.dart |
| diff --git a/pkg/analyzer/test/generated/constant_test.dart b/pkg/analyzer/test/generated/constant_test.dart |
| index 966f487527f508ffce4529ded9e40be574e1e23f..fbfe4c4026e05d8d27eef87142512275ca3b5417 100644 |
| --- a/pkg/analyzer/test/generated/constant_test.dart |
| +++ b/pkg/analyzer/test/generated/constant_test.dart |
| @@ -2,7 +2,7 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| -library analyzer.test.generated.all_the_rest_test; |
| +library analyzer.test.generated.constant_test; |
| import 'package:analyzer/dart/ast/ast.dart'; |
| import 'package:analyzer/dart/element/element.dart'; |
| @@ -43,42 +43,49 @@ main() { |
| */ |
| class ConstantEvaluationValidator_ForTest |
| implements ConstantEvaluationValidator { |
| + final InternalAnalysisContext context; |
| ConstantValueComputer computer; |
| - |
| ConstantEvaluationTarget _nodeBeingEvaluated; |
| + ConstantEvaluationValidator_ForTest(this.context); |
| + |
| @override |
| void beforeComputeValue(ConstantEvaluationTarget constant) { |
| _nodeBeingEvaluated = constant; |
| } |
| @override |
| - void beforeGetConstantInitializers(ConstructorElement constructor) { |
| - // Make sure we properly recorded the dependency. |
| - expect( |
| - computer.referenceGraph.containsPath(_nodeBeingEvaluated, constructor), |
| - isTrue); |
| - } |
| + void beforeGetConstantInitializers(ConstructorElement constructor) => |
| + _checkPathTo(constructor); |
| @override |
| - void beforeGetEvaluationResult(ConstantEvaluationTarget constant) { |
| - // Make sure we properly recorded the dependency. |
| - expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, constant), |
| - isTrue); |
| - } |
| + void beforeGetEvaluationResult(ConstantEvaluationTarget constant) => |
| + _checkPathTo(constant); |
| @override |
| - void beforeGetFieldEvaluationResult(FieldElementImpl field) { |
| - // Make sure we properly recorded the dependency. |
| - expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, field), |
| - isTrue); |
| - } |
| + void beforeGetFieldEvaluationResult(FieldElementImpl field) => |
| + _checkPathTo(field); |
| @override |
| - void beforeGetParameterDefault(ParameterElement parameter) { |
| - // Make sure we properly recorded the dependency. |
| - expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, parameter), |
| - isTrue); |
| + void beforeGetParameterDefault(ParameterElement parameter) => |
| + _checkPathTo(parameter); |
| + |
| + void _checkPathTo(ConstantEvaluationTarget target) { |
| + if (computer.referenceGraph.containsPath(_nodeBeingEvaluated, target)) { |
| + return; // pass |
| + } |
| + // print a nice error message on failure |
| + var out = new StringBuffer(); |
|
Paul Berry
2016/01/22 15:02:22
In analyzer code we have made the deliberate choic
|
| + out.writeln("missing path in constant dependency graph"); |
| + out.writeln("from $_nodeBeingEvaluated to $target"); |
| + for (var s in context.analysisCache.sources) { |
| + var text = context.getContents(s).data; |
| + if (text == "") continue; |
|
Brian Wilkerson
2016/01/22 15:32:17
We also always use blocks in structured statements
|
| + out.writeln(''' |
| +=== ${s.shortName} |
| +$text'''); |
| + } |
| + fail(out.toString()); |
| } |
| } |
| @@ -851,17 +858,17 @@ class C { |
| TestLogger logger = new TestLogger(); |
| AnalysisEngine.instance.logger = logger; |
| try { |
| - Source librarySource = addSource(r''' |
| + Source source = addSource(r''' |
| const int a = c; |
| const int b = a; |
| const int c = b;'''); |
| - LibraryElement libraryElement = resolve2(librarySource); |
| + LibraryElement libraryElement = resolve2(source); |
| CompilationUnit unit = |
| - analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| - analysisContext.computeErrors(librarySource); |
| + analysisContext.resolveCompilationUnit(source, libraryElement); |
| + analysisContext.computeErrors(source); |
| expect(unit, isNotNull); |
| ConstantValueComputer computer = _makeConstantValueComputer(); |
| - computer.add(unit, librarySource, librarySource); |
| + computer.add(unit, source, source); |
| computer.computeValues(); |
| NodeList<CompilationUnitMember> members = unit.declarations; |
| expect(members, hasLength(3)); |
| @@ -874,15 +881,15 @@ class C { |
| } |
| void test_computeValues_dependentVariables() { |
| - Source librarySource = addSource(r''' |
| + Source source = addSource(r''' |
| const int b = a; |
| const int a = 0;'''); |
| - LibraryElement libraryElement = resolve2(librarySource); |
| + LibraryElement libraryElement = resolve2(source); |
| CompilationUnit unit = |
| - analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| + analysisContext.resolveCompilationUnit(source, libraryElement); |
| expect(unit, isNotNull); |
| ConstantValueComputer computer = _makeConstantValueComputer(); |
| - computer.add(unit, librarySource, librarySource); |
| + computer.add(unit, source, source); |
| computer.computeValues(); |
| NodeList<CompilationUnitMember> members = unit.declarations; |
| expect(members, hasLength(2)); |
| @@ -933,13 +940,13 @@ const int d = c;'''); |
| } |
| void test_computeValues_singleVariable() { |
| - Source librarySource = addSource("const int a = 0;"); |
| - LibraryElement libraryElement = resolve2(librarySource); |
| + Source source = addSource("const int a = 0;"); |
| + LibraryElement libraryElement = resolve2(source); |
| CompilationUnit unit = |
| - analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| + analysisContext.resolveCompilationUnit(source, libraryElement); |
| expect(unit, isNotNull); |
| ConstantValueComputer computer = _makeConstantValueComputer(); |
| - computer.add(unit, librarySource, librarySource); |
| + computer.add(unit, source, source); |
| computer.computeValues(); |
| NodeList<CompilationUnitMember> members = unit.declarations; |
| expect(members, hasLength(1)); |
| @@ -947,16 +954,16 @@ const int d = c;'''); |
| } |
| void test_computeValues_value_depends_on_enum() { |
| - Source librarySource = addSource(''' |
| + Source source = addSource(''' |
| enum E { id0, id1 } |
| const E e = E.id0; |
| '''); |
| - LibraryElement libraryElement = resolve2(librarySource); |
| + LibraryElement libraryElement = resolve2(source); |
| CompilationUnit unit = |
| - analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
| + analysisContext.resolveCompilationUnit(source, libraryElement); |
| expect(unit, isNotNull); |
| ConstantValueComputer computer = _makeConstantValueComputer(); |
| - computer.add(unit, librarySource, librarySource); |
| + computer.add(unit, source, source); |
| computer.computeValues(); |
| TopLevelVariableDeclaration declaration = unit.declarations |
| .firstWhere((member) => member is TopLevelVariableDeclaration); |
| @@ -1963,7 +1970,7 @@ class A { |
| ConstantValueComputer _makeConstantValueComputer() { |
| ConstantEvaluationValidator_ForTest validator = |
| - new ConstantEvaluationValidator_ForTest(); |
| + new ConstantEvaluationValidator_ForTest(analysisContext2); |
| validator.computer = new ConstantValueComputer( |
| analysisContext2, |
| analysisContext2.typeProvider, |