| 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'; |
| 11 import 'package:analyzer/src/generated/engine.dart' | 11 import 'package:analyzer/src/generated/engine.dart' |
| 12 show AnalysisOptionsImpl, CacheState; | 12 show AnalysisOptionsImpl, CacheState; |
| 13 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
| 14 import 'package:analyzer/src/generated/resolver.dart'; | 14 import 'package:analyzer/src/generated/resolver.dart'; |
| 15 import 'package:analyzer/src/generated/scanner.dart'; | 15 import 'package:analyzer/src/generated/scanner.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | 16 import 'package:analyzer/src/generated/sdk.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/services/lint.dart'; | 18 import 'package:analyzer/src/services/lint.dart'; |
| 19 import 'package:analyzer/src/task/dart.dart'; | 19 import 'package:analyzer/src/task/dart.dart'; |
| 20 import 'package:analyzer/src/task/html.dart'; | 20 import 'package:analyzer/src/task/html.dart'; |
| 21 import 'package:analyzer/src/task/strong/info.dart'; |
| 21 import 'package:analyzer/task/dart.dart'; | 22 import 'package:analyzer/task/dart.dart'; |
| 22 import 'package:analyzer/task/general.dart'; | 23 import 'package:analyzer/task/general.dart'; |
| 23 import 'package:analyzer/task/model.dart'; | 24 import 'package:analyzer/task/model.dart'; |
| 24 import 'package:unittest/unittest.dart'; | 25 import 'package:unittest/unittest.dart'; |
| 25 | 26 |
| 26 import '../../generated/resolver_test.dart'; | 27 import '../../generated/resolver_test.dart'; |
| 27 import '../../generated/test_support.dart'; | 28 import '../../generated/test_support.dart'; |
| 28 import '../../reflective_tests.dart'; | 29 import '../../reflective_tests.dart'; |
| 29 import '../../utils.dart'; | 30 import '../../utils.dart'; |
| 30 import '../context/abstract_context.dart'; | 31 import '../context/abstract_context.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 58 runReflectiveTests(LibraryUnitErrorsTaskTest); | 59 runReflectiveTests(LibraryUnitErrorsTaskTest); |
| 59 runReflectiveTests(ParseDartTaskTest); | 60 runReflectiveTests(ParseDartTaskTest); |
| 60 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); | 61 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); |
| 61 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); | 62 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); |
| 62 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 63 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 63 runReflectiveTests(ResolveUnitTaskTest); | 64 runReflectiveTests(ResolveUnitTaskTest); |
| 64 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 65 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 65 runReflectiveTests(ResolveVariableReferencesTaskTest); | 66 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 66 runReflectiveTests(ScanDartTaskTest); | 67 runReflectiveTests(ScanDartTaskTest); |
| 67 runReflectiveTests(StrongModeInferenceTest); | 68 runReflectiveTests(StrongModeInferenceTest); |
| 69 runReflectiveTests(StrongModeVerifyUnitTaskTest); |
| 68 runReflectiveTests(VerifyUnitTaskTest); | 70 runReflectiveTests(VerifyUnitTaskTest); |
| 69 } | 71 } |
| 70 | 72 |
| 71 isInstanceOf isBuildCompilationUnitElementTask = | 73 isInstanceOf isBuildCompilationUnitElementTask = |
| 72 new isInstanceOf<BuildCompilationUnitElementTask>(); | 74 new isInstanceOf<BuildCompilationUnitElementTask>(); |
| 73 isInstanceOf isBuildDirectiveElementsTask = | 75 isInstanceOf isBuildDirectiveElementsTask = |
| 74 new isInstanceOf<BuildDirectiveElementsTask>(); | 76 new isInstanceOf<BuildDirectiveElementsTask>(); |
| 75 isInstanceOf isBuildEnumMemberElementsTask = | 77 isInstanceOf isBuildEnumMemberElementsTask = |
| 76 new isInstanceOf<BuildEnumMemberElementsTask>(); | 78 new isInstanceOf<BuildEnumMemberElementsTask>(); |
| 77 isInstanceOf isBuildExportNamespaceTask = | 79 isInstanceOf isBuildExportNamespaceTask = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 isInstanceOf isPartiallyResolveUnitReferencesTask = | 119 isInstanceOf isPartiallyResolveUnitReferencesTask = |
| 118 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); | 120 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); |
| 119 isInstanceOf isResolveLibraryTypeNamesTask = | 121 isInstanceOf isResolveLibraryTypeNamesTask = |
| 120 new isInstanceOf<ResolveLibraryTypeNamesTask>(); | 122 new isInstanceOf<ResolveLibraryTypeNamesTask>(); |
| 121 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); | 123 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); |
| 122 isInstanceOf isResolveUnitTypeNamesTask = | 124 isInstanceOf isResolveUnitTypeNamesTask = |
| 123 new isInstanceOf<ResolveUnitTypeNamesTask>(); | 125 new isInstanceOf<ResolveUnitTypeNamesTask>(); |
| 124 isInstanceOf isResolveVariableReferencesTask = | 126 isInstanceOf isResolveVariableReferencesTask = |
| 125 new isInstanceOf<ResolveVariableReferencesTask>(); | 127 new isInstanceOf<ResolveVariableReferencesTask>(); |
| 126 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); | 128 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); |
| 129 isInstanceOf isStrongModeVerifyUnitTask = |
| 130 new isInstanceOf<StrongModeVerifyUnitTask>(); |
| 127 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); | 131 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); |
| 128 | 132 |
| 129 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); | 133 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); |
| 130 | 134 |
| 131 @reflectiveTest | 135 @reflectiveTest |
| 132 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 136 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 133 Source source; | 137 Source source; |
| 134 LibrarySpecificUnit target; | 138 LibrarySpecificUnit target; |
| 135 | 139 |
| 136 test_perform_find_constants() { | 140 test_perform_find_constants() { |
| (...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 class C { | 1841 class C { |
| 1838 const C(); | 1842 const C(); |
| 1839 } | 1843 } |
| 1840 | 1844 |
| 1841 @x | 1845 @x |
| 1842 f() {} | 1846 f() {} |
| 1843 | 1847 |
| 1844 const x = const C(); | 1848 const x = const C(); |
| 1845 '''); | 1849 '''); |
| 1846 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1850 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1847 computeResult(target, RESOLVED_UNIT, matcher: isEvaluateUnitConstantsTask); | 1851 computeResult(target, RESOLVED_UNIT10, |
| 1848 CompilationUnit unit = outputs[RESOLVED_UNIT]; | 1852 matcher: isEvaluateUnitConstantsTask); |
| 1853 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 1849 CompilationUnitElement unitElement = unit.element; | 1854 CompilationUnitElement unitElement = unit.element; |
| 1850 expect( | 1855 expect( |
| 1851 (unitElement.types[0].constructors[0] as ConstructorElementImpl) | 1856 (unitElement.types[0].constructors[0] as ConstructorElementImpl) |
| 1852 .isCycleFree, | 1857 .isCycleFree, |
| 1853 isTrue); | 1858 isTrue); |
| 1854 expect( | 1859 expect( |
| 1855 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) | 1860 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) |
| 1856 .evaluationResult, | 1861 .evaluationResult, |
| 1857 isNotNull); | 1862 isNotNull); |
| 1858 expect( | 1863 expect( |
| (...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3963 expect(decl.initializer.staticType, intType); | 3968 expect(decl.initializer.staticType, intType); |
| 3964 | 3969 |
| 3965 ExpressionStatement statement = statements[1]; | 3970 ExpressionStatement statement = statements[1]; |
| 3966 AssignmentExpression assgn = statement.expression; | 3971 AssignmentExpression assgn = statement.expression; |
| 3967 expect(assgn.leftHandSide.staticType, intType); | 3972 expect(assgn.leftHandSide.staticType, intType); |
| 3968 expect(assgn.rightHandSide.staticType, stringType); | 3973 expect(assgn.rightHandSide.staticType, stringType); |
| 3969 } | 3974 } |
| 3970 } | 3975 } |
| 3971 | 3976 |
| 3972 @reflectiveTest | 3977 @reflectiveTest |
| 3978 class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 3979 @override |
| 3980 void setUp() { |
| 3981 super.setUp(); |
| 3982 enableStrongMode(); |
| 3983 } |
| 3984 |
| 3985 void test_perform_verifyError() { |
| 3986 enableStrongMode(); |
| 3987 AnalysisTarget source = newSource( |
| 3988 '/test.dart', |
| 3989 ''' |
| 3990 int topLevel = 3; |
| 3991 class C { |
| 3992 String field = topLevel; |
| 3993 } |
| 3994 '''); |
| 3995 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 3996 // validate |
| 3997 _fillErrorListener(STRONG_MODE_ERRORS); |
| 3998 |
| 3999 var errors = errorListener.errors; |
| 4000 expect(errors.length, 1); |
| 4001 expect(errors[0].errorCode.name, "dev_compiler.StaticTypeError"); |
| 4002 } |
| 4003 |
| 4004 void test_perform_recordDynamicInvoke() { |
| 4005 enableStrongMode(); |
| 4006 AnalysisTarget source = newSource( |
| 4007 '/test.dart', |
| 4008 ''' |
| 4009 void main() { |
| 4010 dynamic a = []; |
| 4011 a[0]; |
| 4012 } |
| 4013 '''); |
| 4014 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 4015 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 4016 |
| 4017 // validate |
| 4018 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4019 var errors = errorListener.errors; |
| 4020 expect(errors.length, 1); |
| 4021 expect(errors[0].errorCode.name, "dev_compiler.DynamicInvoke"); |
| 4022 |
| 4023 List<Statement> statements = getStatementsInTopLevelFunction(unit, "main"); |
| 4024 ExpressionStatement statement = statements[1]; |
| 4025 IndexExpression idx = statement.expression; |
| 4026 expect(DynamicInvoke.get(idx.target), isNotNull); |
| 4027 expect(DynamicInvoke.get(idx.target), isNotNull); |
| 4028 expect(DynamicInvoke.get(idx.target), isTrue); |
| 4029 } |
| 4030 } |
| 4031 |
| 4032 @reflectiveTest |
| 3973 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 4033 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 3974 test_perform_constantError() { | 4034 test_perform_constantError() { |
| 3975 Source source = newSource( | 4035 Source source = newSource( |
| 3976 '/test.dart', | 4036 '/test.dart', |
| 3977 ''' | 4037 ''' |
| 3978 main(int p) { | 4038 main(int p) { |
| 3979 const v = p; | 4039 const v = p; |
| 3980 } | 4040 } |
| 3981 '''); | 4041 '''); |
| 3982 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4042 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4008 '/test.dart', | 4068 '/test.dart', |
| 4009 ''' | 4069 ''' |
| 4010 const topLevel = 3; | 4070 const topLevel = 3; |
| 4011 class C { | 4071 class C { |
| 4012 String field = topLevel; | 4072 String field = topLevel; |
| 4013 } | 4073 } |
| 4014 '''); | 4074 '''); |
| 4015 computeResult(new LibrarySpecificUnit(source, source), VERIFY_ERRORS); | 4075 computeResult(new LibrarySpecificUnit(source, source), VERIFY_ERRORS); |
| 4016 // validate | 4076 // validate |
| 4017 _fillErrorListener(VERIFY_ERRORS); | 4077 _fillErrorListener(VERIFY_ERRORS); |
| 4018 errorListener.assertErrorsWithCodes( | 4078 |
| 4019 <ErrorCode>[StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 4079 var errors = errorListener.errors; |
| 4080 expect(errors.length, 1); |
| 4081 expect(errors[0].errorCode, StaticTypeWarningCode.INVALID_ASSIGNMENT); |
| 4020 } | 4082 } |
| 4021 | 4083 |
| 4022 test_perform_verifyError() { | 4084 test_perform_verifyError() { |
| 4023 Source source = newSource( | 4085 Source source = newSource( |
| 4024 '/test.dart', | 4086 '/test.dart', |
| 4025 ''' | 4087 ''' |
| 4026 main() { | 4088 main() { |
| 4027 if (42) { | 4089 if (42) { |
| 4028 print('Not bool!'); | 4090 print('Not bool!'); |
| 4029 } | 4091 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4248 /** | 4310 /** |
| 4249 * Fill [errorListener] with [result] errors in the current [task]. | 4311 * Fill [errorListener] with [result] errors in the current [task]. |
| 4250 */ | 4312 */ |
| 4251 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4313 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4252 List<AnalysisError> errors = task.outputs[result]; | 4314 List<AnalysisError> errors = task.outputs[result]; |
| 4253 expect(errors, isNotNull, reason: result.name); | 4315 expect(errors, isNotNull, reason: result.name); |
| 4254 errorListener = new GatheringErrorListener(); | 4316 errorListener = new GatheringErrorListener(); |
| 4255 errorListener.addAll(errors); | 4317 errorListener.addAll(errors); |
| 4256 } | 4318 } |
| 4257 } | 4319 } |
| OLD | NEW |