| 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'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 runReflectiveTests(BuildExportSourceClosureTaskTest); | 38 runReflectiveTests(BuildExportSourceClosureTaskTest); |
| 39 runReflectiveTests(BuildExportNamespaceTaskTest); | 39 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 40 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); | 40 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); |
| 41 runReflectiveTests(BuildLibraryConstructorsTaskTest); | 41 runReflectiveTests(BuildLibraryConstructorsTaskTest); |
| 42 runReflectiveTests(BuildLibraryElementTaskTest); | 42 runReflectiveTests(BuildLibraryElementTaskTest); |
| 43 runReflectiveTests(BuildPublicNamespaceTaskTest); | 43 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 44 runReflectiveTests(BuildTypeProviderTaskTest); | 44 runReflectiveTests(BuildTypeProviderTaskTest); |
| 45 runReflectiveTests(ParseDartTaskTest); | 45 runReflectiveTests(ParseDartTaskTest); |
| 46 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 46 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 47 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 47 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 48 runReflectiveTests(ResolveReferencesTaskTest); |
| 48 runReflectiveTests(ResolveVariableReferencesTaskTest); | 49 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 49 runReflectiveTests(ScanDartTaskTest); | 50 runReflectiveTests(ScanDartTaskTest); |
| 50 } | 51 } |
| 51 | 52 |
| 52 @reflectiveTest | 53 @reflectiveTest |
| 53 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { | 54 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { |
| 54 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { | 55 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { |
| 55 Source source = _newSource('/test.dart', ''' | 56 Source source = _newSource('/test.dart', ''' |
| 56 class B { | 57 class B { |
| 57 B({x}); | 58 B({x}); |
| (...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 expect(classB.supertype.displayName, 'A'); | 1192 expect(classB.supertype.displayName, 'A'); |
| 1192 } | 1193 } |
| 1193 { | 1194 { |
| 1194 ClassElement classC = library.getType('C'); | 1195 ClassElement classC = library.getType('C'); |
| 1195 expect(classC.supertype.displayName, 'A'); | 1196 expect(classC.supertype.displayName, 'A'); |
| 1196 } | 1197 } |
| 1197 } | 1198 } |
| 1198 } | 1199 } |
| 1199 | 1200 |
| 1200 @reflectiveTest | 1201 @reflectiveTest |
| 1202 class ResolveReferencesTaskTest extends _AbstractDartTaskTest { |
| 1203 test_perform() { |
| 1204 Source source = _newSource('/test.dart', ''' |
| 1205 class A { |
| 1206 m() {} |
| 1207 } |
| 1208 main(A a) { |
| 1209 a.m(); |
| 1210 } |
| 1211 '''); |
| 1212 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1213 // prepare unit and "a.m()" invocation |
| 1214 CompilationUnit unit; |
| 1215 MethodInvocation invocation; |
| 1216 { |
| 1217 _computeResult(target, RESOLVED_UNIT1); |
| 1218 unit = outputs[RESOLVED_UNIT1]; |
| 1219 // walk the AST |
| 1220 FunctionDeclaration function = unit.declarations[1]; |
| 1221 BlockFunctionBody body = function.functionExpression.body; |
| 1222 ExpressionStatement statement = body.block.statements[0]; |
| 1223 invocation = statement.expression; |
| 1224 // not resolved yet |
| 1225 expect(invocation.methodName.staticElement, isNull); |
| 1226 } |
| 1227 // fully resolve |
| 1228 { |
| 1229 _computeResult(target, RESOLVED_UNIT); |
| 1230 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 1231 expect(outputs[RESOLVED_UNIT], same(outputs[RESOLVED_UNIT])); |
| 1232 // a.m() is resolved now |
| 1233 expect(invocation.methodName.staticElement, isNotNull); |
| 1234 } |
| 1235 } |
| 1236 |
| 1237 test_perform_errors() { |
| 1238 Source source = _newSource('/test.dart', ''' |
| 1239 class A { |
| 1240 } |
| 1241 main(A a) { |
| 1242 a.unknownMethod(); |
| 1243 } |
| 1244 '''); |
| 1245 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1246 _computeResult(target, RESOLVED_UNIT); |
| 1247 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 1248 // validate |
| 1249 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
| 1250 errorListener.assertErrorsWithCodes( |
| 1251 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 1252 } |
| 1253 } |
| 1254 |
| 1255 @reflectiveTest |
| 1201 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 1256 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 1202 test_perform() { | 1257 test_perform() { |
| 1203 Source source = _newSource('/test.dart', ''' | 1258 Source source = _newSource('/test.dart', ''' |
| 1204 class A {} | 1259 class A {} |
| 1205 class B extends A {} | 1260 class B extends A {} |
| 1206 int f(String p) => p.length; | 1261 int f(String p) => p.length; |
| 1207 '''); | 1262 '''); |
| 1208 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1263 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1209 _computeResult(target, RESOLVED_UNIT4); | 1264 _computeResult(target, RESOLVED_UNIT4); |
| 1210 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1265 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); | 1471 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); |
| 1417 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); | 1472 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); |
| 1418 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); | 1473 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); |
| 1419 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); | 1474 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); |
| 1420 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); | 1475 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); |
| 1421 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); | 1476 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); |
| 1422 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); | 1477 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); |
| 1423 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); | 1478 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); |
| 1424 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); | 1479 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); |
| 1425 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); | 1480 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); |
| 1481 taskManager.addTaskDescriptor(ResolveReferencesTask.DESCRIPTOR); |
| 1426 taskManager.addTaskDescriptor(ResolveVariableReferencesTask.DESCRIPTOR); | 1482 taskManager.addTaskDescriptor(ResolveVariableReferencesTask.DESCRIPTOR); |
| 1427 // prepare AnalysisDriver | 1483 // prepare AnalysisDriver |
| 1428 analysisDriver = new AnalysisDriver(taskManager, context); | 1484 analysisDriver = new AnalysisDriver(taskManager, context); |
| 1429 } | 1485 } |
| 1430 | 1486 |
| 1431 void _computeResult(AnalysisTarget target, ResultDescriptor result) { | 1487 void _computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 1432 task = analysisDriver.computeResult(target, result); | 1488 task = analysisDriver.computeResult(target, result); |
| 1433 expect(task.caughtException, isNull); | 1489 expect(task.caughtException, isNull); |
| 1434 outputs = task.outputs; | 1490 outputs = task.outputs; |
| 1435 } | 1491 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1532 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1477 } | 1533 } |
| 1478 | 1534 |
| 1479 TimestampedData<String> getContents(Source source) => source.contents; | 1535 TimestampedData<String> getContents(Source source) => source.contents; |
| 1480 | 1536 |
| 1481 noSuchMethod(Invocation invocation) { | 1537 noSuchMethod(Invocation invocation) { |
| 1482 print('noSuchMethod: ${invocation.memberName}'); | 1538 print('noSuchMethod: ${invocation.memberName}'); |
| 1483 return super.noSuchMethod(invocation); | 1539 return super.noSuchMethod(invocation); |
| 1484 } | 1540 } |
| 1485 } | 1541 } |
| OLD | NEW |