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 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 CompilationUnit unit = _resolveSource(source); | 1260 CompilationUnit unit = _resolveSource(source); |
1257 // Compute the constant value of the annotation on C. | 1261 // Compute the constant value of the annotation on C. |
1258 EvaluationResultImpl evaluationResult = | 1262 EvaluationResultImpl evaluationResult = |
1259 computeClassAnnotation(source, unit, 'C'); | 1263 computeClassAnnotation(source, unit, 'C'); |
1260 // And check that it has the expected value. | 1264 // And check that it has the expected value. |
1261 expect(evaluationResult, isNotNull); | 1265 expect(evaluationResult, isNotNull); |
1262 expect(evaluationResult.value, isNotNull); | 1266 expect(evaluationResult.value, isNotNull); |
1263 expect(evaluationResult.value.type, isNotNull); | 1267 expect(evaluationResult.value.type, isNotNull); |
1264 expect(evaluationResult.value.type.name, 'D'); | 1268 expect(evaluationResult.value.type.name, 'D'); |
1265 expect(evaluationResult.value.fields, contains('value')); | 1269 expect(evaluationResult.value.fields, contains('value')); |
1266 expect(evaluationResult.value.fields['value'].intValue, 1); | 1270 expect(evaluationResult.value.fields['value'].toIntValue(), 1); |
1267 } | 1271 } |
1268 | 1272 |
1269 test_annotation_without_args() { | 1273 test_annotation_without_args() { |
1270 Source source = newSource( | 1274 Source source = newSource( |
1271 '/test.dart', | 1275 '/test.dart', |
1272 ''' | 1276 ''' |
1273 const x = 1; | 1277 const x = 1; |
1274 @x class C {} | 1278 @x class C {} |
1275 '''); | 1279 '''); |
1276 // First compute the resolved unit for the source. | 1280 // First compute the resolved unit for the source. |
1277 CompilationUnit unit = _resolveSource(source); | 1281 CompilationUnit unit = _resolveSource(source); |
1278 // Compute the constant value of the annotation on C. | 1282 // Compute the constant value of the annotation on C. |
1279 EvaluationResultImpl evaluationResult = | 1283 EvaluationResultImpl evaluationResult = |
1280 computeClassAnnotation(source, unit, 'C'); | 1284 computeClassAnnotation(source, unit, 'C'); |
1281 // And check that it has the expected value. | 1285 // And check that it has the expected value. |
1282 expect(evaluationResult, isNotNull); | 1286 expect(evaluationResult, isNotNull); |
1283 expect(evaluationResult.value, isNotNull); | 1287 expect(evaluationResult.value, isNotNull); |
1284 expect(evaluationResult.value.intValue, 1); | 1288 expect(evaluationResult.value.toIntValue(), 1); |
1285 } | 1289 } |
1286 | 1290 |
1287 test_circular_reference() { | 1291 test_circular_reference() { |
1288 _checkCircularities( | 1292 _checkCircularities( |
1289 'x', | 1293 'x', |
1290 ['y'], | 1294 ['y'], |
1291 ''' | 1295 ''' |
1292 const x = y + 1; | 1296 const x = y + 1; |
1293 const y = x + 1; | 1297 const y = x + 1; |
1294 '''); | 1298 '''); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 | 1335 |
1332 test_dependency() { | 1336 test_dependency() { |
1333 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1337 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( |
1334 'x', | 1338 'x', |
1335 ''' | 1339 ''' |
1336 const x = y + 1; | 1340 const x = y + 1; |
1337 const y = 1; | 1341 const y = 1; |
1338 '''); | 1342 '''); |
1339 expect(evaluationResult, isNotNull); | 1343 expect(evaluationResult, isNotNull); |
1340 expect(evaluationResult.value, isNotNull); | 1344 expect(evaluationResult.value, isNotNull); |
1341 expect(evaluationResult.value.intValue, 2); | 1345 expect(evaluationResult.value.toIntValue(), 2); |
1342 } | 1346 } |
1343 | 1347 |
1344 test_external_const_factory() { | 1348 test_external_const_factory() { |
1345 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1349 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( |
1346 'x', | 1350 'x', |
1347 ''' | 1351 ''' |
1348 const x = const C.foo(); | 1352 const x = const C.foo(); |
1349 | 1353 |
1350 class C extends B { | 1354 class C extends B { |
1351 external const factory C.foo(); | 1355 external const factory C.foo(); |
1352 } | 1356 } |
1353 | 1357 |
1354 class B {} | 1358 class B {} |
1355 '''); | 1359 '''); |
1356 expect(evaluationResult, isNotNull); | 1360 expect(evaluationResult, isNotNull); |
1357 } | 1361 } |
1358 | 1362 |
1359 test_simple_constant() { | 1363 test_simple_constant() { |
1360 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1364 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( |
1361 'x', | 1365 'x', |
1362 ''' | 1366 ''' |
1363 const x = 1; | 1367 const x = 1; |
1364 '''); | 1368 '''); |
1365 expect(evaluationResult, isNotNull); | 1369 expect(evaluationResult, isNotNull); |
1366 expect(evaluationResult.value, isNotNull); | 1370 expect(evaluationResult.value, isNotNull); |
1367 expect(evaluationResult.value.intValue, 1); | 1371 expect(evaluationResult.value.toIntValue(), 1); |
1368 } | 1372 } |
1369 | 1373 |
1370 void _checkCircularities( | 1374 void _checkCircularities( |
1371 String variableName, List<String> otherVariables, String content) { | 1375 String variableName, List<String> otherVariables, String content) { |
1372 // Evaluating the first constant should produce an error. | 1376 // Evaluating the first constant should produce an error. |
1373 CompilationUnit unit = _resolveUnit(content); | 1377 CompilationUnit unit = _resolveUnit(content); |
1374 _expectCircularityError(_evaluateConstant(unit, variableName)); | 1378 _expectCircularityError(_evaluateConstant(unit, variableName)); |
1375 // And all the other constants involved in the strongly connected component | 1379 // And all the other constants involved in the strongly connected component |
1376 // should be set to the same error state. | 1380 // should be set to the same error state. |
1377 for (String otherVariableName in otherVariables) { | 1381 for (String otherVariableName in otherVariables) { |
(...skipping 459 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 usedElements = outputs[USED_IMPORTED_ELEMENTS]; | 1905 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
1901 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1906 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
1902 } | 1907 } |
1903 } | 1908 } |
1904 | 1909 |
1905 @reflectiveTest | 1910 @reflectiveTest |
1906 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { | 1911 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { |
1907 UsedLocalElements usedElements; | 1912 UsedLocalElements usedElements; |
1908 Set<String> usedElementNames; | 1913 Set<String> usedElementNames; |
1909 | 1914 |
1910 fail_perform_forPart_afterLibraryUpdate() { | 1915 test_perform_forPart_afterLibraryUpdate() { |
1911 Source libSource = newSource( | 1916 Source libSource = newSource( |
1912 '/my_lib.dart', | 1917 '/my_lib.dart', |
1913 ''' | 1918 ''' |
1914 library my_lib; | 1919 library my_lib; |
1915 part 'my_part.dart'; | 1920 part 'my_part.dart'; |
1916 foo() => null; | 1921 foo() => null; |
1917 class _LocalClass {} | 1922 class _LocalClass {} |
1918 '''); | 1923 '''); |
1919 Source partSource = newSource( | 1924 Source partSource = newSource( |
1920 '/my_part.dart', | 1925 '/my_part.dart', |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2242 void enableLints() { | 2247 void enableLints() { |
2243 AnalysisOptionsImpl options = context.analysisOptions; | 2248 AnalysisOptionsImpl options = context.analysisOptions; |
2244 options.lint = true; | 2249 options.lint = true; |
2245 context.analysisOptions = options; | 2250 context.analysisOptions = options; |
2246 } | 2251 } |
2247 | 2252 |
2248 @override | 2253 @override |
2249 void setUp() { | 2254 void setUp() { |
2250 super.setUp(); | 2255 super.setUp(); |
2251 enableLints(); | 2256 enableLints(); |
| 2257 setLints(context, [new GenerateLintsTaskTest_TestLinter()]); |
2252 } | 2258 } |
2253 | 2259 |
2254 @override | 2260 @override |
2255 void tearDown() { | 2261 void tearDown() { |
2256 LintGenerator.LINTERS.clear(); | 2262 setLints(context, []); |
2257 super.tearDown(); | 2263 super.tearDown(); |
2258 } | 2264 } |
2259 | 2265 |
2260 test_camel_case_types() { | 2266 test_camel_case_types() { |
2261 Source source = newSource( | 2267 Source source = newSource( |
2262 '/test.dart', | 2268 '/test.dart', |
2263 ''' | 2269 ''' |
2264 class a { } | 2270 class a { } |
2265 '''); | 2271 '''); |
2266 | 2272 |
2267 LintGenerator.LINTERS.clear(); | |
2268 LintGenerator.LINTERS.add(new GenerateLintsTaskTest_TestLinter()); | |
2269 | |
2270 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2273 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
2271 computeResult(target, LINTS, matcher: isGenerateLintsTask); | 2274 computeResult(target, LINTS, matcher: isGenerateLintsTask); |
2272 // validate | 2275 // validate |
2273 _fillErrorListener(LINTS); | 2276 _fillErrorListener(LINTS); |
2274 errorListener.assertErrorsWithCodes(<ErrorCode>[_testLintCode]); | 2277 errorListener.assertErrorsWithCodes(<ErrorCode>[_testLintCode]); |
2275 } | 2278 } |
2276 } | 2279 } |
2277 | 2280 |
2278 class GenerateLintsTaskTest_AstVisitor extends SimpleAstVisitor { | 2281 class GenerateLintsTaskTest_AstVisitor extends SimpleAstVisitor { |
2279 Linter linter; | 2282 Linter linter; |
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3965 expect(decl.initializer.staticType, intType); | 3968 expect(decl.initializer.staticType, intType); |
3966 | 3969 |
3967 ExpressionStatement statement = statements[1]; | 3970 ExpressionStatement statement = statements[1]; |
3968 AssignmentExpression assgn = statement.expression; | 3971 AssignmentExpression assgn = statement.expression; |
3969 expect(assgn.leftHandSide.staticType, intType); | 3972 expect(assgn.leftHandSide.staticType, intType); |
3970 expect(assgn.rightHandSide.staticType, stringType); | 3973 expect(assgn.rightHandSide.staticType, stringType); |
3971 } | 3974 } |
3972 } | 3975 } |
3973 | 3976 |
3974 @reflectiveTest | 3977 @reflectiveTest |
| 3978 class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 3979 @override |
| 3980 void setUp() { |
| 3981 super.setUp(); |
| 3982 enableStrongMode(); |
| 3983 } |
| 3984 |
| 3985 void test_perform_recordDynamicInvoke() { |
| 3986 enableStrongMode(); |
| 3987 AnalysisTarget source = newSource( |
| 3988 '/test.dart', |
| 3989 ''' |
| 3990 void main() { |
| 3991 dynamic a = []; |
| 3992 a[0]; |
| 3993 } |
| 3994 '''); |
| 3995 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 3996 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 3997 |
| 3998 // validate |
| 3999 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4000 expect(errorListener.errors, isEmpty); |
| 4001 |
| 4002 List<Statement> statements = getStatementsInTopLevelFunction(unit, "main"); |
| 4003 ExpressionStatement statement = statements[1]; |
| 4004 IndexExpression idx = statement.expression; |
| 4005 expect(DynamicInvoke.get(idx.target), isNotNull); |
| 4006 expect(DynamicInvoke.get(idx.target), isNotNull); |
| 4007 expect(DynamicInvoke.get(idx.target), isTrue); |
| 4008 } |
| 4009 |
| 4010 void test_perform_verifyError() { |
| 4011 enableStrongMode(); |
| 4012 AnalysisTarget source = newSource( |
| 4013 '/test.dart', |
| 4014 ''' |
| 4015 int topLevel = 3; |
| 4016 class C { |
| 4017 String field = topLevel; |
| 4018 } |
| 4019 '''); |
| 4020 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 4021 // validate |
| 4022 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4023 |
| 4024 var errors = errorListener.errors; |
| 4025 expect(errors.length, 1); |
| 4026 expect(errors[0].errorCode.name, "dev_compiler.StaticTypeError"); |
| 4027 } |
| 4028 } |
| 4029 |
| 4030 @reflectiveTest |
3975 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 4031 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
3976 test_perform_constantError() { | 4032 test_perform_constantError() { |
3977 Source source = newSource( | 4033 Source source = newSource( |
3978 '/test.dart', | 4034 '/test.dart', |
3979 ''' | 4035 ''' |
3980 main(int p) { | 4036 main(int p) { |
3981 const v = p; | 4037 const v = p; |
3982 } | 4038 } |
3983 '''); | 4039 '''); |
3984 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4040 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
(...skipping 25 matching lines...) Expand all Loading... |
4010 '/test.dart', | 4066 '/test.dart', |
4011 ''' | 4067 ''' |
4012 const topLevel = 3; | 4068 const topLevel = 3; |
4013 class C { | 4069 class C { |
4014 String field = topLevel; | 4070 String field = topLevel; |
4015 } | 4071 } |
4016 '''); | 4072 '''); |
4017 computeResult(new LibrarySpecificUnit(source, source), VERIFY_ERRORS); | 4073 computeResult(new LibrarySpecificUnit(source, source), VERIFY_ERRORS); |
4018 // validate | 4074 // validate |
4019 _fillErrorListener(VERIFY_ERRORS); | 4075 _fillErrorListener(VERIFY_ERRORS); |
4020 errorListener.assertErrorsWithCodes( | 4076 |
4021 <ErrorCode>[StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 4077 var errors = errorListener.errors; |
| 4078 expect(errors.length, 1); |
| 4079 expect(errors[0].errorCode, StaticTypeWarningCode.INVALID_ASSIGNMENT); |
4022 } | 4080 } |
4023 | 4081 |
4024 test_perform_verifyError() { | 4082 test_perform_verifyError() { |
4025 Source source = newSource( | 4083 Source source = newSource( |
4026 '/test.dart', | 4084 '/test.dart', |
4027 ''' | 4085 ''' |
4028 main() { | 4086 main() { |
4029 if (42) { | 4087 if (42) { |
4030 print('Not bool!'); | 4088 print('Not bool!'); |
4031 } | 4089 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4250 /** | 4308 /** |
4251 * Fill [errorListener] with [result] errors in the current [task]. | 4309 * Fill [errorListener] with [result] errors in the current [task]. |
4252 */ | 4310 */ |
4253 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4311 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
4254 List<AnalysisError> errors = task.outputs[result]; | 4312 List<AnalysisError> errors = task.outputs[result]; |
4255 expect(errors, isNotNull, reason: result.name); | 4313 expect(errors, isNotNull, reason: result.name); |
4256 errorListener = new GatheringErrorListener(); | 4314 errorListener = new GatheringErrorListener(); |
4257 errorListener.addAll(errors); | 4315 errorListener.addAll(errors); |
4258 } | 4316 } |
4259 } | 4317 } |
OLD | NEW |