| 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/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 import '../context/abstract_context.dart'; | 27 import '../context/abstract_context.dart'; |
| 28 | 28 |
| 29 main() { | 29 main() { |
| 30 groupSep = ' | '; | 30 groupSep = ' | '; |
| 31 runReflectiveTests(BuildClassConstructorsTaskTest); | 31 runReflectiveTests(BuildClassConstructorsTaskTest); |
| 32 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 32 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 33 runReflectiveTests(BuildDirectiveElementsTaskTest); | 33 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 34 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 34 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 35 runReflectiveTests(BuildSourceClosuresTaskTest); | 35 runReflectiveTests(BuildSourceClosuresTaskTest); |
| 36 runReflectiveTests(BuildExportNamespaceTaskTest); | 36 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 37 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); | |
| 38 runReflectiveTests(BuildLibraryConstructorsTaskTest); | 37 runReflectiveTests(BuildLibraryConstructorsTaskTest); |
| 39 runReflectiveTests(BuildLibraryElementTaskTest); | 38 runReflectiveTests(BuildLibraryElementTaskTest); |
| 40 runReflectiveTests(BuildPublicNamespaceTaskTest); | 39 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 41 runReflectiveTests(BuildTypeProviderTaskTest); | 40 runReflectiveTests(BuildTypeProviderTaskTest); |
| 42 runReflectiveTests(ComputeConstantDependenciesTaskTest); | 41 runReflectiveTests(ComputeConstantDependenciesTaskTest); |
| 43 runReflectiveTests(ComputeConstantValueTaskTest); | 42 runReflectiveTests(ComputeConstantValueTaskTest); |
| 44 runReflectiveTests(ContainingLibrariesTaskTest); | 43 runReflectiveTests(ContainingLibrariesTaskTest); |
| 45 runReflectiveTests(DartErrorsTaskTest); | 44 runReflectiveTests(DartErrorsTaskTest); |
| 46 runReflectiveTests(EvaluateUnitConstantsTaskTest); | 45 runReflectiveTests(EvaluateUnitConstantsTaskTest); |
| 47 runReflectiveTests(GatherUsedImportedElementsTaskTest); | 46 runReflectiveTests(GatherUsedImportedElementsTaskTest); |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 { | 707 { |
| 709 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 708 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 710 Namespace namespace = library.exportNamespace; | 709 Namespace namespace = library.exportNamespace; |
| 711 Iterable<String> definedKeys = namespace.definedNames.keys; | 710 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 712 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); | 711 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); |
| 713 } | 712 } |
| 714 } | 713 } |
| 715 } | 714 } |
| 716 | 715 |
| 717 @reflectiveTest | 716 @reflectiveTest |
| 718 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { | |
| 719 test_perform() { | |
| 720 Source source = newSource('/test.dart', ''' | |
| 721 typedef int F(G g); | |
| 722 typedef String G(int p); | |
| 723 '''); | |
| 724 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | |
| 725 computeResult(target, RESOLVED_UNIT3); | |
| 726 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | |
| 727 // validate | |
| 728 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | |
| 729 FunctionTypeAlias nodeF = unit.declarations[0]; | |
| 730 FunctionTypeAlias nodeG = unit.declarations[1]; | |
| 731 { | |
| 732 FormalParameter parameter = nodeF.parameters.parameters[0]; | |
| 733 DartType parameterType = parameter.element.type; | |
| 734 Element returnTypeElement = nodeF.returnType.type.element; | |
| 735 expect(returnTypeElement.displayName, 'int'); | |
| 736 expect(parameterType.element, nodeG.element); | |
| 737 } | |
| 738 { | |
| 739 FormalParameter parameter = nodeG.parameters.parameters[0]; | |
| 740 DartType parameterType = parameter.element.type; | |
| 741 expect(nodeG.returnType.type.element.displayName, 'String'); | |
| 742 expect(parameterType.element.displayName, 'int'); | |
| 743 } | |
| 744 } | |
| 745 | |
| 746 test_perform_errors() { | |
| 747 Source source = newSource('/test.dart', ''' | |
| 748 typedef int F(NoSuchType p); | |
| 749 '''); | |
| 750 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | |
| 751 computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS); | |
| 752 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); | |
| 753 // validate | |
| 754 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS); | |
| 755 errorListener | |
| 756 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | |
| 757 } | |
| 758 } | |
| 759 | |
| 760 @reflectiveTest | |
| 761 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest { | 717 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest { |
| 762 test_perform() { | 718 test_perform() { |
| 763 Source source = newSource('/test.dart', ''' | 719 Source source = newSource('/test.dart', ''' |
| 764 class B { | 720 class B { |
| 765 B(int i); | 721 B(int i); |
| 766 } | 722 } |
| 767 class M1 {} | 723 class M1 {} |
| 768 class M2 {} | 724 class M2 {} |
| 769 | 725 |
| 770 class C2 = C1 with M2; | 726 class C2 = C1 with M2; |
| (...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2134 } | 2090 } |
| 2135 } | 2091 } |
| 2136 | 2092 |
| 2137 @reflectiveTest | 2093 @reflectiveTest |
| 2138 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { | 2094 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { |
| 2139 test_buildInputs() { | 2095 test_buildInputs() { |
| 2140 Map<String, TaskInput> inputs = LibraryUnitErrorsTask | 2096 Map<String, TaskInput> inputs = LibraryUnitErrorsTask |
| 2141 .buildInputs(new LibrarySpecificUnit(emptySource, emptySource)); | 2097 .buildInputs(new LibrarySpecificUnit(emptySource, emptySource)); |
| 2142 expect(inputs, isNotNull); | 2098 expect(inputs, isNotNull); |
| 2143 expect(inputs.keys, unorderedEquals([ | 2099 expect(inputs.keys, unorderedEquals([ |
| 2144 LibraryUnitErrorsTask.BUILD_FUNCTION_TYPE_ALIASES_ERRORS_INPUT, | |
| 2145 LibraryUnitErrorsTask.CONSTRUCTORS_ERRORS_INPUT, | 2100 LibraryUnitErrorsTask.CONSTRUCTORS_ERRORS_INPUT, |
| 2146 LibraryUnitErrorsTask.HINTS_INPUT, | 2101 LibraryUnitErrorsTask.HINTS_INPUT, |
| 2147 LibraryUnitErrorsTask.RESOLVE_REFERENCES_ERRORS_INPUT, | 2102 LibraryUnitErrorsTask.RESOLVE_REFERENCES_ERRORS_INPUT, |
| 2148 LibraryUnitErrorsTask.RESOLVE_TYPE_NAMES_ERRORS_INPUT, | 2103 LibraryUnitErrorsTask.RESOLVE_TYPE_NAMES_ERRORS_INPUT, |
| 2149 LibraryUnitErrorsTask.VARIABLE_REFERENCE_ERRORS_INPUT, | 2104 LibraryUnitErrorsTask.VARIABLE_REFERENCE_ERRORS_INPUT, |
| 2150 LibraryUnitErrorsTask.VERIFY_ERRORS_INPUT | 2105 LibraryUnitErrorsTask.VERIFY_ERRORS_INPUT |
| 2151 ])); | 2106 ])); |
| 2152 } | 2107 } |
| 2153 | 2108 |
| 2154 test_constructor() { | 2109 test_constructor() { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2536 NoSuchClass f() => null; | 2491 NoSuchClass f() => null; |
| 2537 '''); | 2492 '''); |
| 2538 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2493 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2539 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 2494 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); |
| 2540 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 2495 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 2541 // validate | 2496 // validate |
| 2542 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 2497 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 2543 errorListener | 2498 errorListener |
| 2544 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 2499 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 2545 } | 2500 } |
| 2501 |
| 2502 test_perform_typedef() { |
| 2503 Source source = newSource('/test.dart', ''' |
| 2504 typedef int F(G g); |
| 2505 typedef String G(int p); |
| 2506 '''); |
| 2507 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2508 computeResult(target, RESOLVED_UNIT4); |
| 2509 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 2510 // validate |
| 2511 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 2512 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 2513 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 2514 { |
| 2515 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 2516 DartType parameterType = parameter.element.type; |
| 2517 Element returnTypeElement = nodeF.returnType.type.element; |
| 2518 expect(returnTypeElement.displayName, 'int'); |
| 2519 expect(parameterType.element, nodeG.element); |
| 2520 } |
| 2521 { |
| 2522 FormalParameter parameter = nodeG.parameters.parameters[0]; |
| 2523 DartType parameterType = parameter.element.type; |
| 2524 expect(nodeG.returnType.type.element.displayName, 'String'); |
| 2525 expect(parameterType.element.displayName, 'int'); |
| 2526 } |
| 2527 } |
| 2528 |
| 2529 test_perform_typedef_errors() { |
| 2530 Source source = newSource('/test.dart', ''' |
| 2531 typedef int F(NoSuchType p); |
| 2532 '''); |
| 2533 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2534 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); |
| 2535 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 2536 // validate |
| 2537 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 2538 errorListener |
| 2539 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 2540 } |
| 2546 } | 2541 } |
| 2547 | 2542 |
| 2548 @reflectiveTest | 2543 @reflectiveTest |
| 2549 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { | 2544 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 2550 /** | 2545 /** |
| 2551 * Verify that the mutated states of the given [variable] correspond to the | 2546 * Verify that the mutated states of the given [variable] correspond to the |
| 2552 * [mutatedInClosure] and [mutatedInScope] matchers. | 2547 * [mutatedInClosure] and [mutatedInScope] matchers. |
| 2553 */ | 2548 */ |
| 2554 void expectMutated(VariableElement variable, Matcher mutatedInClosure, | 2549 void expectMutated(VariableElement variable, Matcher mutatedInClosure, |
| 2555 Matcher mutatedInScope) { | 2550 Matcher mutatedInScope) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2800 /** | 2795 /** |
| 2801 * Fill [errorListener] with [result] errors in the current [task]. | 2796 * Fill [errorListener] with [result] errors in the current [task]. |
| 2802 */ | 2797 */ |
| 2803 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2798 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2804 List<AnalysisError> errors = task.outputs[result]; | 2799 List<AnalysisError> errors = task.outputs[result]; |
| 2805 expect(errors, isNotNull, reason: result.name); | 2800 expect(errors, isNotNull, reason: result.name); |
| 2806 errorListener = new GatheringErrorListener(); | 2801 errorListener = new GatheringErrorListener(); |
| 2807 errorListener.addAll(errors); | 2802 errorListener.addAll(errors); |
| 2808 } | 2803 } |
| 2809 } | 2804 } |
| OLD | NEW |