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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1289283004: Initial steps toward adding strong mode to the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 runReflectiveTests(ResolveVariableReferencesTaskTest); 55 runReflectiveTests(ResolveVariableReferencesTaskTest);
56 runReflectiveTests(ScanDartTaskTest); 56 runReflectiveTests(ScanDartTaskTest);
57 runReflectiveTests(VerifyUnitTaskTest); 57 runReflectiveTests(VerifyUnitTaskTest);
58 } 58 }
59 59
60 @reflectiveTest 60 @reflectiveTest
61 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { 61 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest {
62 Source source; 62 Source source;
63 LibrarySpecificUnit target; 63 LibrarySpecificUnit target;
64 64
65 /**
66 * Enable strong mode in the current analysis context.
67 */
68 void enableStrongMode() {
69 AnalysisOptionsImpl options = context.analysisOptions;
70 options.strongMode = true;
71 context.analysisOptions = options;
72 }
73
65 test_buildInputs() { 74 test_buildInputs() {
66 LibrarySpecificUnit target = 75 LibrarySpecificUnit target =
67 new LibrarySpecificUnit(emptySource, emptySource); 76 new LibrarySpecificUnit(emptySource, emptySource);
68 Map<String, TaskInput> inputs = 77 Map<String, TaskInput> inputs =
69 BuildCompilationUnitElementTask.buildInputs(target); 78 BuildCompilationUnitElementTask.buildInputs(target);
70 expect(inputs, isNotNull); 79 expect(inputs, isNotNull);
71 expect( 80 expect(
72 inputs.keys, 81 inputs.keys,
73 unorderedEquals( 82 unorderedEquals(
74 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); 83 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME]));
(...skipping 19 matching lines...) Expand all
94 BuildCompilationUnitElementTask task = 103 BuildCompilationUnitElementTask task =
95 new BuildCompilationUnitElementTask(null, emptySource); 104 new BuildCompilationUnitElementTask(null, emptySource);
96 expect(task.description, isNotNull); 105 expect(task.description, isNotNull);
97 } 106 }
98 107
99 test_descriptor() { 108 test_descriptor() {
100 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR; 109 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR;
101 expect(descriptor, isNotNull); 110 expect(descriptor, isNotNull);
102 } 111 }
103 112
104 test_perform_find_constants() { 113 test_perform_find_constants_strong() {
114 enableStrongMode();
105 _performBuildTask(''' 115 _performBuildTask('''
106 const x = 1; 116 const x = 1;
107 class C { 117 class C {
108 static const y = 1; 118 static const y = 1;
109 const C([p = 1]); 119 const C([p = 1]);
110 } 120 }
111 @x 121 @x
112 f() { 122 f() {
113 const z = 1; 123 const z = 1;
114 } 124 }
115 '''); 125 ''');
116 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 126 CompilationUnit unit = outputs[RESOLVED_UNIT1];
117 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; 127 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT];
118 Annotation annotation = unit.declarations 128 Annotation annotation = unit.declarations
119 .firstWhere((m) => m is FunctionDeclaration) 129 .firstWhere((m) => m is FunctionDeclaration)
120 .metadata[0]; 130 .metadata[0];
121 List<ConstantEvaluationTarget> expectedConstants = [ 131 List<ConstantEvaluationTarget> expectedConstants = [
122 unitElement.accessors.firstWhere((e) => e.isGetter).variable, 132 unitElement.accessors.firstWhere((e) => e.isGetter).variable,
123 unitElement.types[0].fields[0], 133 unitElement.types[0].fields[0],
124 unitElement.functions[0].localVariables[0], 134 unitElement.functions[0].localVariables[0],
125 unitElement.types[0].constructors[0], 135 unitElement.types[0].constructors[0],
126 new ConstantEvaluationTarget_Annotation( 136 new ConstantEvaluationTarget_Annotation(
127 context, source, source, annotation), 137 context, source, source, annotation),
128 unitElement.types[0].constructors[0].parameters[0] 138 unitElement.types[0].constructors[0].parameters[0]
129 ]; 139 ];
140 expect(outputs[CLASSES_IN_UNIT], hasLength(1));
130 expect( 141 expect(
131 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet()); 142 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet());
143 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(2));
132 } 144 }
133 145
134 test_perform_library() { 146 test_perform_find_constants_weak() {
147 _performBuildTask('''
148 const x = 1;
149 class C {
150 static const y = 1;
151 const C([p = 1]);
152 }
153 @x
154 f() {
155 const z = 1;
156 }
157 ''');
158 CompilationUnit unit = outputs[RESOLVED_UNIT1];
159 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT];
160 Annotation annotation = unit.declarations
161 .firstWhere((m) => m is FunctionDeclaration)
162 .metadata[0];
163 List<ConstantEvaluationTarget> expectedConstants = [
164 unitElement.accessors.firstWhere((e) => e.isGetter).variable,
165 unitElement.types[0].fields[0],
166 unitElement.functions[0].localVariables[0],
167 unitElement.types[0].constructors[0],
168 new ConstantEvaluationTarget_Annotation(
169 context, source, source, annotation),
170 unitElement.types[0].constructors[0].parameters[0]
171 ];
172 expect(outputs[CLASSES_IN_UNIT], hasLength(0));
173 expect(
174 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet());
175 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0));
176 }
177
178 test_perform_library_strong() {
179 enableStrongMode();
135 _performBuildTask(r''' 180 _performBuildTask(r'''
136 library lib; 181 library lib;
137 import 'lib2.dart'; 182 import 'lib2.dart';
138 export 'lib3.dart'; 183 export 'lib3.dart';
139 part 'part.dart'; 184 part 'part.dart';
140 class A {} 185 final x = '';
186 class A {
187 static final y = 0;
188 }
141 class B = Object with A; 189 class B = Object with A;
142 '''); 190 ''');
143 expect(outputs, hasLength(3)); 191 expect(outputs, hasLength(5));
192 expect(outputs[CLASSES_IN_UNIT], hasLength(2));
193 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull);
144 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); 194 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull);
195 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(2));
145 expect(outputs[RESOLVED_UNIT1], isNotNull); 196 expect(outputs[RESOLVED_UNIT1], isNotNull);
197 }
198
199 test_perform_library_weak() {
200 _performBuildTask(r'''
201 library lib;
202 import 'lib2.dart';
203 export 'lib3.dart';
204 part 'part.dart';
205 final x = '';
206 class A {
207 static final y = 0;
208 }
209 class B = Object with A;
210 ''');
211 expect(outputs, hasLength(5));
212 expect(outputs[CLASSES_IN_UNIT], hasLength(0));
146 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull); 213 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull);
214 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull);
215 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0));
216 expect(outputs[RESOLVED_UNIT1], isNotNull);
147 } 217 }
148 218
149 test_perform_reuseElement() { 219 test_perform_reuseElement() {
150 _performBuildTask(r''' 220 _performBuildTask(r'''
151 library lib; 221 library lib;
152 class A {} 222 class A {}
153 class B = Object with A; 223 class B = Object with A;
154 '''); 224 ''');
155 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 225 CompilationUnit unit = outputs[RESOLVED_UNIT1];
156 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; 226 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT];
(...skipping 2610 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 /** 2837 /**
2768 * Fill [errorListener] with [result] errors in the current [task]. 2838 * Fill [errorListener] with [result] errors in the current [task].
2769 */ 2839 */
2770 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 2840 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
2771 List<AnalysisError> errors = task.outputs[result]; 2841 List<AnalysisError> errors = task.outputs[result];
2772 expect(errors, isNotNull, reason: result.name); 2842 expect(errors, isNotNull, reason: result.name);
2773 errorListener = new GatheringErrorListener(); 2843 errorListener = new GatheringErrorListener();
2774 errorListener.addAll(errors); 2844 errorListener.addAll(errors);
2775 } 2845 }
2776 } 2846 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698