| 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'; | |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | |
| 9 import 'package:analyzer/src/context/cache.dart'; | |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart' | |
| 13 hide AnalysisTask, GetContentTask, ParseDartTask, ScanDartTask; | |
| 14 import 'package:analyzer/src/generated/error.dart'; | 9 import 'package:analyzer/src/generated/error.dart'; |
| 15 import 'package:analyzer/src/generated/resolver.dart'; | 10 import 'package:analyzer/src/generated/resolver.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | |
| 17 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/plugin/engine_plugin.dart'; | |
| 19 import 'package:analyzer/src/task/dart.dart'; | 12 import 'package:analyzer/src/task/dart.dart'; |
| 20 import 'package:analyzer/src/task/driver.dart'; | |
| 21 import 'package:analyzer/src/task/manager.dart'; | |
| 22 import 'package:analyzer/task/dart.dart'; | 13 import 'package:analyzer/task/dart.dart'; |
| 23 import 'package:analyzer/task/general.dart'; | 14 import 'package:analyzer/task/general.dart'; |
| 24 import 'package:analyzer/task/model.dart'; | 15 import 'package:analyzer/task/model.dart'; |
| 25 import 'package:plugin/manager.dart'; | |
| 26 import 'package:typed_mock/typed_mock.dart'; | |
| 27 import 'package:unittest/unittest.dart'; | 16 import 'package:unittest/unittest.dart'; |
| 28 | 17 |
| 29 import '../../generated/test_support.dart'; | 18 import '../../generated/test_support.dart'; |
| 30 import '../../reflective_tests.dart'; | 19 import '../../reflective_tests.dart'; |
| 31 import '../mock_sdk.dart'; | 20 import '../context/abstract_context_test.dart'; |
| 32 | 21 |
| 33 main() { | 22 main() { |
| 34 groupSep = ' | '; | 23 groupSep = ' | '; |
| 35 runReflectiveTests(BuildClassConstructorsTaskTest); | 24 runReflectiveTests(BuildClassConstructorsTaskTest); |
| 36 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 25 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 37 runReflectiveTests(BuildDirectiveElementsTaskTest); | 26 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 38 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 27 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 39 runReflectiveTests(BuildSourceClosuresTaskTest); | 28 runReflectiveTests(BuildSourceClosuresTaskTest); |
| 40 runReflectiveTests(BuildExportNamespaceTaskTest); | 29 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 41 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); | 30 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); |
| 42 runReflectiveTests(BuildLibraryConstructorsTaskTest); | 31 runReflectiveTests(BuildLibraryConstructorsTaskTest); |
| 43 runReflectiveTests(BuildLibraryElementTaskTest); | 32 runReflectiveTests(BuildLibraryElementTaskTest); |
| 44 runReflectiveTests(BuildPublicNamespaceTaskTest); | 33 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 45 runReflectiveTests(BuildTypeProviderTaskTest); | 34 runReflectiveTests(BuildTypeProviderTaskTest); |
| 46 runReflectiveTests(GatherUsedImportedElementsTaskTest); | 35 runReflectiveTests(GatherUsedImportedElementsTaskTest); |
| 47 runReflectiveTests(GatherUsedLocalElementsTaskTest); | 36 runReflectiveTests(GatherUsedLocalElementsTaskTest); |
| 48 runReflectiveTests(GenerateHintsTaskTest); | 37 runReflectiveTests(GenerateHintsTaskTest); |
| 49 runReflectiveTests(ParseDartTaskTest); | 38 runReflectiveTests(ParseDartTaskTest); |
| 50 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 39 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 51 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 40 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 52 runReflectiveTests(ResolveReferencesTaskTest); | 41 runReflectiveTests(ResolveReferencesTaskTest); |
| 53 runReflectiveTests(ResolveVariableReferencesTaskTest); | 42 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 54 runReflectiveTests(ScanDartTaskTest); | 43 runReflectiveTests(ScanDartTaskTest); |
| 55 runReflectiveTests(VerifyUnitTaskTest); | 44 runReflectiveTests(VerifyUnitTaskTest); |
| 56 } | 45 } |
| 57 | 46 |
| 58 @reflectiveTest | 47 @reflectiveTest |
| 59 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { | 48 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { |
| 60 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { | 49 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { |
| 61 Source source = _newSource('/test.dart', ''' | 50 Source source = newSource('/test.dart', ''' |
| 62 class B { | 51 class B { |
| 63 B({x}); | 52 B({x}); |
| 64 } | 53 } |
| 65 class M {} | 54 class M {} |
| 66 class C extends B with M {} | 55 class C extends B with M {} |
| 67 '''); | 56 '''); |
| 68 LibraryElement libraryElement; | 57 LibraryElement libraryElement; |
| 69 { | 58 { |
| 70 _computeResult(source, LIBRARY_ELEMENT5); | 59 _computeResult(source, LIBRARY_ELEMENT5); |
| 71 libraryElement = outputs[LIBRARY_ELEMENT5]; | 60 libraryElement = outputs[LIBRARY_ELEMENT5]; |
| 72 } | 61 } |
| 73 // prepare C | 62 // prepare C |
| 74 ClassElement c = libraryElement.getType('C'); | 63 ClassElement c = libraryElement.getType('C'); |
| 75 expect(c, isNotNull); | 64 expect(c, isNotNull); |
| 76 // build constructors | 65 // build constructors |
| 77 _computeResult(c, CONSTRUCTORS); | 66 _computeResult(c, CONSTRUCTORS); |
| 78 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | 67 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); |
| 79 _fillErrorListener(CONSTRUCTORS_ERRORS); | 68 _fillErrorListener(CONSTRUCTORS_ERRORS); |
| 80 errorListener.assertErrorsWithCodes( | 69 errorListener.assertErrorsWithCodes( |
| 81 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 70 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
| 82 } | 71 } |
| 83 | 72 |
| 84 test_perform_ClassDeclaration_explicitConstructors() { | 73 test_perform_ClassDeclaration_explicitConstructors() { |
| 85 Source source = _newSource('/test.dart', ''' | 74 Source source = newSource('/test.dart', ''' |
| 86 class B { | 75 class B { |
| 87 B(p); | 76 B(p); |
| 88 } | 77 } |
| 89 class C extends B { | 78 class C extends B { |
| 90 C(int a, String b) {} | 79 C(int a, String b) {} |
| 91 } | 80 } |
| 92 '''); | 81 '''); |
| 93 LibraryElement libraryElement; | 82 LibraryElement libraryElement; |
| 94 { | 83 { |
| 95 _computeResult(source, LIBRARY_ELEMENT5); | 84 _computeResult(source, LIBRARY_ELEMENT5); |
| 96 libraryElement = outputs[LIBRARY_ELEMENT5]; | 85 libraryElement = outputs[LIBRARY_ELEMENT5]; |
| 97 } | 86 } |
| 98 // prepare C | 87 // prepare C |
| 99 ClassElement c = libraryElement.getType('C'); | 88 ClassElement c = libraryElement.getType('C'); |
| 100 expect(c, isNotNull); | 89 expect(c, isNotNull); |
| 101 // build constructors | 90 // build constructors |
| 102 _computeResult(c, CONSTRUCTORS); | 91 _computeResult(c, CONSTRUCTORS); |
| 103 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | 92 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); |
| 104 // no errors | 93 // no errors |
| 105 expect(outputs[CONSTRUCTORS_ERRORS], isEmpty); | 94 expect(outputs[CONSTRUCTORS_ERRORS], isEmpty); |
| 106 // explicit constructor | 95 // explicit constructor |
| 107 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; | 96 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; |
| 108 expect(constructors, hasLength(1)); | 97 expect(constructors, hasLength(1)); |
| 109 expect(constructors[0].parameters, hasLength(2)); | 98 expect(constructors[0].parameters, hasLength(2)); |
| 110 } | 99 } |
| 111 | 100 |
| 112 test_perform_ClassTypeAlias() { | 101 test_perform_ClassTypeAlias() { |
| 113 Source source = _newSource('/test.dart', ''' | 102 Source source = newSource('/test.dart', ''' |
| 114 class B { | 103 class B { |
| 115 B(int i); | 104 B(int i); |
| 116 } | 105 } |
| 117 class M1 {} | 106 class M1 {} |
| 118 class M2 {} | 107 class M2 {} |
| 119 | 108 |
| 120 class C2 = C1 with M2; | 109 class C2 = C1 with M2; |
| 121 class C1 = B with M1; | 110 class C1 = B with M1; |
| 122 '''); | 111 '''); |
| 123 LibraryElement libraryElement; | 112 LibraryElement libraryElement; |
| 124 { | 113 { |
| 125 _computeResult(source, LIBRARY_ELEMENT5); | 114 _computeResult(source, LIBRARY_ELEMENT5); |
| 126 libraryElement = outputs[LIBRARY_ELEMENT5]; | 115 libraryElement = outputs[LIBRARY_ELEMENT5]; |
| 127 } | 116 } |
| 128 // prepare C2 | 117 // prepare C2 |
| 129 ClassElement class2 = libraryElement.getType('C2'); | 118 ClassElement class2 = libraryElement.getType('C2'); |
| 130 expect(class2, isNotNull); | 119 expect(class2, isNotNull); |
| 131 // build constructors | 120 // build constructors |
| 132 _computeResult(class2, CONSTRUCTORS); | 121 _computeResult(class2, CONSTRUCTORS); |
| 133 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | 122 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); |
| 134 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; | 123 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; |
| 135 expect(constructors, hasLength(1)); | 124 expect(constructors, hasLength(1)); |
| 136 expect(constructors[0].parameters, hasLength(1)); | 125 expect(constructors[0].parameters, hasLength(1)); |
| 137 } | 126 } |
| 138 | 127 |
| 139 test_perform_ClassTypeAlias_errors_mixinHasNoConstructors() { | 128 test_perform_ClassTypeAlias_errors_mixinHasNoConstructors() { |
| 140 Source source = _newSource('/test.dart', ''' | 129 Source source = newSource('/test.dart', ''' |
| 141 class B { | 130 class B { |
| 142 B({x}); | 131 B({x}); |
| 143 } | 132 } |
| 144 class M {} | 133 class M {} |
| 145 class C = B with M; | 134 class C = B with M; |
| 146 '''); | 135 '''); |
| 147 LibraryElement libraryElement; | 136 LibraryElement libraryElement; |
| 148 { | 137 { |
| 149 _computeResult(source, LIBRARY_ELEMENT5); | 138 _computeResult(source, LIBRARY_ELEMENT5); |
| 150 libraryElement = outputs[LIBRARY_ELEMENT5]; | 139 libraryElement = outputs[LIBRARY_ELEMENT5]; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 class A {} | 198 class A {} |
| 210 class B = Object with A; | 199 class B = Object with A; |
| 211 '''); | 200 '''); |
| 212 expect(outputs, hasLength(3)); | 201 expect(outputs, hasLength(3)); |
| 213 expect(outputs[CLASS_ELEMENTS], hasLength(2)); | 202 expect(outputs[CLASS_ELEMENTS], hasLength(2)); |
| 214 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 203 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 215 expect(outputs[RESOLVED_UNIT1], isNotNull); | 204 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 216 } | 205 } |
| 217 | 206 |
| 218 void _performBuildTask(String content) { | 207 void _performBuildTask(String content) { |
| 219 Source source = _newSource('/test.dart', content); | 208 Source source = newSource('/test.dart', content); |
| 220 AnalysisTarget target = new LibrarySpecificUnit(source, source); | 209 AnalysisTarget target = new LibrarySpecificUnit(source, source); |
| 221 _computeResult(target, RESOLVED_UNIT1); | 210 _computeResult(target, RESOLVED_UNIT1); |
| 222 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); | 211 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); |
| 223 } | 212 } |
| 224 } | 213 } |
| 225 | 214 |
| 226 @reflectiveTest | 215 @reflectiveTest |
| 227 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 216 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 228 test_constructor() { | 217 test_constructor() { |
| 229 BuildDirectiveElementsTask task = | 218 BuildDirectiveElementsTask task = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 246 new BuildDirectiveElementsTask(null, emptySource); | 235 new BuildDirectiveElementsTask(null, emptySource); |
| 247 expect(task.description, isNotNull); | 236 expect(task.description, isNotNull); |
| 248 } | 237 } |
| 249 | 238 |
| 250 test_descriptor() { | 239 test_descriptor() { |
| 251 TaskDescriptor descriptor = BuildDirectiveElementsTask.DESCRIPTOR; | 240 TaskDescriptor descriptor = BuildDirectiveElementsTask.DESCRIPTOR; |
| 252 expect(descriptor, isNotNull); | 241 expect(descriptor, isNotNull); |
| 253 } | 242 } |
| 254 | 243 |
| 255 test_perform() { | 244 test_perform() { |
| 256 List<Source> sources = _newSources({ | 245 List<Source> sources = newSources({ |
| 257 '/libA.dart': ''' | 246 '/libA.dart': ''' |
| 258 library libA; | 247 library libA; |
| 259 import 'libB.dart'; | 248 import 'libB.dart'; |
| 260 export 'libC.dart'; | 249 export 'libC.dart'; |
| 261 ''', | 250 ''', |
| 262 '/libB.dart': ''' | 251 '/libB.dart': ''' |
| 263 library libB; | 252 library libB; |
| 264 ''', | 253 ''', |
| 265 '/libC.dart': ''' | 254 '/libC.dart': ''' |
| 266 library libC; | 255 library libC; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 expect(libraryElementA.hasExtUri, isFalse); | 294 expect(libraryElementA.hasExtUri, isFalse); |
| 306 // has an artificial "dart:core" import | 295 // has an artificial "dart:core" import |
| 307 { | 296 { |
| 308 List<ImportElement> imports = libraryElementA.imports; | 297 List<ImportElement> imports = libraryElementA.imports; |
| 309 expect(imports, hasLength(2)); | 298 expect(imports, hasLength(2)); |
| 310 expect(imports[1].importedLibrary.isDartCore, isTrue); | 299 expect(imports[1].importedLibrary.isDartCore, isTrue); |
| 311 } | 300 } |
| 312 } | 301 } |
| 313 | 302 |
| 314 test_perform_combinators() { | 303 test_perform_combinators() { |
| 315 List<Source> sources = _newSources({ | 304 List<Source> sources = newSources({ |
| 316 '/libA.dart': ''' | 305 '/libA.dart': ''' |
| 317 library libA; | 306 library libA; |
| 318 import 'libB.dart' show A, B hide C, D; | 307 import 'libB.dart' show A, B hide C, D; |
| 319 ''', | 308 ''', |
| 320 '/libB.dart': ''' | 309 '/libB.dart': ''' |
| 321 library libB; | 310 library libB; |
| 322 ''' | 311 ''' |
| 323 }); | 312 }); |
| 324 Source sourceA = sources[0]; | 313 Source sourceA = sources[0]; |
| 325 // perform task | 314 // perform task |
| (...skipping 16 matching lines...) Expand all Loading... |
| 342 expect(combinator.end, 42); | 331 expect(combinator.end, 42); |
| 343 expect(combinator.shownNames, ['A', 'B']); | 332 expect(combinator.shownNames, ['A', 'B']); |
| 344 } | 333 } |
| 345 { | 334 { |
| 346 HideElementCombinator combinator = combinators[1]; | 335 HideElementCombinator combinator = combinators[1]; |
| 347 expect(combinator.hiddenNames, ['C', 'D']); | 336 expect(combinator.hiddenNames, ['C', 'D']); |
| 348 } | 337 } |
| 349 } | 338 } |
| 350 | 339 |
| 351 test_perform_error_exportOfNonLibrary() { | 340 test_perform_error_exportOfNonLibrary() { |
| 352 List<Source> sources = _newSources({ | 341 List<Source> sources = newSources({ |
| 353 '/libA.dart': ''' | 342 '/libA.dart': ''' |
| 354 library libA; | 343 library libA; |
| 355 export 'part.dart'; | 344 export 'part.dart'; |
| 356 ''', | 345 ''', |
| 357 '/part.dart': ''' | 346 '/part.dart': ''' |
| 358 part of notLib; | 347 part of notLib; |
| 359 ''' | 348 ''' |
| 360 }); | 349 }); |
| 361 Source sourceA = sources[0]; | 350 Source sourceA = sources[0]; |
| 362 // perform task | 351 // perform task |
| 363 _computeResult(sourceA, LIBRARY_ELEMENT2); | 352 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 364 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 353 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 365 // validate errors | 354 // validate errors |
| 366 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); | 355 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
| 367 } | 356 } |
| 368 | 357 |
| 369 test_perform_error_importOfNonLibrary() { | 358 test_perform_error_importOfNonLibrary() { |
| 370 List<Source> sources = _newSources({ | 359 List<Source> sources = newSources({ |
| 371 '/libA.dart': ''' | 360 '/libA.dart': ''' |
| 372 library libA; | 361 library libA; |
| 373 import 'part.dart'; | 362 import 'part.dart'; |
| 374 ''', | 363 ''', |
| 375 '/part.dart': ''' | 364 '/part.dart': ''' |
| 376 part of notLib; | 365 part of notLib; |
| 377 ''' | 366 ''' |
| 378 }); | 367 }); |
| 379 Source sourceA = sources[0]; | 368 Source sourceA = sources[0]; |
| 380 // perform task | 369 // perform task |
| 381 _computeResult(sourceA, LIBRARY_ELEMENT2); | 370 _computeResult(sourceA, LIBRARY_ELEMENT2); |
| 382 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 371 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 383 // validate errors | 372 // validate errors |
| 384 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); | 373 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 385 } | 374 } |
| 386 | 375 |
| 387 test_perform_hasExtUri() { | 376 test_perform_hasExtUri() { |
| 388 List<Source> sources = _newSources({ | 377 List<Source> sources = newSources({ |
| 389 '/lib.dart': ''' | 378 '/lib.dart': ''' |
| 390 import 'dart-ext:doesNotExist.dart'; | 379 import 'dart-ext:doesNotExist.dart'; |
| 391 ''' | 380 ''' |
| 392 }); | 381 }); |
| 393 Source source = sources[0]; | 382 Source source = sources[0]; |
| 394 // perform task | 383 // perform task |
| 395 _computeResult(source, LIBRARY_ELEMENT2); | 384 _computeResult(source, LIBRARY_ELEMENT2); |
| 396 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 385 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 397 // prepare outputs | 386 // prepare outputs |
| 398 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; | 387 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
| 399 expect(libraryElement.hasExtUri, isTrue); | 388 expect(libraryElement.hasExtUri, isTrue); |
| 400 } | 389 } |
| 401 | 390 |
| 402 test_perform_importPrefix() { | 391 test_perform_importPrefix() { |
| 403 List<Source> sources = _newSources({ | 392 List<Source> sources = newSources({ |
| 404 '/libA.dart': ''' | 393 '/libA.dart': ''' |
| 405 library libA; | 394 library libA; |
| 406 import 'libB.dart' as pref; | 395 import 'libB.dart' as pref; |
| 407 import 'libC.dart' as pref; | 396 import 'libC.dart' as pref; |
| 408 ''', | 397 ''', |
| 409 '/libB.dart': ''' | 398 '/libB.dart': ''' |
| 410 library libB; | 399 library libB; |
| 411 ''', | 400 ''', |
| 412 '/libC.dart': ''' | 401 '/libC.dart': ''' |
| 413 library libC; | 402 library libC; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 443 |
| 455 _getImportLibraryInput(Source source) { | 444 _getImportLibraryInput(Source source) { |
| 456 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 445 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 457 return task.inputs[key][source]; | 446 return task.inputs[key][source]; |
| 458 } | 447 } |
| 459 } | 448 } |
| 460 | 449 |
| 461 @reflectiveTest | 450 @reflectiveTest |
| 462 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { | 451 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { |
| 463 test_perform() { | 452 test_perform() { |
| 464 Source source = _newSource('/test.dart', ''' | 453 Source source = newSource('/test.dart', ''' |
| 465 enum MyEnum { | 454 enum MyEnum { |
| 466 A, B | 455 A, B |
| 467 } | 456 } |
| 468 '''); | 457 '''); |
| 469 _computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2); | 458 _computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2); |
| 470 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); | 459 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); |
| 471 CompilationUnit unit = outputs[RESOLVED_UNIT2]; | 460 CompilationUnit unit = outputs[RESOLVED_UNIT2]; |
| 472 // validate Element | 461 // validate Element |
| 473 ClassElement enumElement = unit.element.getEnum('MyEnum'); | 462 ClassElement enumElement = unit.element.getEnum('MyEnum'); |
| 474 List<FieldElement> fields = enumElement.fields; | 463 List<FieldElement> fields = enumElement.fields; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 PropertyAccessorElement getter = field.getter; | 505 PropertyAccessorElement getter = field.getter; |
| 517 expect(getter, isNotNull); | 506 expect(getter, isNotNull); |
| 518 expect(getter.variable, same(field)); | 507 expect(getter.variable, same(field)); |
| 519 expect(getter.type, isNotNull); | 508 expect(getter.type, isNotNull); |
| 520 } | 509 } |
| 521 } | 510 } |
| 522 | 511 |
| 523 @reflectiveTest | 512 @reflectiveTest |
| 524 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { | 513 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { |
| 525 test_perform_entryPoint() { | 514 test_perform_entryPoint() { |
| 526 Source sourceA = _newSource('/a.dart', ''' | 515 Source sourceA = newSource('/a.dart', ''' |
| 527 library lib_a; | 516 library lib_a; |
| 528 export 'b.dart'; | 517 export 'b.dart'; |
| 529 '''); | 518 '''); |
| 530 Source sourceB = _newSource('/b.dart', ''' | 519 Source sourceB = newSource('/b.dart', ''' |
| 531 library lib_b; | 520 library lib_b; |
| 532 main() {} | 521 main() {} |
| 533 '''); | 522 '''); |
| 534 _computeResult(sourceA, LIBRARY_ELEMENT4); | 523 _computeResult(sourceA, LIBRARY_ELEMENT4); |
| 535 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 524 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 536 // validate | 525 // validate |
| 537 { | 526 { |
| 538 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 527 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 539 FunctionElement entryPoint = library.entryPoint; | 528 FunctionElement entryPoint = library.entryPoint; |
| 540 expect(entryPoint, isNotNull); | 529 expect(entryPoint, isNotNull); |
| 541 expect(entryPoint.source, sourceB); | 530 expect(entryPoint.source, sourceB); |
| 542 } | 531 } |
| 543 } | 532 } |
| 544 | 533 |
| 545 test_perform_hideCombinator() { | 534 test_perform_hideCombinator() { |
| 546 Source sourceA = _newSource('/a.dart', ''' | 535 Source sourceA = newSource('/a.dart', ''' |
| 547 library lib_a; | 536 library lib_a; |
| 548 export 'b.dart' hide B1; | 537 export 'b.dart' hide B1; |
| 549 class A1 {} | 538 class A1 {} |
| 550 class A2 {} | 539 class A2 {} |
| 551 class _A3 {} | 540 class _A3 {} |
| 552 '''); | 541 '''); |
| 553 _newSource('/b.dart', ''' | 542 newSource('/b.dart', ''' |
| 554 library lib_b; | 543 library lib_b; |
| 555 class B1 {} | 544 class B1 {} |
| 556 class B2 {} | 545 class B2 {} |
| 557 class B3 {} | 546 class B3 {} |
| 558 class _B4 {} | 547 class _B4 {} |
| 559 '''); | 548 '''); |
| 560 _newSource('/c.dart', ''' | 549 newSource('/c.dart', ''' |
| 561 library lib_c; | 550 library lib_c; |
| 562 class C1 {} | 551 class C1 {} |
| 563 class C2 {} | 552 class C2 {} |
| 564 class C3 {} | 553 class C3 {} |
| 565 '''); | 554 '''); |
| 566 _computeResult(sourceA, LIBRARY_ELEMENT4); | 555 _computeResult(sourceA, LIBRARY_ELEMENT4); |
| 567 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 556 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 568 // validate | 557 // validate |
| 569 { | 558 { |
| 570 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 559 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 571 Namespace namespace = library.exportNamespace; | 560 Namespace namespace = library.exportNamespace; |
| 572 Iterable<String> definedKeys = namespace.definedNames.keys; | 561 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 573 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); | 562 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); |
| 574 } | 563 } |
| 575 } | 564 } |
| 576 | 565 |
| 577 test_perform_showCombinator() { | 566 test_perform_showCombinator() { |
| 578 Source sourceA = _newSource('/a.dart', ''' | 567 Source sourceA = newSource('/a.dart', ''' |
| 579 library lib_a; | 568 library lib_a; |
| 580 export 'b.dart' show B1; | 569 export 'b.dart' show B1; |
| 581 class A1 {} | 570 class A1 {} |
| 582 class A2 {} | 571 class A2 {} |
| 583 class _A3 {} | 572 class _A3 {} |
| 584 '''); | 573 '''); |
| 585 _newSource('/b.dart', ''' | 574 newSource('/b.dart', ''' |
| 586 library lib_b; | 575 library lib_b; |
| 587 class B1 {} | 576 class B1 {} |
| 588 class B2 {} | 577 class B2 {} |
| 589 class _B3 {} | 578 class _B3 {} |
| 590 '''); | 579 '''); |
| 591 _computeResult(sourceA, LIBRARY_ELEMENT4); | 580 _computeResult(sourceA, LIBRARY_ELEMENT4); |
| 592 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 581 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 593 // validate | 582 // validate |
| 594 { | 583 { |
| 595 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 584 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 596 Namespace namespace = library.exportNamespace; | 585 Namespace namespace = library.exportNamespace; |
| 597 Iterable<String> definedKeys = namespace.definedNames.keys; | 586 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 598 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); | 587 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); |
| 599 } | 588 } |
| 600 } | 589 } |
| 601 | 590 |
| 602 test_perform_showCombinator_setter() { | 591 test_perform_showCombinator_setter() { |
| 603 Source sourceA = _newSource('/a.dart', ''' | 592 Source sourceA = newSource('/a.dart', ''' |
| 604 library lib_a; | 593 library lib_a; |
| 605 export 'b.dart' show topLevelB; | 594 export 'b.dart' show topLevelB; |
| 606 class A {} | 595 class A {} |
| 607 '''); | 596 '''); |
| 608 _newSource('/b.dart', ''' | 597 newSource('/b.dart', ''' |
| 609 library lib_b; | 598 library lib_b; |
| 610 int topLevelB; | 599 int topLevelB; |
| 611 '''); | 600 '''); |
| 612 _computeResult(sourceA, LIBRARY_ELEMENT4); | 601 _computeResult(sourceA, LIBRARY_ELEMENT4); |
| 613 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 602 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 614 // validate | 603 // validate |
| 615 { | 604 { |
| 616 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 605 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 617 Namespace namespace = library.exportNamespace; | 606 Namespace namespace = library.exportNamespace; |
| 618 Iterable<String> definedKeys = namespace.definedNames.keys; | 607 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 619 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); | 608 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); |
| 620 } | 609 } |
| 621 } | 610 } |
| 622 } | 611 } |
| 623 | 612 |
| 624 @reflectiveTest | 613 @reflectiveTest |
| 625 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { | 614 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { |
| 626 test_perform() { | 615 test_perform() { |
| 627 Source source = _newSource('/test.dart', ''' | 616 Source source = newSource('/test.dart', ''' |
| 628 typedef int F(G g); | 617 typedef int F(G g); |
| 629 typedef String G(int p); | 618 typedef String G(int p); |
| 630 '''); | 619 '''); |
| 631 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 620 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 632 _computeResult(target, RESOLVED_UNIT3); | 621 _computeResult(target, RESOLVED_UNIT3); |
| 633 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | 622 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); |
| 634 // validate | 623 // validate |
| 635 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 624 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 636 FunctionTypeAlias nodeF = unit.declarations[0]; | 625 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 637 FunctionTypeAlias nodeG = unit.declarations[1]; | 626 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 638 { | 627 { |
| 639 FormalParameter parameter = nodeF.parameters.parameters[0]; | 628 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 640 DartType parameterType = parameter.element.type; | 629 DartType parameterType = parameter.element.type; |
| 641 Element returnTypeElement = nodeF.returnType.type.element; | 630 Element returnTypeElement = nodeF.returnType.type.element; |
| 642 expect(returnTypeElement.displayName, 'int'); | 631 expect(returnTypeElement.displayName, 'int'); |
| 643 expect(parameterType.element, nodeG.element); | 632 expect(parameterType.element, nodeG.element); |
| 644 } | 633 } |
| 645 { | 634 { |
| 646 FormalParameter parameter = nodeG.parameters.parameters[0]; | 635 FormalParameter parameter = nodeG.parameters.parameters[0]; |
| 647 DartType parameterType = parameter.element.type; | 636 DartType parameterType = parameter.element.type; |
| 648 expect(nodeG.returnType.type.element.displayName, 'String'); | 637 expect(nodeG.returnType.type.element.displayName, 'String'); |
| 649 expect(parameterType.element.displayName, 'int'); | 638 expect(parameterType.element.displayName, 'int'); |
| 650 } | 639 } |
| 651 } | 640 } |
| 652 | 641 |
| 653 test_perform_errors() { | 642 test_perform_errors() { |
| 654 Source source = _newSource('/test.dart', ''' | 643 Source source = newSource('/test.dart', ''' |
| 655 typedef int F(NoSuchType p); | 644 typedef int F(NoSuchType p); |
| 656 '''); | 645 '''); |
| 657 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 646 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 658 _computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS); | 647 _computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS); |
| 659 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | 648 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); |
| 660 // validate | 649 // validate |
| 661 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS); | 650 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS); |
| 662 errorListener | 651 errorListener |
| 663 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 652 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 664 } | 653 } |
| 665 } | 654 } |
| 666 | 655 |
| 667 @reflectiveTest | 656 @reflectiveTest |
| 668 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest { | 657 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest { |
| 669 test_perform() { | 658 test_perform() { |
| 670 Source source = _newSource('/test.dart', ''' | 659 Source source = newSource('/test.dart', ''' |
| 671 class B { | 660 class B { |
| 672 B(int i); | 661 B(int i); |
| 673 } | 662 } |
| 674 class M1 {} | 663 class M1 {} |
| 675 class M2 {} | 664 class M2 {} |
| 676 | 665 |
| 677 class C2 = C1 with M2; | 666 class C2 = C1 with M2; |
| 678 class C1 = B with M1; | 667 class C1 = B with M1; |
| 679 class C3 = B with M2; | 668 class C3 = B with M2; |
| 680 '''); | 669 '''); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 expect(unitElement1.topLevelVariables, [variable]); | 920 expect(unitElement1.topLevelVariables, [variable]); |
| 932 expect(unitElement2.topLevelVariables, [variable]); | 921 expect(unitElement2.topLevelVariables, [variable]); |
| 933 } | 922 } |
| 934 | 923 |
| 935 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 924 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 936 _fillErrorListener(BUILD_LIBRARY_ERRORS); | 925 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 937 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 926 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 938 } | 927 } |
| 939 | 928 |
| 940 void _performBuildTask(Map<String, String> sourceMap) { | 929 void _performBuildTask(Map<String, String> sourceMap) { |
| 941 List<Source> sources = _newSources(sourceMap); | 930 List<Source> sources = newSources(sourceMap); |
| 942 Source libSource = sources.first; | 931 Source libSource = sources.first; |
| 943 _computeResult(libSource, LIBRARY_ELEMENT1); | 932 _computeResult(libSource, LIBRARY_ELEMENT1); |
| 944 expect(task, new isInstanceOf<BuildLibraryElementTask>()); | 933 expect(task, new isInstanceOf<BuildLibraryElementTask>()); |
| 945 libraryUnit = context | 934 libraryUnit = context |
| 946 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) | 935 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) |
| 947 .getValue(RESOLVED_UNIT1); | 936 .getValue(RESOLVED_UNIT1); |
| 948 libraryUnitElement = libraryUnit.element; | 937 libraryUnitElement = libraryUnit.element; |
| 949 librarySource = libraryUnitElement.source; | 938 librarySource = libraryUnitElement.source; |
| 950 libraryElement = outputs[LIBRARY_ELEMENT1]; | 939 libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 951 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; | 940 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 new BuildPublicNamespaceTask(null, emptySource); | 972 new BuildPublicNamespaceTask(null, emptySource); |
| 984 expect(task.description, isNotNull); | 973 expect(task.description, isNotNull); |
| 985 } | 974 } |
| 986 | 975 |
| 987 test_descriptor() { | 976 test_descriptor() { |
| 988 TaskDescriptor descriptor = BuildPublicNamespaceTask.DESCRIPTOR; | 977 TaskDescriptor descriptor = BuildPublicNamespaceTask.DESCRIPTOR; |
| 989 expect(descriptor, isNotNull); | 978 expect(descriptor, isNotNull); |
| 990 } | 979 } |
| 991 | 980 |
| 992 test_perform() { | 981 test_perform() { |
| 993 List<Source> sources = _newSources({ | 982 List<Source> sources = newSources({ |
| 994 '/lib.dart': ''' | 983 '/lib.dart': ''' |
| 995 library lib; | 984 library lib; |
| 996 part 'part.dart'; | 985 part 'part.dart'; |
| 997 a() {} | 986 a() {} |
| 998 _b() {} | 987 _b() {} |
| 999 ''', | 988 ''', |
| 1000 '/part.dart': ''' | 989 '/part.dart': ''' |
| 1001 part of lib; | 990 part of lib; |
| 1002 _c() {} | 991 _c() {} |
| 1003 d() {} | 992 d() {} |
| 1004 ''' | 993 ''' |
| 1005 }); | 994 }); |
| 1006 _computeResult(sources.first, LIBRARY_ELEMENT3); | 995 _computeResult(sources.first, LIBRARY_ELEMENT3); |
| 1007 expect(task, new isInstanceOf<BuildPublicNamespaceTask>()); | 996 expect(task, new isInstanceOf<BuildPublicNamespaceTask>()); |
| 1008 // validate | 997 // validate |
| 1009 LibraryElement library = outputs[LIBRARY_ELEMENT3]; | 998 LibraryElement library = outputs[LIBRARY_ELEMENT3]; |
| 1010 Namespace namespace = library.publicNamespace; | 999 Namespace namespace = library.publicNamespace; |
| 1011 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); | 1000 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); |
| 1012 } | 1001 } |
| 1013 } | 1002 } |
| 1014 | 1003 |
| 1015 @reflectiveTest | 1004 @reflectiveTest |
| 1016 class BuildSourceClosuresTaskTest extends _AbstractDartTaskTest { | 1005 class BuildSourceClosuresTaskTest extends _AbstractDartTaskTest { |
| 1017 test_perform_exportClosure() { | 1006 test_perform_exportClosure() { |
| 1018 Source sourceA = _newSource('/a.dart', ''' | 1007 Source sourceA = newSource('/a.dart', ''' |
| 1019 library lib_a; | 1008 library lib_a; |
| 1020 export 'b.dart'; | 1009 export 'b.dart'; |
| 1021 '''); | 1010 '''); |
| 1022 Source sourceB = _newSource('/b.dart', ''' | 1011 Source sourceB = newSource('/b.dart', ''' |
| 1023 library lib_b; | 1012 library lib_b; |
| 1024 export 'c.dart'; | 1013 export 'c.dart'; |
| 1025 '''); | 1014 '''); |
| 1026 Source sourceC = _newSource('/c.dart', ''' | 1015 Source sourceC = newSource('/c.dart', ''' |
| 1027 library lib_c; | 1016 library lib_c; |
| 1028 export 'a.dart'; | 1017 export 'a.dart'; |
| 1029 '''); | 1018 '''); |
| 1030 Source sourceD = _newSource('/d.dart', ''' | 1019 Source sourceD = newSource('/d.dart', ''' |
| 1031 library lib_d; | 1020 library lib_d; |
| 1032 '''); | 1021 '''); |
| 1033 // a.dart | 1022 // a.dart |
| 1034 { | 1023 { |
| 1035 _computeResult(sourceA, EXPORT_SOURCE_CLOSURE); | 1024 _computeResult(sourceA, EXPORT_SOURCE_CLOSURE); |
| 1036 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1025 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1037 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1026 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; |
| 1038 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1027 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 1039 } | 1028 } |
| 1040 // c.dart | 1029 // c.dart |
| 1041 { | 1030 { |
| 1042 _computeResult(sourceC, EXPORT_SOURCE_CLOSURE); | 1031 _computeResult(sourceC, EXPORT_SOURCE_CLOSURE); |
| 1043 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1032 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1044 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1033 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; |
| 1045 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1034 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 1046 } | 1035 } |
| 1047 // d.dart | 1036 // d.dart |
| 1048 { | 1037 { |
| 1049 _computeResult(sourceD, EXPORT_SOURCE_CLOSURE); | 1038 _computeResult(sourceD, EXPORT_SOURCE_CLOSURE); |
| 1050 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1039 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1051 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1040 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; |
| 1052 expect(closure, unorderedEquals([sourceD])); | 1041 expect(closure, unorderedEquals([sourceD])); |
| 1053 } | 1042 } |
| 1054 } | 1043 } |
| 1055 | 1044 |
| 1056 test_perform_importClosure() { | 1045 test_perform_importClosure() { |
| 1057 Source sourceA = _newSource('/a.dart', ''' | 1046 Source sourceA = newSource('/a.dart', ''' |
| 1058 library lib_a; | 1047 library lib_a; |
| 1059 import 'b.dart'; | 1048 import 'b.dart'; |
| 1060 '''); | 1049 '''); |
| 1061 Source sourceB = _newSource('/b.dart', ''' | 1050 Source sourceB = newSource('/b.dart', ''' |
| 1062 library lib_b; | 1051 library lib_b; |
| 1063 import 'c.dart'; | 1052 import 'c.dart'; |
| 1064 '''); | 1053 '''); |
| 1065 Source sourceC = _newSource('/c.dart', ''' | 1054 Source sourceC = newSource('/c.dart', ''' |
| 1066 library lib_c; | 1055 library lib_c; |
| 1067 import 'a.dart'; | 1056 import 'a.dart'; |
| 1068 '''); | 1057 '''); |
| 1069 Source sourceD = _newSource('/d.dart', ''' | 1058 Source sourceD = newSource('/d.dart', ''' |
| 1070 library lib_d; | 1059 library lib_d; |
| 1071 '''); | 1060 '''); |
| 1072 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); | 1061 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); |
| 1073 // a.dart | 1062 // a.dart |
| 1074 { | 1063 { |
| 1075 _computeResult(sourceA, IMPORT_SOURCE_CLOSURE); | 1064 _computeResult(sourceA, IMPORT_SOURCE_CLOSURE); |
| 1076 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1065 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1077 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; | 1066 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; |
| 1078 expect(closure, contains(sourceA)); | 1067 expect(closure, contains(sourceA)); |
| 1079 expect(closure, contains(sourceB)); | 1068 expect(closure, contains(sourceB)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1094 { | 1083 { |
| 1095 _computeResult(sourceD, IMPORT_SOURCE_CLOSURE); | 1084 _computeResult(sourceD, IMPORT_SOURCE_CLOSURE); |
| 1096 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1085 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1097 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; | 1086 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; |
| 1098 expect(closure, contains(sourceD)); | 1087 expect(closure, contains(sourceD)); |
| 1099 expect(closure, contains(coreSource)); | 1088 expect(closure, contains(coreSource)); |
| 1100 } | 1089 } |
| 1101 } | 1090 } |
| 1102 | 1091 |
| 1103 test_perform_isClient_false() { | 1092 test_perform_isClient_false() { |
| 1104 Source sourceA = _newSource('/a.dart', ''' | 1093 Source sourceA = newSource('/a.dart', ''' |
| 1105 library lib_a; | 1094 library lib_a; |
| 1106 import 'b.dart'; | 1095 import 'b.dart'; |
| 1107 '''); | 1096 '''); |
| 1108 _newSource('/b.dart', ''' | 1097 newSource('/b.dart', ''' |
| 1109 library lib_b; | 1098 library lib_b; |
| 1110 '''); | 1099 '''); |
| 1111 _computeResult(sourceA, IS_CLIENT); | 1100 _computeResult(sourceA, IS_CLIENT); |
| 1112 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1101 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1113 expect(outputs[IS_CLIENT], isFalse); | 1102 expect(outputs[IS_CLIENT], isFalse); |
| 1114 } | 1103 } |
| 1115 | 1104 |
| 1116 test_perform_isClient_true_export_indirect() { | 1105 test_perform_isClient_true_export_indirect() { |
| 1117 _newSource('/exports_html.dart', ''' | 1106 newSource('/exports_html.dart', ''' |
| 1118 library lib_exports_html; | 1107 library lib_exports_html; |
| 1119 export 'dart:html'; | 1108 export 'dart:html'; |
| 1120 '''); | 1109 '''); |
| 1121 Source source = _newSource('/test.dart', ''' | 1110 Source source = newSource('/test.dart', ''' |
| 1122 import 'exports_html.dart'; | 1111 import 'exports_html.dart'; |
| 1123 '''); | 1112 '''); |
| 1124 _computeResult(source, IS_CLIENT); | 1113 _computeResult(source, IS_CLIENT); |
| 1125 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1114 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1126 expect(outputs[IS_CLIENT], isTrue); | 1115 expect(outputs[IS_CLIENT], isTrue); |
| 1127 } | 1116 } |
| 1128 | 1117 |
| 1129 test_perform_isClient_true_import_direct() { | 1118 test_perform_isClient_true_import_direct() { |
| 1130 Source sourceA = _newSource('/a.dart', ''' | 1119 Source sourceA = newSource('/a.dart', ''' |
| 1131 library lib_a; | 1120 library lib_a; |
| 1132 import 'dart:html'; | 1121 import 'dart:html'; |
| 1133 '''); | 1122 '''); |
| 1134 _computeResult(sourceA, IS_CLIENT); | 1123 _computeResult(sourceA, IS_CLIENT); |
| 1135 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1124 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1136 expect(outputs[IS_CLIENT], isTrue); | 1125 expect(outputs[IS_CLIENT], isTrue); |
| 1137 } | 1126 } |
| 1138 | 1127 |
| 1139 test_perform_isClient_true_import_indirect() { | 1128 test_perform_isClient_true_import_indirect() { |
| 1140 Source sourceA = _newSource('/a.dart', ''' | 1129 Source sourceA = newSource('/a.dart', ''' |
| 1141 library lib_a; | 1130 library lib_a; |
| 1142 import 'b.dart'; | 1131 import 'b.dart'; |
| 1143 '''); | 1132 '''); |
| 1144 _newSource('/b.dart', ''' | 1133 newSource('/b.dart', ''' |
| 1145 library lib_b; | 1134 library lib_b; |
| 1146 import 'dart:html'; | 1135 import 'dart:html'; |
| 1147 '''); | 1136 '''); |
| 1148 _computeResult(sourceA, IS_CLIENT); | 1137 _computeResult(sourceA, IS_CLIENT); |
| 1149 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1138 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1150 expect(outputs[IS_CLIENT], isTrue); | 1139 expect(outputs[IS_CLIENT], isTrue); |
| 1151 } | 1140 } |
| 1152 } | 1141 } |
| 1153 | 1142 |
| 1154 @reflectiveTest | 1143 @reflectiveTest |
| 1155 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { | 1144 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { |
| 1156 test_perform() { | 1145 test_perform() { |
| 1157 _computeResult(AnalysisContextTarget.request, TYPE_PROVIDER); | 1146 _computeResult(AnalysisContextTarget.request, TYPE_PROVIDER); |
| 1158 expect(task, new isInstanceOf<BuildTypeProviderTask>()); | 1147 expect(task, new isInstanceOf<BuildTypeProviderTask>()); |
| 1159 // validate | 1148 // validate |
| 1160 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; | 1149 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; |
| 1161 expect(typeProvider, isNotNull); | 1150 expect(typeProvider, isNotNull); |
| 1162 expect(typeProvider.boolType, isNotNull); | 1151 expect(typeProvider.boolType, isNotNull); |
| 1163 expect(typeProvider.intType, isNotNull); | 1152 expect(typeProvider.intType, isNotNull); |
| 1164 expect(typeProvider.futureType, isNotNull); | 1153 expect(typeProvider.futureType, isNotNull); |
| 1165 } | 1154 } |
| 1166 } | 1155 } |
| 1167 | 1156 |
| 1168 @reflectiveTest | 1157 @reflectiveTest |
| 1169 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { | 1158 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { |
| 1170 UsedImportedElements usedElements; | 1159 UsedImportedElements usedElements; |
| 1171 Set<String> usedElementNames; | 1160 Set<String> usedElementNames; |
| 1172 | 1161 |
| 1173 test_perform() { | 1162 test_perform() { |
| 1174 _newSource('/a.dart', r''' | 1163 newSource('/a.dart', r''' |
| 1175 library lib_a; | 1164 library lib_a; |
| 1176 class A {} | 1165 class A {} |
| 1177 '''); | 1166 '''); |
| 1178 _newSource('/b.dart', r''' | 1167 newSource('/b.dart', r''' |
| 1179 library lib_b; | 1168 library lib_b; |
| 1180 class B {} | 1169 class B {} |
| 1181 '''); | 1170 '''); |
| 1182 Source source = _newSource('/test.dart', r''' | 1171 Source source = newSource('/test.dart', r''' |
| 1183 import 'a.dart'; | 1172 import 'a.dart'; |
| 1184 import 'b.dart'; | 1173 import 'b.dart'; |
| 1185 main() { | 1174 main() { |
| 1186 new A(); | 1175 new A(); |
| 1187 }'''); | 1176 }'''); |
| 1188 _computeUsedElements(source); | 1177 _computeUsedElements(source); |
| 1189 // validate | 1178 // validate |
| 1190 expect(usedElementNames, unorderedEquals(['A'])); | 1179 expect(usedElementNames, unorderedEquals(['A'])); |
| 1191 } | 1180 } |
| 1192 | 1181 |
| 1193 void _computeUsedElements(Source source) { | 1182 void _computeUsedElements(Source source) { |
| 1194 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1183 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1195 _computeResult(target, USED_IMPORTED_ELEMENTS); | 1184 _computeResult(target, USED_IMPORTED_ELEMENTS); |
| 1196 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); | 1185 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); |
| 1197 usedElements = outputs[USED_IMPORTED_ELEMENTS]; | 1186 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
| 1198 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1187 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1199 } | 1188 } |
| 1200 } | 1189 } |
| 1201 | 1190 |
| 1202 @reflectiveTest | 1191 @reflectiveTest |
| 1203 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { | 1192 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { |
| 1204 UsedLocalElements usedElements; | 1193 UsedLocalElements usedElements; |
| 1205 Set<String> usedElementNames; | 1194 Set<String> usedElementNames; |
| 1206 | 1195 |
| 1207 test_perform_localVariable() { | 1196 test_perform_localVariable() { |
| 1208 Source source = _newSource('/test.dart', r''' | 1197 Source source = newSource('/test.dart', r''' |
| 1209 main() { | 1198 main() { |
| 1210 var v1 = 1; | 1199 var v1 = 1; |
| 1211 var v2 = 2; | 1200 var v2 = 2; |
| 1212 print(v2); | 1201 print(v2); |
| 1213 }'''); | 1202 }'''); |
| 1214 _computeUsedElements(source); | 1203 _computeUsedElements(source); |
| 1215 // validate | 1204 // validate |
| 1216 expect(usedElementNames, unorderedEquals(['v2'])); | 1205 expect(usedElementNames, unorderedEquals(['v2'])); |
| 1217 } | 1206 } |
| 1218 | 1207 |
| 1219 test_perform_method() { | 1208 test_perform_method() { |
| 1220 Source source = _newSource('/test.dart', r''' | 1209 Source source = newSource('/test.dart', r''' |
| 1221 class A { | 1210 class A { |
| 1222 _m1() {} | 1211 _m1() {} |
| 1223 _m2() {} | 1212 _m2() {} |
| 1224 } | 1213 } |
| 1225 | 1214 |
| 1226 main(A a, p) { | 1215 main(A a, p) { |
| 1227 a._m2(); | 1216 a._m2(); |
| 1228 p._m3(); | 1217 p._m3(); |
| 1229 } | 1218 } |
| 1230 '''); | 1219 '''); |
| 1231 _computeUsedElements(source); | 1220 _computeUsedElements(source); |
| 1232 // validate | 1221 // validate |
| 1233 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); | 1222 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); |
| 1234 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); | 1223 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); |
| 1235 } | 1224 } |
| 1236 | 1225 |
| 1237 void _computeUsedElements(Source source) { | 1226 void _computeUsedElements(Source source) { |
| 1238 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1227 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1239 _computeResult(target, USED_LOCAL_ELEMENTS); | 1228 _computeResult(target, USED_LOCAL_ELEMENTS); |
| 1240 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>()); | 1229 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>()); |
| 1241 usedElements = outputs[USED_LOCAL_ELEMENTS]; | 1230 usedElements = outputs[USED_LOCAL_ELEMENTS]; |
| 1242 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1231 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1243 } | 1232 } |
| 1244 } | 1233 } |
| 1245 | 1234 |
| 1246 @reflectiveTest | 1235 @reflectiveTest |
| 1247 class GenerateHintsTaskTest extends _AbstractDartTaskTest { | 1236 class GenerateHintsTaskTest extends _AbstractDartTaskTest { |
| 1248 test_perform_bestPractices_missingReturn() { | 1237 test_perform_bestPractices_missingReturn() { |
| 1249 Source source = _newSource('/test.dart', ''' | 1238 Source source = newSource('/test.dart', ''' |
| 1250 int main() { | 1239 int main() { |
| 1251 } | 1240 } |
| 1252 '''); | 1241 '''); |
| 1253 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1242 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1254 _computeResult(target, HINTS); | 1243 _computeResult(target, HINTS); |
| 1255 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1244 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1256 // validate | 1245 // validate |
| 1257 _fillErrorListener(HINTS); | 1246 _fillErrorListener(HINTS); |
| 1258 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); | 1247 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); |
| 1259 } | 1248 } |
| 1260 | 1249 |
| 1261 test_perform_dart2js() { | 1250 test_perform_dart2js() { |
| 1262 Source source = _newSource('/test.dart', ''' | 1251 Source source = newSource('/test.dart', ''' |
| 1263 main(p) { | 1252 main(p) { |
| 1264 if (p is double) { | 1253 if (p is double) { |
| 1265 print('double'); | 1254 print('double'); |
| 1266 } | 1255 } |
| 1267 } | 1256 } |
| 1268 '''); | 1257 '''); |
| 1269 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1258 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1270 _computeResult(target, HINTS); | 1259 _computeResult(target, HINTS); |
| 1271 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1260 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1272 // validate | 1261 // validate |
| 1273 _fillErrorListener(HINTS); | 1262 _fillErrorListener(HINTS); |
| 1274 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); | 1263 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); |
| 1275 } | 1264 } |
| 1276 | 1265 |
| 1277 test_perform_deadCode() { | 1266 test_perform_deadCode() { |
| 1278 Source source = _newSource('/test.dart', ''' | 1267 Source source = newSource('/test.dart', ''' |
| 1279 main() { | 1268 main() { |
| 1280 if (false) { | 1269 if (false) { |
| 1281 print('how?'); | 1270 print('how?'); |
| 1282 } | 1271 } |
| 1283 } | 1272 } |
| 1284 '''); | 1273 '''); |
| 1285 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1274 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1286 _computeResult(target, HINTS); | 1275 _computeResult(target, HINTS); |
| 1287 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1276 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1288 // validate | 1277 // validate |
| 1289 _fillErrorListener(HINTS); | 1278 _fillErrorListener(HINTS); |
| 1290 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); | 1279 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); |
| 1291 } | 1280 } |
| 1292 | 1281 |
| 1293 test_perform_imports_duplicateImport() { | 1282 test_perform_imports_duplicateImport() { |
| 1294 _newSource('/a.dart', r''' | 1283 newSource('/a.dart', r''' |
| 1295 library lib_a; | 1284 library lib_a; |
| 1296 class A {} | 1285 class A {} |
| 1297 '''); | 1286 '''); |
| 1298 Source source = _newSource('/test.dart', r''' | 1287 Source source = newSource('/test.dart', r''' |
| 1299 import 'a.dart'; | 1288 import 'a.dart'; |
| 1300 import 'a.dart'; | 1289 import 'a.dart'; |
| 1301 main() { | 1290 main() { |
| 1302 new A(); | 1291 new A(); |
| 1303 } | 1292 } |
| 1304 '''); | 1293 '''); |
| 1305 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1294 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1306 _computeResult(target, HINTS); | 1295 _computeResult(target, HINTS); |
| 1307 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1296 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1308 // validate | 1297 // validate |
| 1309 _fillErrorListener(HINTS); | 1298 _fillErrorListener(HINTS); |
| 1310 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); | 1299 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); |
| 1311 } | 1300 } |
| 1312 | 1301 |
| 1313 test_perform_imports_unusedImport_one() { | 1302 test_perform_imports_unusedImport_one() { |
| 1314 _newSource('/a.dart', r''' | 1303 newSource('/a.dart', r''' |
| 1315 library lib_a; | 1304 library lib_a; |
| 1316 class A {} | 1305 class A {} |
| 1317 '''); | 1306 '''); |
| 1318 _newSource('/b.dart', r''' | 1307 newSource('/b.dart', r''' |
| 1319 library lib_b; | 1308 library lib_b; |
| 1320 class B {} | 1309 class B {} |
| 1321 '''); | 1310 '''); |
| 1322 Source source = _newSource('/test.dart', r''' | 1311 Source source = newSource('/test.dart', r''' |
| 1323 import 'a.dart'; | 1312 import 'a.dart'; |
| 1324 import 'b.dart'; | 1313 import 'b.dart'; |
| 1325 main() { | 1314 main() { |
| 1326 new A(); | 1315 new A(); |
| 1327 }'''); | 1316 }'''); |
| 1328 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1317 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1329 _computeResult(target, HINTS); | 1318 _computeResult(target, HINTS); |
| 1330 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1319 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1331 // validate | 1320 // validate |
| 1332 _fillErrorListener(HINTS); | 1321 _fillErrorListener(HINTS); |
| 1333 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); | 1322 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); |
| 1334 } | 1323 } |
| 1335 | 1324 |
| 1336 test_perform_imports_unusedImport_zero() { | 1325 test_perform_imports_unusedImport_zero() { |
| 1337 _newSource('/a.dart', r''' | 1326 newSource('/a.dart', r''' |
| 1338 library lib_a; | 1327 library lib_a; |
| 1339 class A {} | 1328 class A {} |
| 1340 '''); | 1329 '''); |
| 1341 Source source = _newSource('/test.dart', r''' | 1330 Source source = newSource('/test.dart', r''' |
| 1342 import 'a.dart'; | 1331 import 'a.dart'; |
| 1343 main() { | 1332 main() { |
| 1344 new A(); | 1333 new A(); |
| 1345 }'''); | 1334 }'''); |
| 1346 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1335 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1347 _computeResult(target, HINTS); | 1336 _computeResult(target, HINTS); |
| 1348 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1337 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1349 // validate | 1338 // validate |
| 1350 _fillErrorListener(HINTS); | 1339 _fillErrorListener(HINTS); |
| 1351 errorListener.assertNoErrors(); | 1340 errorListener.assertNoErrors(); |
| 1352 } | 1341 } |
| 1353 | 1342 |
| 1354 test_perform_overrideVerifier() { | 1343 test_perform_overrideVerifier() { |
| 1355 Source source = _newSource('/test.dart', ''' | 1344 Source source = newSource('/test.dart', ''' |
| 1356 class A {} | 1345 class A {} |
| 1357 class B { | 1346 class B { |
| 1358 @override | 1347 @override |
| 1359 m() {} | 1348 m() {} |
| 1360 } | 1349 } |
| 1361 '''); | 1350 '''); |
| 1362 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1351 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1363 _computeResult(target, HINTS); | 1352 _computeResult(target, HINTS); |
| 1364 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1353 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1365 // validate | 1354 // validate |
| 1366 _fillErrorListener(HINTS); | 1355 _fillErrorListener(HINTS); |
| 1367 errorListener.assertErrorsWithCodes( | 1356 errorListener.assertErrorsWithCodes( |
| 1368 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); | 1357 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); |
| 1369 } | 1358 } |
| 1370 | 1359 |
| 1371 test_perform_todo() { | 1360 test_perform_todo() { |
| 1372 Source source = _newSource('/test.dart', ''' | 1361 Source source = newSource('/test.dart', ''' |
| 1373 main() { | 1362 main() { |
| 1374 // TODO(developer) foo bar | 1363 // TODO(developer) foo bar |
| 1375 } | 1364 } |
| 1376 '''); | 1365 '''); |
| 1377 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1366 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1378 _computeResult(target, HINTS); | 1367 _computeResult(target, HINTS); |
| 1379 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1368 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1380 // validate | 1369 // validate |
| 1381 _fillErrorListener(HINTS); | 1370 _fillErrorListener(HINTS); |
| 1382 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); | 1371 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); |
| 1383 } | 1372 } |
| 1384 | 1373 |
| 1385 test_perform_unusedLocalElements_class() { | 1374 test_perform_unusedLocalElements_class() { |
| 1386 Source source = _newSource('/test.dart', ''' | 1375 Source source = newSource('/test.dart', ''' |
| 1387 class _A {} | 1376 class _A {} |
| 1388 class _B {} | 1377 class _B {} |
| 1389 main() { | 1378 main() { |
| 1390 new _A(); | 1379 new _A(); |
| 1391 } | 1380 } |
| 1392 '''); | 1381 '''); |
| 1393 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1382 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1394 _computeResult(target, HINTS); | 1383 _computeResult(target, HINTS); |
| 1395 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1384 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1396 // validate | 1385 // validate |
| 1397 _fillErrorListener(HINTS); | 1386 _fillErrorListener(HINTS); |
| 1398 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); | 1387 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); |
| 1399 } | 1388 } |
| 1400 | 1389 |
| 1401 test_perform_unusedLocalElements_localVariable() { | 1390 test_perform_unusedLocalElements_localVariable() { |
| 1402 Source source = _newSource('/test.dart', ''' | 1391 Source source = newSource('/test.dart', ''' |
| 1403 main() { | 1392 main() { |
| 1404 var v = 42; | 1393 var v = 42; |
| 1405 } | 1394 } |
| 1406 '''); | 1395 '''); |
| 1407 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1396 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1408 _computeResult(target, HINTS); | 1397 _computeResult(target, HINTS); |
| 1409 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1398 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1410 // validate | 1399 // validate |
| 1411 _fillErrorListener(HINTS); | 1400 _fillErrorListener(HINTS); |
| 1412 errorListener | 1401 errorListener |
| 1413 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); | 1402 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); |
| 1414 } | 1403 } |
| 1415 | 1404 |
| 1416 test_perform_unusedLocalElements_method() { | 1405 test_perform_unusedLocalElements_method() { |
| 1417 Source source = _newSource('/my_lib.dart', ''' | 1406 Source source = newSource('/my_lib.dart', ''' |
| 1418 library my_lib; | 1407 library my_lib; |
| 1419 part 'my_part.dart'; | 1408 part 'my_part.dart'; |
| 1420 class A { | 1409 class A { |
| 1421 _ma() {} | 1410 _ma() {} |
| 1422 _mb() {} | 1411 _mb() {} |
| 1423 _mc() {} | 1412 _mc() {} |
| 1424 } | 1413 } |
| 1425 '''); | 1414 '''); |
| 1426 _newSource('/my_part.dart', ''' | 1415 newSource('/my_part.dart', ''' |
| 1427 part of my_lib; | 1416 part of my_lib; |
| 1428 | 1417 |
| 1429 f(A a) { | 1418 f(A a) { |
| 1430 a._mb(); | 1419 a._mb(); |
| 1431 } | 1420 } |
| 1432 '''); | 1421 '''); |
| 1433 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1422 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1434 _computeResult(target, HINTS); | 1423 _computeResult(target, HINTS); |
| 1435 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1424 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1436 // validate | 1425 // validate |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 1507 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 1519 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 1508 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 1520 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 1509 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 1521 expect(outputs[PARSE_ERRORS], hasLength(1)); | 1510 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 1522 expect(outputs[PARSED_UNIT], isNotNull); | 1511 expect(outputs[PARSED_UNIT], isNotNull); |
| 1523 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 1512 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 1524 expect(outputs[UNITS], hasLength(2)); | 1513 expect(outputs[UNITS], hasLength(2)); |
| 1525 } | 1514 } |
| 1526 | 1515 |
| 1527 void _performParseTask(String content) { | 1516 void _performParseTask(String content) { |
| 1528 AnalysisTarget target = _newSource('/test.dart', content); | 1517 AnalysisTarget target = newSource('/test.dart', content); |
| 1529 _computeResult(target, PARSED_UNIT); | 1518 _computeResult(target, PARSED_UNIT); |
| 1530 expect(task, new isInstanceOf<ParseDartTask>()); | 1519 expect(task, new isInstanceOf<ParseDartTask>()); |
| 1531 } | 1520 } |
| 1532 | 1521 |
| 1533 static void _assertHasCore(List<Source> sources, int lenght) { | 1522 static void _assertHasCore(List<Source> sources, int lenght) { |
| 1534 expect(sources, hasLength(lenght)); | 1523 expect(sources, hasLength(lenght)); |
| 1535 expect(sources, contains(predicate((Source s) { | 1524 expect(sources, contains(predicate((Source s) { |
| 1536 return s.fullName.endsWith('core.dart'); | 1525 return s.fullName.endsWith('core.dart'); |
| 1537 }))); | 1526 }))); |
| 1538 } | 1527 } |
| 1539 } | 1528 } |
| 1540 | 1529 |
| 1541 @reflectiveTest | 1530 @reflectiveTest |
| 1542 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { | 1531 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 1543 test_perform() { | 1532 test_perform() { |
| 1544 Source sourceLib = _newSource('/my_lib.dart', ''' | 1533 Source sourceLib = newSource('/my_lib.dart', ''' |
| 1545 library my_lib; | 1534 library my_lib; |
| 1546 part 'my_part.dart'; | 1535 part 'my_part.dart'; |
| 1547 class A {} | 1536 class A {} |
| 1548 class B extends A {} | 1537 class B extends A {} |
| 1549 '''); | 1538 '''); |
| 1550 _newSource('/my_part.dart', ''' | 1539 newSource('/my_part.dart', ''' |
| 1551 part of my_lib; | 1540 part of my_lib; |
| 1552 class C extends A {} | 1541 class C extends A {} |
| 1553 '''); | 1542 '''); |
| 1554 _computeResult(sourceLib, LIBRARY_ELEMENT5); | 1543 _computeResult(sourceLib, LIBRARY_ELEMENT5); |
| 1555 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); | 1544 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); |
| 1556 // validate | 1545 // validate |
| 1557 LibraryElement library = outputs[LIBRARY_ELEMENT5]; | 1546 LibraryElement library = outputs[LIBRARY_ELEMENT5]; |
| 1558 { | 1547 { |
| 1559 ClassElement classB = library.getType('B'); | 1548 ClassElement classB = library.getType('B'); |
| 1560 expect(classB.supertype.displayName, 'A'); | 1549 expect(classB.supertype.displayName, 'A'); |
| 1561 } | 1550 } |
| 1562 { | 1551 { |
| 1563 ClassElement classC = library.getType('C'); | 1552 ClassElement classC = library.getType('C'); |
| 1564 expect(classC.supertype.displayName, 'A'); | 1553 expect(classC.supertype.displayName, 'A'); |
| 1565 } | 1554 } |
| 1566 } | 1555 } |
| 1567 | 1556 |
| 1568 test_perform_deep() { | 1557 test_perform_deep() { |
| 1569 Source sourceA = _newSource('/a.dart', ''' | 1558 Source sourceA = newSource('/a.dart', ''' |
| 1570 library a; | 1559 library a; |
| 1571 import 'b.dart'; | 1560 import 'b.dart'; |
| 1572 class A extends B {} | 1561 class A extends B {} |
| 1573 '''); | 1562 '''); |
| 1574 _newSource('/b.dart', ''' | 1563 newSource('/b.dart', ''' |
| 1575 library b; | 1564 library b; |
| 1576 import 'c.dart'; | 1565 import 'c.dart'; |
| 1577 part 'b2.dart'; | 1566 part 'b2.dart'; |
| 1578 class B extends B2 {} | 1567 class B extends B2 {} |
| 1579 '''); | 1568 '''); |
| 1580 _newSource('/b2.dart', ''' | 1569 newSource('/b2.dart', ''' |
| 1581 part of b; | 1570 part of b; |
| 1582 class B2 extends C {} | 1571 class B2 extends C {} |
| 1583 '''); | 1572 '''); |
| 1584 _newSource('/c.dart', ''' | 1573 newSource('/c.dart', ''' |
| 1585 library c; | 1574 library c; |
| 1586 class C {} | 1575 class C {} |
| 1587 '''); | 1576 '''); |
| 1588 _computeResult(sourceA, LIBRARY_ELEMENT5); | 1577 _computeResult(sourceA, LIBRARY_ELEMENT5); |
| 1589 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); | 1578 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); |
| 1590 // validate | 1579 // validate |
| 1591 LibraryElement library = outputs[LIBRARY_ELEMENT5]; | 1580 LibraryElement library = outputs[LIBRARY_ELEMENT5]; |
| 1592 { | 1581 { |
| 1593 ClassElement clazz = library.getType('A'); | 1582 ClassElement clazz = library.getType('A'); |
| 1594 expect(clazz.displayName, 'A'); | 1583 expect(clazz.displayName, 'A'); |
| 1595 clazz = clazz.supertype.element; | 1584 clazz = clazz.supertype.element; |
| 1596 expect(clazz.displayName, 'B'); | 1585 expect(clazz.displayName, 'B'); |
| 1597 clazz = clazz.supertype.element; | 1586 clazz = clazz.supertype.element; |
| 1598 expect(clazz.displayName, 'B2'); | 1587 expect(clazz.displayName, 'B2'); |
| 1599 clazz = clazz.supertype.element; | 1588 clazz = clazz.supertype.element; |
| 1600 expect(clazz.displayName, 'C'); | 1589 expect(clazz.displayName, 'C'); |
| 1601 clazz = clazz.supertype.element; | 1590 clazz = clazz.supertype.element; |
| 1602 expect(clazz.displayName, 'Object'); | 1591 expect(clazz.displayName, 'Object'); |
| 1603 expect(clazz.supertype, isNull); | 1592 expect(clazz.supertype, isNull); |
| 1604 } | 1593 } |
| 1605 } | 1594 } |
| 1606 } | 1595 } |
| 1607 | 1596 |
| 1608 @reflectiveTest | 1597 @reflectiveTest |
| 1609 class ResolveReferencesTaskTest extends _AbstractDartTaskTest { | 1598 class ResolveReferencesTaskTest extends _AbstractDartTaskTest { |
| 1610 test_perform() { | 1599 test_perform() { |
| 1611 Source source = _newSource('/test.dart', ''' | 1600 Source source = newSource('/test.dart', ''' |
| 1612 class A { | 1601 class A { |
| 1613 m() {} | 1602 m() {} |
| 1614 } | 1603 } |
| 1615 main(A a) { | 1604 main(A a) { |
| 1616 a.m(); | 1605 a.m(); |
| 1617 } | 1606 } |
| 1618 '''); | 1607 '''); |
| 1619 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1608 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1620 // prepare unit and "a.m()" invocation | 1609 // prepare unit and "a.m()" invocation |
| 1621 CompilationUnit unit; | 1610 CompilationUnit unit; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1635 { | 1624 { |
| 1636 _computeResult(target, RESOLVED_UNIT); | 1625 _computeResult(target, RESOLVED_UNIT); |
| 1637 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 1626 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 1638 expect(outputs[RESOLVED_UNIT], same(outputs[RESOLVED_UNIT])); | 1627 expect(outputs[RESOLVED_UNIT], same(outputs[RESOLVED_UNIT])); |
| 1639 // a.m() is resolved now | 1628 // a.m() is resolved now |
| 1640 expect(invocation.methodName.staticElement, isNotNull); | 1629 expect(invocation.methodName.staticElement, isNotNull); |
| 1641 } | 1630 } |
| 1642 } | 1631 } |
| 1643 | 1632 |
| 1644 test_perform_errors() { | 1633 test_perform_errors() { |
| 1645 Source source = _newSource('/test.dart', ''' | 1634 Source source = newSource('/test.dart', ''' |
| 1646 class A { | 1635 class A { |
| 1647 } | 1636 } |
| 1648 main(A a) { | 1637 main(A a) { |
| 1649 a.unknownMethod(); | 1638 a.unknownMethod(); |
| 1650 } | 1639 } |
| 1651 '''); | 1640 '''); |
| 1652 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1641 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1653 _computeResult(target, RESOLVED_UNIT); | 1642 _computeResult(target, RESOLVED_UNIT); |
| 1654 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 1643 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 1655 // validate | 1644 // validate |
| 1656 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | 1645 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
| 1657 errorListener.assertErrorsWithCodes( | 1646 errorListener.assertErrorsWithCodes( |
| 1658 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | 1647 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 1659 } | 1648 } |
| 1660 } | 1649 } |
| 1661 | 1650 |
| 1662 @reflectiveTest | 1651 @reflectiveTest |
| 1663 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 1652 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 1664 test_perform() { | 1653 test_perform() { |
| 1665 Source source = _newSource('/test.dart', ''' | 1654 Source source = newSource('/test.dart', ''' |
| 1666 class A {} | 1655 class A {} |
| 1667 class B extends A {} | 1656 class B extends A {} |
| 1668 int f(String p) => p.length; | 1657 int f(String p) => p.length; |
| 1669 '''); | 1658 '''); |
| 1670 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1659 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1671 _computeResult(target, RESOLVED_UNIT4); | 1660 _computeResult(target, RESOLVED_UNIT4); |
| 1672 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1661 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1673 // validate | 1662 // validate |
| 1674 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 1663 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 1675 { | 1664 { |
| 1676 ClassDeclaration nodeA = unit.declarations[0]; | 1665 ClassDeclaration nodeA = unit.declarations[0]; |
| 1677 ClassDeclaration nodeB = unit.declarations[1]; | 1666 ClassDeclaration nodeB = unit.declarations[1]; |
| 1678 DartType extendsType = nodeB.extendsClause.superclass.type; | 1667 DartType extendsType = nodeB.extendsClause.superclass.type; |
| 1679 expect(extendsType, nodeA.element.type); | 1668 expect(extendsType, nodeA.element.type); |
| 1680 } | 1669 } |
| 1681 { | 1670 { |
| 1682 FunctionDeclaration functionNode = unit.declarations[2]; | 1671 FunctionDeclaration functionNode = unit.declarations[2]; |
| 1683 DartType returnType = functionNode.returnType.type; | 1672 DartType returnType = functionNode.returnType.type; |
| 1684 List<FormalParameter> parameters = | 1673 List<FormalParameter> parameters = |
| 1685 functionNode.functionExpression.parameters.parameters; | 1674 functionNode.functionExpression.parameters.parameters; |
| 1686 expect(returnType.displayName, 'int'); | 1675 expect(returnType.displayName, 'int'); |
| 1687 expect(parameters[0].element.type.displayName, 'String'); | 1676 expect(parameters[0].element.type.displayName, 'String'); |
| 1688 } | 1677 } |
| 1689 } | 1678 } |
| 1690 | 1679 |
| 1691 test_perform_errors() { | 1680 test_perform_errors() { |
| 1692 Source source = _newSource('/test.dart', ''' | 1681 Source source = newSource('/test.dart', ''' |
| 1693 NoSuchClass f() => null; | 1682 NoSuchClass f() => null; |
| 1694 '''); | 1683 '''); |
| 1695 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1684 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1696 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 1685 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); |
| 1697 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1686 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1698 // validate | 1687 // validate |
| 1699 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 1688 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 1700 errorListener | 1689 errorListener |
| 1701 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 1690 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 1702 } | 1691 } |
| 1703 } | 1692 } |
| 1704 | 1693 |
| 1705 @reflectiveTest | 1694 @reflectiveTest |
| 1706 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { | 1695 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 1707 /** | 1696 /** |
| 1708 * Verify that the mutated states of the given [variable] correspond to the | 1697 * Verify that the mutated states of the given [variable] correspond to the |
| 1709 * [mutatedInClosure] and [mutatedInScope] matchers. | 1698 * [mutatedInClosure] and [mutatedInScope] matchers. |
| 1710 */ | 1699 */ |
| 1711 void expectMutated(VariableElement variable, Matcher mutatedInClosure, | 1700 void expectMutated(VariableElement variable, Matcher mutatedInClosure, |
| 1712 Matcher mutatedInScope) { | 1701 Matcher mutatedInScope) { |
| 1713 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); | 1702 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); |
| 1714 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); | 1703 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); |
| 1715 } | 1704 } |
| 1716 | 1705 |
| 1717 test_perform_local() { | 1706 test_perform_local() { |
| 1718 Source source = _newSource('/test.dart', ''' | 1707 Source source = newSource('/test.dart', ''' |
| 1719 main() { | 1708 main() { |
| 1720 var v1 = 1; | 1709 var v1 = 1; |
| 1721 var v2 = 1; | 1710 var v2 = 1; |
| 1722 var v3 = 1; | 1711 var v3 = 1; |
| 1723 var v4 = 1; | 1712 var v4 = 1; |
| 1724 v2 = 2; | 1713 v2 = 2; |
| 1725 v4 = 2; | 1714 v4 = 2; |
| 1726 localFunction() { | 1715 localFunction() { |
| 1727 v3 = 3; | 1716 v3 = 3; |
| 1728 v4 = 3; | 1717 v4 = 3; |
| 1729 } | 1718 } |
| 1730 } | 1719 } |
| 1731 '''); | 1720 '''); |
| 1732 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1721 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1733 _computeResult(target, RESOLVED_UNIT5); | 1722 _computeResult(target, RESOLVED_UNIT5); |
| 1734 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 1723 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1735 // validate | 1724 // validate |
| 1736 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1725 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1737 FunctionElement main = unit.element.functions[0]; | 1726 FunctionElement main = unit.element.functions[0]; |
| 1738 expectMutated(main.localVariables[0], isFalse, isFalse); | 1727 expectMutated(main.localVariables[0], isFalse, isFalse); |
| 1739 expectMutated(main.localVariables[1], isFalse, isTrue); | 1728 expectMutated(main.localVariables[1], isFalse, isTrue); |
| 1740 expectMutated(main.localVariables[2], isTrue, isTrue); | 1729 expectMutated(main.localVariables[2], isTrue, isTrue); |
| 1741 expectMutated(main.localVariables[3], isTrue, isTrue); | 1730 expectMutated(main.localVariables[3], isTrue, isTrue); |
| 1742 } | 1731 } |
| 1743 | 1732 |
| 1744 test_perform_parameter() { | 1733 test_perform_parameter() { |
| 1745 Source source = _newSource('/test.dart', ''' | 1734 Source source = newSource('/test.dart', ''' |
| 1746 main(p1, p2, p3, p4) { | 1735 main(p1, p2, p3, p4) { |
| 1747 p2 = 2; | 1736 p2 = 2; |
| 1748 p4 = 2; | 1737 p4 = 2; |
| 1749 localFunction() { | 1738 localFunction() { |
| 1750 p3 = 3; | 1739 p3 = 3; |
| 1751 p4 = 3; | 1740 p4 = 3; |
| 1752 } | 1741 } |
| 1753 } | 1742 } |
| 1754 '''); | 1743 '''); |
| 1755 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1744 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 | 1796 |
| 1808 test_perform_noErrors() { | 1797 test_perform_noErrors() { |
| 1809 _performScanTask('class A {}'); | 1798 _performScanTask('class A {}'); |
| 1810 expect(outputs, hasLength(3)); | 1799 expect(outputs, hasLength(3)); |
| 1811 expect(outputs[LINE_INFO], isNotNull); | 1800 expect(outputs[LINE_INFO], isNotNull); |
| 1812 expect(outputs[SCAN_ERRORS], hasLength(0)); | 1801 expect(outputs[SCAN_ERRORS], hasLength(0)); |
| 1813 expect(outputs[TOKEN_STREAM], isNotNull); | 1802 expect(outputs[TOKEN_STREAM], isNotNull); |
| 1814 } | 1803 } |
| 1815 | 1804 |
| 1816 void _performScanTask(String content) { | 1805 void _performScanTask(String content) { |
| 1817 AnalysisTarget target = _newSource('/test.dart', content); | 1806 AnalysisTarget target = newSource('/test.dart', content); |
| 1818 _computeResult(target, TOKEN_STREAM); | 1807 _computeResult(target, TOKEN_STREAM); |
| 1819 expect(task, new isInstanceOf<ScanDartTask>()); | 1808 expect(task, new isInstanceOf<ScanDartTask>()); |
| 1820 } | 1809 } |
| 1821 } | 1810 } |
| 1822 | 1811 |
| 1823 @reflectiveTest | 1812 @reflectiveTest |
| 1824 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 1813 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 1825 test_perform_verifyError() { | 1814 test_perform_verifyError() { |
| 1826 Source source = _newSource('/test.dart', ''' | 1815 Source source = newSource('/test.dart', ''' |
| 1827 main() { | 1816 main() { |
| 1828 if (42) { | 1817 if (42) { |
| 1829 print('Not bool!'); | 1818 print('Not bool!'); |
| 1830 } | 1819 } |
| 1831 } | 1820 } |
| 1832 '''); | 1821 '''); |
| 1833 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1822 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1834 _computeResult(target, VERIFY_ERRORS); | 1823 _computeResult(target, VERIFY_ERRORS); |
| 1835 expect(task, new isInstanceOf<VerifyUnitTask>()); | 1824 expect(task, new isInstanceOf<VerifyUnitTask>()); |
| 1836 // validate | 1825 // validate |
| 1837 _fillErrorListener(VERIFY_ERRORS); | 1826 _fillErrorListener(VERIFY_ERRORS); |
| 1838 errorListener.assertErrorsWithCodes( | 1827 errorListener.assertErrorsWithCodes( |
| 1839 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); | 1828 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); |
| 1840 } | 1829 } |
| 1841 } | 1830 } |
| 1842 | 1831 |
| 1843 class _AbstractDartTaskTest extends EngineTestCase { | 1832 class _AbstractDartTaskTest extends AbstractContextTest { |
| 1844 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | |
| 1845 Source emptySource; | 1833 Source emptySource; |
| 1846 | 1834 |
| 1847 DartSdk sdk = new MockSdk(); | |
| 1848 _MockContext context = new _MockContext(); | |
| 1849 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; | |
| 1850 | |
| 1851 ExtensionManager extensionManager = new ExtensionManager(); | |
| 1852 | |
| 1853 TaskManager taskManager = new TaskManager(); | |
| 1854 AnalysisDriver analysisDriver; | |
| 1855 | |
| 1856 AnalysisTask task; | 1835 AnalysisTask task; |
| 1857 Map<ResultDescriptor<dynamic>, dynamic> outputs; | 1836 Map<ResultDescriptor<dynamic>, dynamic> outputs; |
| 1858 GatheringErrorListener errorListener = new GatheringErrorListener(); | 1837 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 1859 | 1838 |
| 1860 CacheEntry getCacheEntry(AnalysisTarget target) { | |
| 1861 return entryMap.putIfAbsent(target, () => new CacheEntry()); | |
| 1862 } | |
| 1863 | |
| 1864 void setUp() { | 1839 void setUp() { |
| 1865 emptySource = _newSource('/test.dart'); | 1840 super.setUp(); |
| 1866 // prepare AnalysisContext | 1841 emptySource = newSource('/test.dart'); |
| 1867 context.sourceFactory = new SourceFactory(<UriResolver>[ | |
| 1868 new DartUriResolver(sdk), | |
| 1869 new ResourceUriResolver(resourceProvider) | |
| 1870 ]); | |
| 1871 // configure TaskManager | |
| 1872 { | |
| 1873 EnginePlugin plugin = new EnginePlugin(); | |
| 1874 extensionManager.processPlugins([plugin]); | |
| 1875 taskManager.addTaskDescriptors(plugin.taskDescriptors); | |
| 1876 } | |
| 1877 // prepare AnalysisDriver | |
| 1878 analysisDriver = new AnalysisDriver(taskManager, context); | |
| 1879 } | 1842 } |
| 1880 | 1843 |
| 1881 void _computeResult(AnalysisTarget target, ResultDescriptor result) { | 1844 void _computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 1882 task = analysisDriver.computeResult(target, result); | 1845 task = analysisDriver.computeResult(target, result); |
| 1883 expect(task.caughtException, isNull); | 1846 expect(task.caughtException, isNull); |
| 1884 outputs = task.outputs; | 1847 outputs = task.outputs; |
| 1885 } | 1848 } |
| 1886 | 1849 |
| 1887 /** | 1850 /** |
| 1888 * Fill [errorListener] with [result] errors in the current [task]. | 1851 * Fill [errorListener] with [result] errors in the current [task]. |
| 1889 */ | 1852 */ |
| 1890 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 1853 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 1891 List<AnalysisError> errors = task.outputs[result]; | 1854 List<AnalysisError> errors = task.outputs[result]; |
| 1892 expect(errors, isNotNull, reason: result.name); | 1855 expect(errors, isNotNull, reason: result.name); |
| 1893 errorListener = new GatheringErrorListener(); | 1856 errorListener = new GatheringErrorListener(); |
| 1894 errorListener.addAll(errors); | 1857 errorListener.addAll(errors); |
| 1895 } | 1858 } |
| 1896 | |
| 1897 Source _newSource(String path, [String content = '']) { | |
| 1898 File file = resourceProvider.newFile(path, content); | |
| 1899 return file.createSource(); | |
| 1900 } | |
| 1901 | |
| 1902 List<Source> _newSources(Map<String, String> sourceMap) { | |
| 1903 List<Source> sources = <Source>[]; | |
| 1904 sourceMap.forEach((String path, String content) { | |
| 1905 File file = resourceProvider.newFile(path, content); | |
| 1906 Source source = file.createSource(); | |
| 1907 sources.add(source); | |
| 1908 }); | |
| 1909 return sources; | |
| 1910 } | |
| 1911 } | 1859 } |
| 1912 | |
| 1913 class _MockContext extends TypedMock implements InternalAnalysisContext { | |
| 1914 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | |
| 1915 SourceFactory sourceFactory; | |
| 1916 TypeProvider typeProvider; | |
| 1917 | |
| 1918 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; | |
| 1919 | |
| 1920 String get name => '_MockContext'; | |
| 1921 | |
| 1922 bool exists(Source source) => source.exists(); | |
| 1923 | |
| 1924 @override | |
| 1925 CacheEntry getCacheEntry(AnalysisTarget target) { | |
| 1926 return entryMap.putIfAbsent(target, () => new CacheEntry()); | |
| 1927 } | |
| 1928 | |
| 1929 TimestampedData<String> getContents(Source source) => source.contents; | |
| 1930 | |
| 1931 noSuchMethod(Invocation invocation) { | |
| 1932 print('noSuchMethod: ${invocation.memberName}'); | |
| 1933 return super.noSuchMethod(invocation); | |
| 1934 } | |
| 1935 } | |
| OLD | NEW |