| 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 10 matching lines...) Expand all Loading... |
| 21 import 'package:analyzer/task/general.dart'; | 21 import 'package:analyzer/task/general.dart'; |
| 22 import 'package:analyzer/task/model.dart'; | 22 import 'package:analyzer/task/model.dart'; |
| 23 import 'package:unittest/unittest.dart'; | 23 import 'package:unittest/unittest.dart'; |
| 24 | 24 |
| 25 import '../../generated/test_support.dart'; | 25 import '../../generated/test_support.dart'; |
| 26 import '../../reflective_tests.dart'; | 26 import '../../reflective_tests.dart'; |
| 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); | |
| 32 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 31 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 33 runReflectiveTests(BuildDirectiveElementsTaskTest); | 32 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 34 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 33 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 35 runReflectiveTests(BuildSourceExportClosureTaskTest); | 34 runReflectiveTests(BuildSourceExportClosureTaskTest); |
| 36 runReflectiveTests(BuildSourceImportExportClosureTaskTest); | 35 runReflectiveTests(BuildSourceImportExportClosureTaskTest); |
| 37 runReflectiveTests(BuildExportNamespaceTaskTest); | 36 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 38 runReflectiveTests(BuildLibraryConstructorsTaskTest); | |
| 39 runReflectiveTests(BuildLibraryElementTaskTest); | 37 runReflectiveTests(BuildLibraryElementTaskTest); |
| 40 runReflectiveTests(BuildPublicNamespaceTaskTest); | 38 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 41 runReflectiveTests(BuildTypeProviderTaskTest); | 39 runReflectiveTests(BuildTypeProviderTaskTest); |
| 42 runReflectiveTests(ComputeConstantDependenciesTaskTest); | 40 runReflectiveTests(ComputeConstantDependenciesTaskTest); |
| 43 runReflectiveTests(ComputeConstantValueTaskTest); | 41 runReflectiveTests(ComputeConstantValueTaskTest); |
| 44 runReflectiveTests(ContainingLibrariesTaskTest); | 42 runReflectiveTests(ContainingLibrariesTaskTest); |
| 45 runReflectiveTests(DartErrorsTaskTest); | 43 runReflectiveTests(DartErrorsTaskTest); |
| 46 runReflectiveTests(EvaluateUnitConstantsTaskTest); | 44 runReflectiveTests(EvaluateUnitConstantsTaskTest); |
| 47 runReflectiveTests(GatherUsedImportedElementsTaskTest); | 45 runReflectiveTests(GatherUsedImportedElementsTaskTest); |
| 48 runReflectiveTests(GatherUsedLocalElementsTaskTest); | 46 runReflectiveTests(GatherUsedLocalElementsTaskTest); |
| 49 runReflectiveTests(GenerateHintsTaskTest); | 47 runReflectiveTests(GenerateHintsTaskTest); |
| 50 runReflectiveTests(LibraryErrorsReadyTaskTest); | 48 runReflectiveTests(LibraryErrorsReadyTaskTest); |
| 51 runReflectiveTests(LibraryUnitErrorsTaskTest); | 49 runReflectiveTests(LibraryUnitErrorsTaskTest); |
| 52 runReflectiveTests(ParseDartTaskTest); | 50 runReflectiveTests(ParseDartTaskTest); |
| 53 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 51 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 54 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 52 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 55 runReflectiveTests(ResolveReferencesTaskTest); | 53 runReflectiveTests(ResolveReferencesTaskTest); |
| 56 runReflectiveTests(ResolveVariableReferencesTaskTest); | 54 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 57 runReflectiveTests(ScanDartTaskTest); | 55 runReflectiveTests(ScanDartTaskTest); |
| 58 runReflectiveTests(VerifyUnitTaskTest); | 56 runReflectiveTests(VerifyUnitTaskTest); |
| 59 } | 57 } |
| 60 | 58 |
| 61 @reflectiveTest | 59 @reflectiveTest |
| 62 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { | |
| 63 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { | |
| 64 Source source = newSource('/test.dart', ''' | |
| 65 class B { | |
| 66 B({x}); | |
| 67 } | |
| 68 class M {} | |
| 69 class C extends B with M {} | |
| 70 '''); | |
| 71 LibraryElement libraryElement; | |
| 72 { | |
| 73 computeResult(source, LIBRARY_ELEMENT5); | |
| 74 libraryElement = outputs[LIBRARY_ELEMENT5]; | |
| 75 } | |
| 76 // prepare C | |
| 77 ClassElement c = libraryElement.getType('C'); | |
| 78 expect(c, isNotNull); | |
| 79 // build constructors | |
| 80 computeResult(c, CONSTRUCTORS); | |
| 81 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | |
| 82 _fillErrorListener(CONSTRUCTORS_ERRORS); | |
| 83 errorListener.assertErrorsWithCodes( | |
| 84 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | |
| 85 } | |
| 86 | |
| 87 test_perform_ClassDeclaration_explicitConstructors() { | |
| 88 Source source = newSource('/test.dart', ''' | |
| 89 class B { | |
| 90 B(p); | |
| 91 } | |
| 92 class C extends B { | |
| 93 C(int a, String b) {} | |
| 94 } | |
| 95 '''); | |
| 96 LibraryElement libraryElement; | |
| 97 { | |
| 98 computeResult(source, LIBRARY_ELEMENT5); | |
| 99 libraryElement = outputs[LIBRARY_ELEMENT5]; | |
| 100 } | |
| 101 // prepare C | |
| 102 ClassElement c = libraryElement.getType('C'); | |
| 103 expect(c, isNotNull); | |
| 104 // build constructors | |
| 105 computeResult(c, CONSTRUCTORS); | |
| 106 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | |
| 107 // no errors | |
| 108 expect(outputs[CONSTRUCTORS_ERRORS], isEmpty); | |
| 109 // explicit constructor | |
| 110 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; | |
| 111 expect(constructors, hasLength(1)); | |
| 112 expect(constructors[0].parameters, hasLength(2)); | |
| 113 } | |
| 114 | |
| 115 test_perform_ClassTypeAlias() { | |
| 116 Source source = newSource('/test.dart', ''' | |
| 117 class B { | |
| 118 B(int i); | |
| 119 } | |
| 120 class M1 {} | |
| 121 class M2 {} | |
| 122 | |
| 123 class C2 = C1 with M2; | |
| 124 class C1 = B with M1; | |
| 125 '''); | |
| 126 LibraryElement libraryElement; | |
| 127 { | |
| 128 computeResult(source, LIBRARY_ELEMENT5); | |
| 129 libraryElement = outputs[LIBRARY_ELEMENT5]; | |
| 130 } | |
| 131 // prepare C2 | |
| 132 ClassElement class2 = libraryElement.getType('C2'); | |
| 133 expect(class2, isNotNull); | |
| 134 // build constructors | |
| 135 computeResult(class2, CONSTRUCTORS); | |
| 136 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | |
| 137 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; | |
| 138 expect(constructors, hasLength(1)); | |
| 139 expect(constructors[0].parameters, hasLength(1)); | |
| 140 } | |
| 141 | |
| 142 test_perform_ClassTypeAlias_errors_mixinHasNoConstructors() { | |
| 143 Source source = newSource('/test.dart', ''' | |
| 144 class B { | |
| 145 B({x}); | |
| 146 } | |
| 147 class M {} | |
| 148 class C = B with M; | |
| 149 '''); | |
| 150 LibraryElement libraryElement; | |
| 151 { | |
| 152 computeResult(source, LIBRARY_ELEMENT5); | |
| 153 libraryElement = outputs[LIBRARY_ELEMENT5]; | |
| 154 } | |
| 155 // prepare C | |
| 156 ClassElement c = libraryElement.getType('C'); | |
| 157 expect(c, isNotNull); | |
| 158 // build constructors | |
| 159 computeResult(c, CONSTRUCTORS); | |
| 160 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | |
| 161 _fillErrorListener(CONSTRUCTORS_ERRORS); | |
| 162 errorListener.assertErrorsWithCodes( | |
| 163 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 @reflectiveTest | |
| 168 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 60 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 169 Source source; | 61 Source source; |
| 170 LibrarySpecificUnit target; | 62 LibrarySpecificUnit target; |
| 171 | 63 |
| 172 test_buildInputs() { | 64 test_buildInputs() { |
| 173 LibrarySpecificUnit target = | 65 LibrarySpecificUnit target = |
| 174 new LibrarySpecificUnit(emptySource, emptySource); | 66 new LibrarySpecificUnit(emptySource, emptySource); |
| 175 Map<String, TaskInput> inputs = | 67 Map<String, TaskInput> inputs = |
| 176 BuildCompilationUnitElementTask.buildInputs(target); | 68 BuildCompilationUnitElementTask.buildInputs(target); |
| 177 expect(inputs, isNotNull); | 69 expect(inputs, isNotNull); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 { | 600 { |
| 709 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 601 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 710 Namespace namespace = library.exportNamespace; | 602 Namespace namespace = library.exportNamespace; |
| 711 Iterable<String> definedKeys = namespace.definedNames.keys; | 603 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 712 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); | 604 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); |
| 713 } | 605 } |
| 714 } | 606 } |
| 715 } | 607 } |
| 716 | 608 |
| 717 @reflectiveTest | 609 @reflectiveTest |
| 718 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest { | |
| 719 test_perform() { | |
| 720 Source source = newSource('/test.dart', ''' | |
| 721 class B { | |
| 722 B(int i); | |
| 723 } | |
| 724 class M1 {} | |
| 725 class M2 {} | |
| 726 | |
| 727 class C2 = C1 with M2; | |
| 728 class C1 = B with M1; | |
| 729 class C3 = B with M2; | |
| 730 '''); | |
| 731 computeResult(source, LIBRARY_ELEMENT6); | |
| 732 expect(task, new isInstanceOf<BuildLibraryConstructorsTask>()); | |
| 733 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT6]; | |
| 734 // C1 | |
| 735 { | |
| 736 ClassElement classElement = libraryElement.getType('C2'); | |
| 737 List<ConstructorElement> constructors = classElement.constructors; | |
| 738 expect(constructors, hasLength(1)); | |
| 739 expect(constructors[0].parameters, hasLength(1)); | |
| 740 } | |
| 741 // C3 | |
| 742 { | |
| 743 ClassElement classElement = libraryElement.getType('C3'); | |
| 744 List<ConstructorElement> constructors = classElement.constructors; | |
| 745 expect(constructors, hasLength(1)); | |
| 746 expect(constructors[0].parameters, hasLength(1)); | |
| 747 } | |
| 748 } | |
| 749 } | |
| 750 | |
| 751 @reflectiveTest | |
| 752 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { | 610 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { |
| 753 Source librarySource; | 611 Source librarySource; |
| 754 CompilationUnit libraryUnit; | 612 CompilationUnit libraryUnit; |
| 755 CompilationUnitElement libraryUnitElement; | 613 CompilationUnitElement libraryUnitElement; |
| 756 List<CompilationUnit> partUnits; | 614 List<CompilationUnit> partUnits; |
| 757 | 615 |
| 758 LibraryElement libraryElement; | 616 LibraryElement libraryElement; |
| 759 | 617 |
| 760 test_constructor() { | 618 test_constructor() { |
| 761 BuildLibraryElementTask task = | 619 BuildLibraryElementTask task = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 791 part 'part1.dart'; | 649 part 'part1.dart'; |
| 792 part 'part2.dart'; | 650 part 'part2.dart'; |
| 793 ''', | 651 ''', |
| 794 '/part1.dart': ''' | 652 '/part1.dart': ''' |
| 795 part of lib; | 653 part of lib; |
| 796 ''', | 654 ''', |
| 797 '/part2.dart': ''' | 655 '/part2.dart': ''' |
| 798 part of lib; | 656 part of lib; |
| 799 ''' | 657 ''' |
| 800 }); | 658 }); |
| 801 expect(outputs, hasLength(4)); | 659 expect(outputs, hasLength(3)); |
| 802 // simple outputs | 660 // simple outputs |
| 803 expect(outputs[BUILD_LIBRARY_ERRORS], isEmpty); | 661 expect(outputs[BUILD_LIBRARY_ERRORS], isEmpty); |
| 804 expect(outputs[IS_LAUNCHABLE], isFalse); | 662 expect(outputs[IS_LAUNCHABLE], isFalse); |
| 805 // LibraryElement output | 663 // LibraryElement output |
| 806 expect(libraryElement, isNotNull); | 664 expect(libraryElement, isNotNull); |
| 807 expect(libraryElement.entryPoint, isNull); | 665 expect(libraryElement.entryPoint, isNull); |
| 808 expect(libraryElement.source, same(librarySource)); | 666 expect(libraryElement.source, same(librarySource)); |
| 809 expect(libraryElement.definingCompilationUnit, libraryUnitElement); | 667 expect(libraryElement.definingCompilationUnit, libraryUnitElement); |
| 810 expect(libraryElement.parts, | 668 expect(libraryElement.parts, |
| 811 unorderedEquals([partUnits[0].element, partUnits[1].element])); | 669 unorderedEquals([partUnits[0].element, partUnits[1].element])); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 832 expect( | 690 expect( |
| 833 (libraryUnit.directives[1] as PartDirective).element, same(firstPart)); | 691 (libraryUnit.directives[1] as PartDirective).element, same(firstPart)); |
| 834 | 692 |
| 835 expect(secondPart.uri, 'part2.dart'); | 693 expect(secondPart.uri, 'part2.dart'); |
| 836 expect(secondPart.uriOffset, 37); | 694 expect(secondPart.uriOffset, 37); |
| 837 expect(secondPart.uriEnd, 49); | 695 expect(secondPart.uriEnd, 49); |
| 838 expect( | 696 expect( |
| 839 (libraryUnit.directives[2] as PartDirective).element, same(secondPart)); | 697 (libraryUnit.directives[2] as PartDirective).element, same(secondPart)); |
| 840 } | 698 } |
| 841 | 699 |
| 842 test_perform_classElements() { | |
| 843 _performBuildTask({ | |
| 844 '/lib.dart': ''' | |
| 845 library lib; | |
| 846 part 'part1.dart'; | |
| 847 part 'part2.dart'; | |
| 848 class A {} | |
| 849 ''', | |
| 850 '/part1.dart': ''' | |
| 851 part of lib; | |
| 852 class B {} | |
| 853 ''', | |
| 854 '/part2.dart': ''' | |
| 855 part of lib; | |
| 856 class C {} | |
| 857 ''' | |
| 858 }); | |
| 859 List<ClassElement> classElements = outputs[CLASS_ELEMENTS]; | |
| 860 List<String> classNames = classElements.map((c) => c.displayName).toList(); | |
| 861 expect(classNames, unorderedEquals(['A', 'B', 'C'])); | |
| 862 } | |
| 863 | |
| 864 test_perform_error_missingLibraryDirectiveWithPart_hasCommon() { | 700 test_perform_error_missingLibraryDirectiveWithPart_hasCommon() { |
| 865 _performBuildTask({ | 701 _performBuildTask({ |
| 866 '/lib.dart': ''' | 702 '/lib.dart': ''' |
| 867 part 'partA.dart'; | 703 part 'partA.dart'; |
| 868 part 'partB.dart'; | 704 part 'partB.dart'; |
| 869 ''', | 705 ''', |
| 870 '/partA.dart': ''' | 706 '/partA.dart': ''' |
| 871 part of my_lib; | 707 part of my_lib; |
| 872 ''', | 708 ''', |
| 873 '/partB.dart': ''' | 709 '/partB.dart': ''' |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 } | 1883 } |
| 2048 } | 1884 } |
| 2049 | 1885 |
| 2050 @reflectiveTest | 1886 @reflectiveTest |
| 2051 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { | 1887 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { |
| 2052 test_buildInputs() { | 1888 test_buildInputs() { |
| 2053 Map<String, TaskInput> inputs = LibraryUnitErrorsTask | 1889 Map<String, TaskInput> inputs = LibraryUnitErrorsTask |
| 2054 .buildInputs(new LibrarySpecificUnit(emptySource, emptySource)); | 1890 .buildInputs(new LibrarySpecificUnit(emptySource, emptySource)); |
| 2055 expect(inputs, isNotNull); | 1891 expect(inputs, isNotNull); |
| 2056 expect(inputs.keys, unorderedEquals([ | 1892 expect(inputs.keys, unorderedEquals([ |
| 2057 LibraryUnitErrorsTask.CONSTRUCTORS_ERRORS_INPUT, | |
| 2058 LibraryUnitErrorsTask.HINTS_INPUT, | 1893 LibraryUnitErrorsTask.HINTS_INPUT, |
| 2059 LibraryUnitErrorsTask.RESOLVE_REFERENCES_ERRORS_INPUT, | 1894 LibraryUnitErrorsTask.RESOLVE_REFERENCES_ERRORS_INPUT, |
| 2060 LibraryUnitErrorsTask.RESOLVE_TYPE_NAMES_ERRORS_INPUT, | 1895 LibraryUnitErrorsTask.RESOLVE_TYPE_NAMES_ERRORS_INPUT, |
| 2061 LibraryUnitErrorsTask.VARIABLE_REFERENCE_ERRORS_INPUT, | 1896 LibraryUnitErrorsTask.VARIABLE_REFERENCE_ERRORS_INPUT, |
| 2062 LibraryUnitErrorsTask.VERIFY_ERRORS_INPUT | 1897 LibraryUnitErrorsTask.VERIFY_ERRORS_INPUT |
| 2063 ])); | 1898 ])); |
| 2064 } | 1899 } |
| 2065 | 1900 |
| 2066 test_constructor() { | 1901 test_constructor() { |
| 2067 LibraryUnitErrorsTask task = | 1902 LibraryUnitErrorsTask task = |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2738 /** | 2573 /** |
| 2739 * Fill [errorListener] with [result] errors in the current [task]. | 2574 * Fill [errorListener] with [result] errors in the current [task]. |
| 2740 */ | 2575 */ |
| 2741 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2576 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2742 List<AnalysisError> errors = task.outputs[result]; | 2577 List<AnalysisError> errors = task.outputs[result]; |
| 2743 expect(errors, isNotNull, reason: result.name); | 2578 expect(errors, isNotNull, reason: result.name); |
| 2744 errorListener = new GatheringErrorListener(); | 2579 errorListener = new GatheringErrorListener(); |
| 2745 errorListener.addAll(errors); | 2580 errorListener.addAll(errors); |
| 2746 } | 2581 } |
| 2747 } | 2582 } |
| OLD | NEW |