| OLD | NEW |
| 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/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | 156 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); |
| 157 _fillErrorListener(CONSTRUCTORS_ERRORS); | 157 _fillErrorListener(CONSTRUCTORS_ERRORS); |
| 158 errorListener.assertErrorsWithCodes( | 158 errorListener.assertErrorsWithCodes( |
| 159 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 159 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 @reflectiveTest | 163 @reflectiveTest |
| 164 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 164 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 165 test_buildInputs() { | 165 test_buildInputs() { |
| 166 LibraryUnitTarget target = new LibraryUnitTarget(emptySource, emptySource); | 166 LibrarySpecificUnit target = new LibrarySpecificUnit(emptySource, emptySourc
e); |
| 167 Map<String, TaskInput> inputs = | 167 Map<String, TaskInput> inputs = |
| 168 BuildCompilationUnitElementTask.buildInputs(target); | 168 BuildCompilationUnitElementTask.buildInputs(target); |
| 169 expect(inputs, isNotNull); | 169 expect(inputs, isNotNull); |
| 170 expect(inputs.keys, unorderedEquals( | 170 expect(inputs.keys, unorderedEquals( |
| 171 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); | 171 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); |
| 172 } | 172 } |
| 173 | 173 |
| 174 test_constructor() { | 174 test_constructor() { |
| 175 BuildCompilationUnitElementTask task = | 175 BuildCompilationUnitElementTask task = |
| 176 new BuildCompilationUnitElementTask(context, emptySource); | 176 new BuildCompilationUnitElementTask(context, emptySource); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 class B = Object with A; | 208 class B = Object with A; |
| 209 '''); | 209 '''); |
| 210 expect(outputs, hasLength(3)); | 210 expect(outputs, hasLength(3)); |
| 211 expect(outputs[CLASS_ELEMENTS], hasLength(2)); | 211 expect(outputs[CLASS_ELEMENTS], hasLength(2)); |
| 212 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 212 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 213 expect(outputs[RESOLVED_UNIT1], isNotNull); | 213 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void _performBuildTask(String content) { | 216 void _performBuildTask(String content) { |
| 217 Source source = _newSource('/test.dart', content); | 217 Source source = _newSource('/test.dart', content); |
| 218 AnalysisTarget target = new LibraryUnitTarget(source, source); | 218 AnalysisTarget target = new LibrarySpecificUnit(source, source); |
| 219 _computeResult(target, RESOLVED_UNIT1); | 219 _computeResult(target, RESOLVED_UNIT1); |
| 220 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); | 220 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 @reflectiveTest | 224 @reflectiveTest |
| 225 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 225 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 226 test_constructor() { | 226 test_constructor() { |
| 227 BuildDirectiveElementsTask task = | 227 BuildDirectiveElementsTask task = |
| 228 new BuildDirectiveElementsTask(context, emptySource); | 228 new BuildDirectiveElementsTask(context, emptySource); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 _computeResult(sourceA, LIBRARY_ELEMENT2); | 271 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 272 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 272 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 273 // prepare outputs | 273 // prepare outputs |
| 274 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; | 274 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; |
| 275 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); | 275 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); |
| 276 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); | 276 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); |
| 277 // no errors | 277 // no errors |
| 278 _assertErrorsWithCodes([]); | 278 _assertErrorsWithCodes([]); |
| 279 // validate directives | 279 // validate directives |
| 280 CompilationUnit libraryUnitA = context | 280 CompilationUnit libraryUnitA = context |
| 281 .getCacheEntry(new LibraryUnitTarget(sourceA, sourceA)) | 281 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
| 282 .getValue(RESOLVED_UNIT1); | 282 .getValue(RESOLVED_UNIT1); |
| 283 { | 283 { |
| 284 ImportDirective importNode = libraryUnitA.directives[1]; | 284 ImportDirective importNode = libraryUnitA.directives[1]; |
| 285 ImportElement importElement = importNode.element; | 285 ImportElement importElement = importNode.element; |
| 286 expect(importElement, isNotNull); | 286 expect(importElement, isNotNull); |
| 287 expect(importElement.importedLibrary, libraryElementB); | 287 expect(importElement.importedLibrary, libraryElementB); |
| 288 expect(importElement.prefix, isNull); | 288 expect(importElement.prefix, isNull); |
| 289 expect(importElement.nameOffset, 14); | 289 expect(importElement.nameOffset, 14); |
| 290 expect(importElement.uriOffset, 21); | 290 expect(importElement.uriOffset, 21); |
| 291 expect(importElement.uriEnd, 32); | 291 expect(importElement.uriEnd, 32); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 318 '/libB.dart': ''' | 318 '/libB.dart': ''' |
| 319 library libB; | 319 library libB; |
| 320 ''' | 320 ''' |
| 321 }); | 321 }); |
| 322 Source sourceA = sources[0]; | 322 Source sourceA = sources[0]; |
| 323 // perform task | 323 // perform task |
| 324 _computeResult(sourceA, LIBRARY_ELEMENT2); | 324 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 325 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 325 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 326 // prepare outputs | 326 // prepare outputs |
| 327 CompilationUnit libraryUnitA = context | 327 CompilationUnit libraryUnitA = context |
| 328 .getCacheEntry(new LibraryUnitTarget(sourceA, sourceA)) | 328 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
| 329 .getValue(RESOLVED_UNIT1); | 329 .getValue(RESOLVED_UNIT1); |
| 330 // no errors | 330 // no errors |
| 331 _assertErrorsWithCodes([]); | 331 _assertErrorsWithCodes([]); |
| 332 // validate directives | 332 // validate directives |
| 333 ImportDirective importNode = libraryUnitA.directives[1]; | 333 ImportDirective importNode = libraryUnitA.directives[1]; |
| 334 ImportElement importElement = importNode.element; | 334 ImportElement importElement = importNode.element; |
| 335 List<NamespaceCombinator> combinators = importElement.combinators; | 335 List<NamespaceCombinator> combinators = importElement.combinators; |
| 336 expect(combinators, hasLength(2)); | 336 expect(combinators, hasLength(2)); |
| 337 { | 337 { |
| 338 ShowElementCombinator combinator = combinators[0]; | 338 ShowElementCombinator combinator = combinators[0]; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 library libC; | 411 library libC; |
| 412 ''' | 412 ''' |
| 413 }); | 413 }); |
| 414 Source sourceA = sources[0]; | 414 Source sourceA = sources[0]; |
| 415 Source sourceB = sources[1]; | 415 Source sourceB = sources[1]; |
| 416 // perform task | 416 // perform task |
| 417 _computeResult(sourceA, LIBRARY_ELEMENT2); | 417 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 418 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 418 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 419 // prepare outputs | 419 // prepare outputs |
| 420 CompilationUnit libraryUnitA = context | 420 CompilationUnit libraryUnitA = context |
| 421 .getCacheEntry(new LibraryUnitTarget(sourceA, sourceA)) | 421 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
| 422 .getValue(RESOLVED_UNIT1); | 422 .getValue(RESOLVED_UNIT1); |
| 423 // validate directives | 423 // validate directives |
| 424 { | 424 { |
| 425 ImportDirective importNodeB = libraryUnitA.directives[1]; | 425 ImportDirective importNodeB = libraryUnitA.directives[1]; |
| 426 SimpleIdentifier prefixNodeB = importNodeB.prefix; | 426 SimpleIdentifier prefixNodeB = importNodeB.prefix; |
| 427 ImportElement importElementB = importNodeB.element; | 427 ImportElement importElementB = importNodeB.element; |
| 428 PrefixElement prefixElement = importElementB.prefix; | 428 PrefixElement prefixElement = importElementB.prefix; |
| 429 expect(importElementB, isNotNull); | 429 expect(importElementB, isNotNull); |
| 430 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); | 430 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); |
| 431 expect(prefixElement, isNotNull); | 431 expect(prefixElement, isNotNull); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 457 } | 457 } |
| 458 | 458 |
| 459 @reflectiveTest | 459 @reflectiveTest |
| 460 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { | 460 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { |
| 461 test_perform() { | 461 test_perform() { |
| 462 Source source = _newSource('/test.dart', ''' | 462 Source source = _newSource('/test.dart', ''' |
| 463 enum MyEnum { | 463 enum MyEnum { |
| 464 A, B | 464 A, B |
| 465 } | 465 } |
| 466 '''); | 466 '''); |
| 467 _computeResult(new LibraryUnitTarget(source, source), RESOLVED_UNIT2); | 467 _computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2); |
| 468 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); | 468 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); |
| 469 CompilationUnit unit = outputs[RESOLVED_UNIT2]; | 469 CompilationUnit unit = outputs[RESOLVED_UNIT2]; |
| 470 // validate Element | 470 // validate Element |
| 471 ClassElement enumElement = unit.element.getEnum('MyEnum'); | 471 ClassElement enumElement = unit.element.getEnum('MyEnum'); |
| 472 List<FieldElement> fields = enumElement.fields; | 472 List<FieldElement> fields = enumElement.fields; |
| 473 expect(fields, hasLength(4)); | 473 expect(fields, hasLength(4)); |
| 474 { | 474 { |
| 475 FieldElementImpl index = fields[0]; | 475 FieldElementImpl index = fields[0]; |
| 476 expect(index, isNotNull); | 476 expect(index, isNotNull); |
| 477 expect(index.name, 'index'); | 477 expect(index.name, 'index'); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 | 621 |
| 622 @reflectiveTest | 622 @reflectiveTest |
| 623 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { | 623 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { |
| 624 test_perform() { | 624 test_perform() { |
| 625 Source source = _newSource('/test.dart', ''' | 625 Source source = _newSource('/test.dart', ''' |
| 626 typedef int F(G g); | 626 typedef int F(G g); |
| 627 typedef String G(int p); | 627 typedef String G(int p); |
| 628 '''); | 628 '''); |
| 629 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 629 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 630 _computeResult(target, RESOLVED_UNIT3); | 630 _computeResult(target, RESOLVED_UNIT3); |
| 631 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | 631 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); |
| 632 // validate | 632 // validate |
| 633 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 633 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 634 FunctionTypeAlias nodeF = unit.declarations[0]; | 634 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 635 FunctionTypeAlias nodeG = unit.declarations[1]; | 635 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 636 { | 636 { |
| 637 FormalParameter parameter = nodeF.parameters.parameters[0]; | 637 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 638 DartType parameterType = parameter.element.type; | 638 DartType parameterType = parameter.element.type; |
| 639 Element returnTypeElement = nodeF.returnType.type.element; | 639 Element returnTypeElement = nodeF.returnType.type.element; |
| 640 expect(returnTypeElement.displayName, 'int'); | 640 expect(returnTypeElement.displayName, 'int'); |
| 641 expect(parameterType.element, nodeG.element); | 641 expect(parameterType.element, nodeG.element); |
| 642 } | 642 } |
| 643 { | 643 { |
| 644 FormalParameter parameter = nodeG.parameters.parameters[0]; | 644 FormalParameter parameter = nodeG.parameters.parameters[0]; |
| 645 DartType parameterType = parameter.element.type; | 645 DartType parameterType = parameter.element.type; |
| 646 expect(nodeG.returnType.type.element.displayName, 'String'); | 646 expect(nodeG.returnType.type.element.displayName, 'String'); |
| 647 expect(parameterType.element.displayName, 'int'); | 647 expect(parameterType.element.displayName, 'int'); |
| 648 } | 648 } |
| 649 } | 649 } |
| 650 | 650 |
| 651 test_perform_errors() { | 651 test_perform_errors() { |
| 652 Source source = _newSource('/test.dart', ''' | 652 Source source = _newSource('/test.dart', ''' |
| 653 typedef int F(NoSuchType p); | 653 typedef int F(NoSuchType p); |
| 654 '''); | 654 '''); |
| 655 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 655 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 656 _computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS); | 656 _computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS); |
| 657 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | 657 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); |
| 658 // validate | 658 // validate |
| 659 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS); | 659 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS); |
| 660 errorListener | 660 errorListener |
| 661 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 661 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 662 } | 662 } |
| 663 } | 663 } |
| 664 | 664 |
| 665 @reflectiveTest | 665 @reflectiveTest |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 _fillErrorListener(BUILD_LIBRARY_ERRORS); | 934 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 935 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 935 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 936 } | 936 } |
| 937 | 937 |
| 938 void _performBuildTask(Map<String, String> sourceMap) { | 938 void _performBuildTask(Map<String, String> sourceMap) { |
| 939 List<Source> sources = _newSources(sourceMap); | 939 List<Source> sources = _newSources(sourceMap); |
| 940 Source libSource = sources.first; | 940 Source libSource = sources.first; |
| 941 _computeResult(libSource, LIBRARY_ELEMENT1); | 941 _computeResult(libSource, LIBRARY_ELEMENT1); |
| 942 expect(task, new isInstanceOf<BuildLibraryElementTask>()); | 942 expect(task, new isInstanceOf<BuildLibraryElementTask>()); |
| 943 libraryUnit = context | 943 libraryUnit = context |
| 944 .getCacheEntry(new LibraryUnitTarget(libSource, libSource)) | 944 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) |
| 945 .getValue(RESOLVED_UNIT1); | 945 .getValue(RESOLVED_UNIT1); |
| 946 libraryUnitElement = libraryUnit.element; | 946 libraryUnitElement = libraryUnit.element; |
| 947 librarySource = libraryUnitElement.source; | 947 librarySource = libraryUnitElement.source; |
| 948 libraryElement = outputs[LIBRARY_ELEMENT1]; | 948 libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 949 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; | 949 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; |
| 950 } | 950 } |
| 951 } | 951 } |
| 952 | 952 |
| 953 @reflectiveTest | 953 @reflectiveTest |
| 954 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { | 954 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 import 'b.dart'; | 1169 import 'b.dart'; |
| 1170 main() { | 1170 main() { |
| 1171 new A(); | 1171 new A(); |
| 1172 }'''); | 1172 }'''); |
| 1173 _computeUsedElements(source); | 1173 _computeUsedElements(source); |
| 1174 // validate | 1174 // validate |
| 1175 expect(usedElementNames, unorderedEquals(['A'])); | 1175 expect(usedElementNames, unorderedEquals(['A'])); |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 void _computeUsedElements(Source source) { | 1178 void _computeUsedElements(Source source) { |
| 1179 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1179 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1180 _computeResult(target, USED_IMPORTED_ELEMENTS); | 1180 _computeResult(target, USED_IMPORTED_ELEMENTS); |
| 1181 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); | 1181 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); |
| 1182 usedElements = outputs[USED_IMPORTED_ELEMENTS]; | 1182 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
| 1183 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1183 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1184 } | 1184 } |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 @reflectiveTest | 1187 @reflectiveTest |
| 1188 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { | 1188 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { |
| 1189 UsedLocalElements usedElements; | 1189 UsedLocalElements usedElements; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1213 p._m3(); | 1213 p._m3(); |
| 1214 } | 1214 } |
| 1215 '''); | 1215 '''); |
| 1216 _computeUsedElements(source); | 1216 _computeUsedElements(source); |
| 1217 // validate | 1217 // validate |
| 1218 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); | 1218 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); |
| 1219 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); | 1219 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 void _computeUsedElements(Source source) { | 1222 void _computeUsedElements(Source source) { |
| 1223 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1223 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1224 _computeResult(target, USED_LOCAL_ELEMENTS); | 1224 _computeResult(target, USED_LOCAL_ELEMENTS); |
| 1225 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>()); | 1225 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>()); |
| 1226 usedElements = outputs[USED_LOCAL_ELEMENTS]; | 1226 usedElements = outputs[USED_LOCAL_ELEMENTS]; |
| 1227 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1227 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1228 } | 1228 } |
| 1229 } | 1229 } |
| 1230 | 1230 |
| 1231 @reflectiveTest | 1231 @reflectiveTest |
| 1232 class GenerateHintsTaskTest extends _AbstractDartTaskTest { | 1232 class GenerateHintsTaskTest extends _AbstractDartTaskTest { |
| 1233 test_perform_bestPractices_missingReturn() { | 1233 test_perform_bestPractices_missingReturn() { |
| 1234 Source source = _newSource('/test.dart', ''' | 1234 Source source = _newSource('/test.dart', ''' |
| 1235 int main() { | 1235 int main() { |
| 1236 } | 1236 } |
| 1237 '''); | 1237 '''); |
| 1238 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1238 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1239 _computeResult(target, HINTS); | 1239 _computeResult(target, HINTS); |
| 1240 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1240 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1241 // validate | 1241 // validate |
| 1242 _fillErrorListener(HINTS); | 1242 _fillErrorListener(HINTS); |
| 1243 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); | 1243 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); |
| 1244 } | 1244 } |
| 1245 | 1245 |
| 1246 test_perform_dart2js() { | 1246 test_perform_dart2js() { |
| 1247 Source source = _newSource('/test.dart', ''' | 1247 Source source = _newSource('/test.dart', ''' |
| 1248 main(p) { | 1248 main(p) { |
| 1249 if (p is double) { | 1249 if (p is double) { |
| 1250 print('double'); | 1250 print('double'); |
| 1251 } | 1251 } |
| 1252 } | 1252 } |
| 1253 '''); | 1253 '''); |
| 1254 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1254 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1255 _computeResult(target, HINTS); | 1255 _computeResult(target, HINTS); |
| 1256 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1256 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1257 // validate | 1257 // validate |
| 1258 _fillErrorListener(HINTS); | 1258 _fillErrorListener(HINTS); |
| 1259 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); | 1259 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); |
| 1260 } | 1260 } |
| 1261 | 1261 |
| 1262 test_perform_deadCode() { | 1262 test_perform_deadCode() { |
| 1263 Source source = _newSource('/test.dart', ''' | 1263 Source source = _newSource('/test.dart', ''' |
| 1264 main() { | 1264 main() { |
| 1265 if (false) { | 1265 if (false) { |
| 1266 print('how?'); | 1266 print('how?'); |
| 1267 } | 1267 } |
| 1268 } | 1268 } |
| 1269 '''); | 1269 '''); |
| 1270 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1270 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1271 _computeResult(target, HINTS); | 1271 _computeResult(target, HINTS); |
| 1272 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1272 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1273 // validate | 1273 // validate |
| 1274 _fillErrorListener(HINTS); | 1274 _fillErrorListener(HINTS); |
| 1275 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); | 1275 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); |
| 1276 } | 1276 } |
| 1277 | 1277 |
| 1278 test_perform_imports_duplicateImport() { | 1278 test_perform_imports_duplicateImport() { |
| 1279 _newSource('/a.dart', r''' | 1279 _newSource('/a.dart', r''' |
| 1280 library lib_a; | 1280 library lib_a; |
| 1281 class A {} | 1281 class A {} |
| 1282 '''); | 1282 '''); |
| 1283 Source source = _newSource('/test.dart', r''' | 1283 Source source = _newSource('/test.dart', r''' |
| 1284 import 'a.dart'; | 1284 import 'a.dart'; |
| 1285 import 'a.dart'; | 1285 import 'a.dart'; |
| 1286 main() { | 1286 main() { |
| 1287 new A(); | 1287 new A(); |
| 1288 } | 1288 } |
| 1289 '''); | 1289 '''); |
| 1290 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1290 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1291 _computeResult(target, HINTS); | 1291 _computeResult(target, HINTS); |
| 1292 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1292 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1293 // validate | 1293 // validate |
| 1294 _fillErrorListener(HINTS); | 1294 _fillErrorListener(HINTS); |
| 1295 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); | 1295 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 test_perform_imports_unusedImport_one() { | 1298 test_perform_imports_unusedImport_one() { |
| 1299 _newSource('/a.dart', r''' | 1299 _newSource('/a.dart', r''' |
| 1300 library lib_a; | 1300 library lib_a; |
| 1301 class A {} | 1301 class A {} |
| 1302 '''); | 1302 '''); |
| 1303 _newSource('/b.dart', r''' | 1303 _newSource('/b.dart', r''' |
| 1304 library lib_b; | 1304 library lib_b; |
| 1305 class B {} | 1305 class B {} |
| 1306 '''); | 1306 '''); |
| 1307 Source source = _newSource('/test.dart', r''' | 1307 Source source = _newSource('/test.dart', r''' |
| 1308 import 'a.dart'; | 1308 import 'a.dart'; |
| 1309 import 'b.dart'; | 1309 import 'b.dart'; |
| 1310 main() { | 1310 main() { |
| 1311 new A(); | 1311 new A(); |
| 1312 }'''); | 1312 }'''); |
| 1313 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1313 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1314 _computeResult(target, HINTS); | 1314 _computeResult(target, HINTS); |
| 1315 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1315 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1316 // validate | 1316 // validate |
| 1317 _fillErrorListener(HINTS); | 1317 _fillErrorListener(HINTS); |
| 1318 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); | 1318 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); |
| 1319 } | 1319 } |
| 1320 | 1320 |
| 1321 test_perform_imports_unusedImport_zero() { | 1321 test_perform_imports_unusedImport_zero() { |
| 1322 _newSource('/a.dart', r''' | 1322 _newSource('/a.dart', r''' |
| 1323 library lib_a; | 1323 library lib_a; |
| 1324 class A {} | 1324 class A {} |
| 1325 '''); | 1325 '''); |
| 1326 Source source = _newSource('/test.dart', r''' | 1326 Source source = _newSource('/test.dart', r''' |
| 1327 import 'a.dart'; | 1327 import 'a.dart'; |
| 1328 main() { | 1328 main() { |
| 1329 new A(); | 1329 new A(); |
| 1330 }'''); | 1330 }'''); |
| 1331 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1331 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1332 _computeResult(target, HINTS); | 1332 _computeResult(target, HINTS); |
| 1333 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1333 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1334 // validate | 1334 // validate |
| 1335 _fillErrorListener(HINTS); | 1335 _fillErrorListener(HINTS); |
| 1336 errorListener.assertNoErrors(); | 1336 errorListener.assertNoErrors(); |
| 1337 } | 1337 } |
| 1338 | 1338 |
| 1339 test_perform_overrideVerifier() { | 1339 test_perform_overrideVerifier() { |
| 1340 Source source = _newSource('/test.dart', ''' | 1340 Source source = _newSource('/test.dart', ''' |
| 1341 class A {} | 1341 class A {} |
| 1342 class B { | 1342 class B { |
| 1343 @override | 1343 @override |
| 1344 m() {} | 1344 m() {} |
| 1345 } | 1345 } |
| 1346 '''); | 1346 '''); |
| 1347 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1347 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1348 _computeResult(target, HINTS); | 1348 _computeResult(target, HINTS); |
| 1349 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1349 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1350 // validate | 1350 // validate |
| 1351 _fillErrorListener(HINTS); | 1351 _fillErrorListener(HINTS); |
| 1352 errorListener.assertErrorsWithCodes( | 1352 errorListener.assertErrorsWithCodes( |
| 1353 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); | 1353 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); |
| 1354 } | 1354 } |
| 1355 | 1355 |
| 1356 test_perform_todo() { | 1356 test_perform_todo() { |
| 1357 Source source = _newSource('/test.dart', ''' | 1357 Source source = _newSource('/test.dart', ''' |
| 1358 main() { | 1358 main() { |
| 1359 // TODO(developer) foo bar | 1359 // TODO(developer) foo bar |
| 1360 } | 1360 } |
| 1361 '''); | 1361 '''); |
| 1362 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1362 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1363 _computeResult(target, HINTS); | 1363 _computeResult(target, HINTS); |
| 1364 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1364 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1365 // validate | 1365 // validate |
| 1366 _fillErrorListener(HINTS); | 1366 _fillErrorListener(HINTS); |
| 1367 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); | 1367 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 test_perform_unusedLocalElements_class() { | 1370 test_perform_unusedLocalElements_class() { |
| 1371 Source source = _newSource('/test.dart', ''' | 1371 Source source = _newSource('/test.dart', ''' |
| 1372 class _A {} | 1372 class _A {} |
| 1373 class _B {} | 1373 class _B {} |
| 1374 main() { | 1374 main() { |
| 1375 new _A(); | 1375 new _A(); |
| 1376 } | 1376 } |
| 1377 '''); | 1377 '''); |
| 1378 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1378 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1379 _computeResult(target, HINTS); | 1379 _computeResult(target, HINTS); |
| 1380 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1380 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1381 // validate | 1381 // validate |
| 1382 _fillErrorListener(HINTS); | 1382 _fillErrorListener(HINTS); |
| 1383 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); | 1383 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 test_perform_unusedLocalElements_localVariable() { | 1386 test_perform_unusedLocalElements_localVariable() { |
| 1387 Source source = _newSource('/test.dart', ''' | 1387 Source source = _newSource('/test.dart', ''' |
| 1388 main() { | 1388 main() { |
| 1389 var v = 42; | 1389 var v = 42; |
| 1390 } | 1390 } |
| 1391 '''); | 1391 '''); |
| 1392 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1392 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1393 _computeResult(target, HINTS); | 1393 _computeResult(target, HINTS); |
| 1394 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1394 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1395 // validate | 1395 // validate |
| 1396 _fillErrorListener(HINTS); | 1396 _fillErrorListener(HINTS); |
| 1397 errorListener | 1397 errorListener |
| 1398 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); | 1398 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 test_perform_unusedLocalElements_method() { | 1401 test_perform_unusedLocalElements_method() { |
| 1402 Source source = _newSource('/my_lib.dart', ''' | 1402 Source source = _newSource('/my_lib.dart', ''' |
| 1403 library my_lib; | 1403 library my_lib; |
| 1404 part 'my_part.dart'; | 1404 part 'my_part.dart'; |
| 1405 class A { | 1405 class A { |
| 1406 _ma() {} | 1406 _ma() {} |
| 1407 _mb() {} | 1407 _mb() {} |
| 1408 _mc() {} | 1408 _mc() {} |
| 1409 } | 1409 } |
| 1410 '''); | 1410 '''); |
| 1411 _newSource('/my_part.dart', ''' | 1411 _newSource('/my_part.dart', ''' |
| 1412 part of my_lib; | 1412 part of my_lib; |
| 1413 | 1413 |
| 1414 f(A a) { | 1414 f(A a) { |
| 1415 a._mb(); | 1415 a._mb(); |
| 1416 } | 1416 } |
| 1417 '''); | 1417 '''); |
| 1418 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1418 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1419 _computeResult(target, HINTS); | 1419 _computeResult(target, HINTS); |
| 1420 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1420 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1421 // validate | 1421 // validate |
| 1422 _fillErrorListener(HINTS); | 1422 _fillErrorListener(HINTS); |
| 1423 errorListener.assertErrorsWithCodes( | 1423 errorListener.assertErrorsWithCodes( |
| 1424 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); | 1424 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); |
| 1425 } | 1425 } |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 @reflectiveTest | 1428 @reflectiveTest |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 class ResolveReferencesTaskTest extends _AbstractDartTaskTest { | 1594 class ResolveReferencesTaskTest extends _AbstractDartTaskTest { |
| 1595 test_perform() { | 1595 test_perform() { |
| 1596 Source source = _newSource('/test.dart', ''' | 1596 Source source = _newSource('/test.dart', ''' |
| 1597 class A { | 1597 class A { |
| 1598 m() {} | 1598 m() {} |
| 1599 } | 1599 } |
| 1600 main(A a) { | 1600 main(A a) { |
| 1601 a.m(); | 1601 a.m(); |
| 1602 } | 1602 } |
| 1603 '''); | 1603 '''); |
| 1604 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1604 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1605 // prepare unit and "a.m()" invocation | 1605 // prepare unit and "a.m()" invocation |
| 1606 CompilationUnit unit; | 1606 CompilationUnit unit; |
| 1607 MethodInvocation invocation; | 1607 MethodInvocation invocation; |
| 1608 { | 1608 { |
| 1609 _computeResult(target, RESOLVED_UNIT1); | 1609 _computeResult(target, RESOLVED_UNIT1); |
| 1610 unit = outputs[RESOLVED_UNIT1]; | 1610 unit = outputs[RESOLVED_UNIT1]; |
| 1611 // walk the AST | 1611 // walk the AST |
| 1612 FunctionDeclaration function = unit.declarations[1]; | 1612 FunctionDeclaration function = unit.declarations[1]; |
| 1613 BlockFunctionBody body = function.functionExpression.body; | 1613 BlockFunctionBody body = function.functionExpression.body; |
| 1614 ExpressionStatement statement = body.block.statements[0]; | 1614 ExpressionStatement statement = body.block.statements[0]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1627 } | 1627 } |
| 1628 | 1628 |
| 1629 test_perform_errors() { | 1629 test_perform_errors() { |
| 1630 Source source = _newSource('/test.dart', ''' | 1630 Source source = _newSource('/test.dart', ''' |
| 1631 class A { | 1631 class A { |
| 1632 } | 1632 } |
| 1633 main(A a) { | 1633 main(A a) { |
| 1634 a.unknownMethod(); | 1634 a.unknownMethod(); |
| 1635 } | 1635 } |
| 1636 '''); | 1636 '''); |
| 1637 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1637 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1638 _computeResult(target, RESOLVED_UNIT); | 1638 _computeResult(target, RESOLVED_UNIT); |
| 1639 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 1639 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 1640 // validate | 1640 // validate |
| 1641 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | 1641 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
| 1642 errorListener.assertErrorsWithCodes( | 1642 errorListener.assertErrorsWithCodes( |
| 1643 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | 1643 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 1644 } | 1644 } |
| 1645 } | 1645 } |
| 1646 | 1646 |
| 1647 @reflectiveTest | 1647 @reflectiveTest |
| 1648 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 1648 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 1649 test_perform() { | 1649 test_perform() { |
| 1650 Source source = _newSource('/test.dart', ''' | 1650 Source source = _newSource('/test.dart', ''' |
| 1651 class A {} | 1651 class A {} |
| 1652 class B extends A {} | 1652 class B extends A {} |
| 1653 int f(String p) => p.length; | 1653 int f(String p) => p.length; |
| 1654 '''); | 1654 '''); |
| 1655 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1655 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1656 _computeResult(target, RESOLVED_UNIT4); | 1656 _computeResult(target, RESOLVED_UNIT4); |
| 1657 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1657 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1658 // validate | 1658 // validate |
| 1659 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 1659 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 1660 { | 1660 { |
| 1661 ClassDeclaration nodeA = unit.declarations[0]; | 1661 ClassDeclaration nodeA = unit.declarations[0]; |
| 1662 ClassDeclaration nodeB = unit.declarations[1]; | 1662 ClassDeclaration nodeB = unit.declarations[1]; |
| 1663 DartType extendsType = nodeB.extendsClause.superclass.type; | 1663 DartType extendsType = nodeB.extendsClause.superclass.type; |
| 1664 expect(extendsType, nodeA.element.type); | 1664 expect(extendsType, nodeA.element.type); |
| 1665 } | 1665 } |
| 1666 { | 1666 { |
| 1667 FunctionDeclaration functionNode = unit.declarations[2]; | 1667 FunctionDeclaration functionNode = unit.declarations[2]; |
| 1668 DartType returnType = functionNode.returnType.type; | 1668 DartType returnType = functionNode.returnType.type; |
| 1669 List<FormalParameter> parameters = | 1669 List<FormalParameter> parameters = |
| 1670 functionNode.functionExpression.parameters.parameters; | 1670 functionNode.functionExpression.parameters.parameters; |
| 1671 expect(returnType.displayName, 'int'); | 1671 expect(returnType.displayName, 'int'); |
| 1672 expect(parameters[0].element.type.displayName, 'String'); | 1672 expect(parameters[0].element.type.displayName, 'String'); |
| 1673 } | 1673 } |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 test_perform_errors() { | 1676 test_perform_errors() { |
| 1677 Source source = _newSource('/test.dart', ''' | 1677 Source source = _newSource('/test.dart', ''' |
| 1678 NoSuchClass f() => null; | 1678 NoSuchClass f() => null; |
| 1679 '''); | 1679 '''); |
| 1680 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1680 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1681 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 1681 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); |
| 1682 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1682 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1683 // validate | 1683 // validate |
| 1684 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 1684 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 1685 errorListener | 1685 errorListener |
| 1686 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 1686 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 1687 } | 1687 } |
| 1688 } | 1688 } |
| 1689 | 1689 |
| 1690 @reflectiveTest | 1690 @reflectiveTest |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1707 var v3 = 1; | 1707 var v3 = 1; |
| 1708 var v4 = 1; | 1708 var v4 = 1; |
| 1709 v2 = 2; | 1709 v2 = 2; |
| 1710 v4 = 2; | 1710 v4 = 2; |
| 1711 localFunction() { | 1711 localFunction() { |
| 1712 v3 = 3; | 1712 v3 = 3; |
| 1713 v4 = 3; | 1713 v4 = 3; |
| 1714 } | 1714 } |
| 1715 } | 1715 } |
| 1716 '''); | 1716 '''); |
| 1717 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1717 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1718 _computeResult(target, RESOLVED_UNIT5); | 1718 _computeResult(target, RESOLVED_UNIT5); |
| 1719 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 1719 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1720 // validate | 1720 // validate |
| 1721 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1721 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1722 FunctionElement main = unit.element.functions[0]; | 1722 FunctionElement main = unit.element.functions[0]; |
| 1723 expectMutated(main.localVariables[0], isFalse, isFalse); | 1723 expectMutated(main.localVariables[0], isFalse, isFalse); |
| 1724 expectMutated(main.localVariables[1], isFalse, isTrue); | 1724 expectMutated(main.localVariables[1], isFalse, isTrue); |
| 1725 expectMutated(main.localVariables[2], isTrue, isTrue); | 1725 expectMutated(main.localVariables[2], isTrue, isTrue); |
| 1726 expectMutated(main.localVariables[3], isTrue, isTrue); | 1726 expectMutated(main.localVariables[3], isTrue, isTrue); |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 test_perform_parameter() { | 1729 test_perform_parameter() { |
| 1730 Source source = _newSource('/test.dart', ''' | 1730 Source source = _newSource('/test.dart', ''' |
| 1731 main(p1, p2, p3, p4) { | 1731 main(p1, p2, p3, p4) { |
| 1732 p2 = 2; | 1732 p2 = 2; |
| 1733 p4 = 2; | 1733 p4 = 2; |
| 1734 localFunction() { | 1734 localFunction() { |
| 1735 p3 = 3; | 1735 p3 = 3; |
| 1736 p4 = 3; | 1736 p4 = 3; |
| 1737 } | 1737 } |
| 1738 } | 1738 } |
| 1739 '''); | 1739 '''); |
| 1740 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1740 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1741 _computeResult(target, RESOLVED_UNIT5); | 1741 _computeResult(target, RESOLVED_UNIT5); |
| 1742 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 1742 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1743 // validate | 1743 // validate |
| 1744 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1744 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1745 FunctionElement main = unit.element.functions[0]; | 1745 FunctionElement main = unit.element.functions[0]; |
| 1746 expectMutated(main.parameters[0], isFalse, isFalse); | 1746 expectMutated(main.parameters[0], isFalse, isFalse); |
| 1747 expectMutated(main.parameters[1], isFalse, isTrue); | 1747 expectMutated(main.parameters[1], isFalse, isTrue); |
| 1748 expectMutated(main.parameters[2], isTrue, isTrue); | 1748 expectMutated(main.parameters[2], isTrue, isTrue); |
| 1749 expectMutated(main.parameters[3], isTrue, isTrue); | 1749 expectMutated(main.parameters[3], isTrue, isTrue); |
| 1750 } | 1750 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 @reflectiveTest | 1808 @reflectiveTest |
| 1809 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 1809 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 1810 test_perform_verifyError() { | 1810 test_perform_verifyError() { |
| 1811 Source source = _newSource('/test.dart', ''' | 1811 Source source = _newSource('/test.dart', ''' |
| 1812 main() { | 1812 main() { |
| 1813 if (42) { | 1813 if (42) { |
| 1814 print('Not bool!'); | 1814 print('Not bool!'); |
| 1815 } | 1815 } |
| 1816 } | 1816 } |
| 1817 '''); | 1817 '''); |
| 1818 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1818 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1819 _computeResult(target, VERIFY_ERRORS); | 1819 _computeResult(target, VERIFY_ERRORS); |
| 1820 expect(task, new isInstanceOf<VerifyUnitTask>()); | 1820 expect(task, new isInstanceOf<VerifyUnitTask>()); |
| 1821 // validate | 1821 // validate |
| 1822 _fillErrorListener(VERIFY_ERRORS); | 1822 _fillErrorListener(VERIFY_ERRORS); |
| 1823 errorListener.assertErrorsWithCodes( | 1823 errorListener.assertErrorsWithCodes( |
| 1824 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); | 1824 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); |
| 1825 } | 1825 } |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 class _AbstractDartTaskTest extends EngineTestCase { | 1828 class _AbstractDartTaskTest extends EngineTestCase { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1926 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1927 } | 1927 } |
| 1928 | 1928 |
| 1929 TimestampedData<String> getContents(Source source) => source.contents; | 1929 TimestampedData<String> getContents(Source source) => source.contents; |
| 1930 | 1930 |
| 1931 noSuchMethod(Invocation invocation) { | 1931 noSuchMethod(Invocation invocation) { |
| 1932 print('noSuchMethod: ${invocation.memberName}'); | 1932 print('noSuchMethod: ${invocation.memberName}'); |
| 1933 return super.noSuchMethod(invocation); | 1933 return super.noSuchMethod(invocation); |
| 1934 } | 1934 } |
| 1935 } | 1935 } |
| OLD | NEW |