| 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(ResolveVariableReferencesTaskTest); |
| 48 runReflectiveTests(ScanDartTaskTest); | 49 runReflectiveTests(ScanDartTaskTest); |
| 49 } | 50 } |
| 50 | 51 |
| 51 @reflectiveTest | 52 @reflectiveTest |
| 52 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { | 53 class BuildClassConstructorsTaskTest extends _AbstractDartTaskTest { |
| 53 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { | 54 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { |
| 54 Source source = _newSource('/test.dart', ''' | 55 Source source = _newSource('/test.dart', ''' |
| 55 class B { | 56 class B { |
| 56 B({x}); | 57 B({x}); |
| 57 } | 58 } |
| (...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 1234 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); |
| 1234 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 1235 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); |
| 1235 // validate | 1236 // validate |
| 1236 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 1237 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 1237 errorListener | 1238 errorListener |
| 1238 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 1239 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 1239 } | 1240 } |
| 1240 } | 1241 } |
| 1241 | 1242 |
| 1242 @reflectiveTest | 1243 @reflectiveTest |
| 1244 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 1245 test_perform_local() { |
| 1246 Source source = _newSource('/test.dart', ''' |
| 1247 main() { |
| 1248 var v1 = 1; |
| 1249 var v2 = 1; |
| 1250 var v3 = 1; |
| 1251 var v4 = 1; |
| 1252 v2 = 2; |
| 1253 v4 = 2; |
| 1254 localFunction() { |
| 1255 v3 = 3; |
| 1256 v4 = 3; |
| 1257 } |
| 1258 } |
| 1259 '''); |
| 1260 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1261 _computeResult(target, RESOLVED_UNIT5); |
| 1262 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1263 // validate |
| 1264 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1265 FunctionElement main = unit.element.functions[0]; |
| 1266 { |
| 1267 var v1 = main.localVariables[0] as VariableElementImpl; |
| 1268 expect(v1.isPotentiallyMutatedInClosure, isFalse); |
| 1269 expect(v1.isPotentiallyMutatedInScope, isFalse); |
| 1270 } |
| 1271 { |
| 1272 var v2 = main.localVariables[1] as VariableElementImpl; |
| 1273 expect(v2.isPotentiallyMutatedInClosure, isFalse); |
| 1274 expect(v2.isPotentiallyMutatedInScope, isTrue); |
| 1275 } |
| 1276 { |
| 1277 var v3 = main.localVariables[2] as VariableElementImpl; |
| 1278 expect(v3.isPotentiallyMutatedInClosure, isTrue); |
| 1279 expect(v3.isPotentiallyMutatedInScope, isTrue); |
| 1280 } |
| 1281 { |
| 1282 var v4 = main.localVariables[3] as VariableElementImpl; |
| 1283 expect(v4.isPotentiallyMutatedInClosure, isTrue); |
| 1284 expect(v4.isPotentiallyMutatedInScope, isTrue); |
| 1285 } |
| 1286 } |
| 1287 |
| 1288 test_perform_parameter() { |
| 1289 Source source = _newSource('/test.dart', ''' |
| 1290 main(p1, p2, p3, p4) { |
| 1291 p2 = 2; |
| 1292 p4 = 2; |
| 1293 localFunction() { |
| 1294 p3 = 3; |
| 1295 p4 = 3; |
| 1296 } |
| 1297 } |
| 1298 '''); |
| 1299 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1300 _computeResult(target, RESOLVED_UNIT5); |
| 1301 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); |
| 1302 // validate |
| 1303 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1304 FunctionElement main = unit.element.functions[0]; |
| 1305 { |
| 1306 var p1 = main.parameters[0] as VariableElementImpl; |
| 1307 expect(p1.isPotentiallyMutatedInClosure, isFalse); |
| 1308 expect(p1.isPotentiallyMutatedInScope, isFalse); |
| 1309 } |
| 1310 { |
| 1311 var p2 = main.parameters[1] as VariableElementImpl; |
| 1312 expect(p2.isPotentiallyMutatedInClosure, isFalse); |
| 1313 expect(p2.isPotentiallyMutatedInScope, isTrue); |
| 1314 } |
| 1315 { |
| 1316 var p3 = main.parameters[2] as VariableElementImpl; |
| 1317 expect(p3.isPotentiallyMutatedInClosure, isTrue); |
| 1318 expect(p3.isPotentiallyMutatedInScope, isTrue); |
| 1319 } |
| 1320 { |
| 1321 var p4 = main.parameters[3] as VariableElementImpl; |
| 1322 expect(p4.isPotentiallyMutatedInClosure, isTrue); |
| 1323 expect(p4.isPotentiallyMutatedInScope, isTrue); |
| 1324 } |
| 1325 } |
| 1326 } |
| 1327 |
| 1328 @reflectiveTest |
| 1243 class ScanDartTaskTest extends _AbstractDartTaskTest { | 1329 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| 1244 test_buildInputs() { | 1330 test_buildInputs() { |
| 1245 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(emptySource); | 1331 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(emptySource); |
| 1246 expect(inputs, isNotNull); | 1332 expect(inputs, isNotNull); |
| 1247 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); | 1333 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); |
| 1248 } | 1334 } |
| 1249 | 1335 |
| 1250 test_constructor() { | 1336 test_constructor() { |
| 1251 ScanDartTask task = new ScanDartTask(context, emptySource); | 1337 ScanDartTask task = new ScanDartTask(context, emptySource); |
| 1252 expect(task, isNotNull); | 1338 expect(task, isNotNull); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); | 1416 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); |
| 1331 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); | 1417 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); |
| 1332 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); | 1418 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); |
| 1333 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); | 1419 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); |
| 1334 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); | 1420 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); |
| 1335 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); | 1421 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); |
| 1336 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); | 1422 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); |
| 1337 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); | 1423 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); |
| 1338 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); | 1424 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); |
| 1339 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); | 1425 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); |
| 1426 taskManager.addTaskDescriptor(ResolveVariableReferencesTask.DESCRIPTOR); |
| 1340 // prepare AnalysisDriver | 1427 // prepare AnalysisDriver |
| 1341 analysisDriver = new AnalysisDriver(taskManager, context); | 1428 analysisDriver = new AnalysisDriver(taskManager, context); |
| 1342 } | 1429 } |
| 1343 | 1430 |
| 1344 void _computeResult(AnalysisTarget target, ResultDescriptor result) { | 1431 void _computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 1345 task = analysisDriver.computeResult(target, result); | 1432 task = analysisDriver.computeResult(target, result); |
| 1346 expect(task.caughtException, isNull); | 1433 expect(task.caughtException, isNull); |
| 1347 outputs = task.outputs; | 1434 outputs = task.outputs; |
| 1348 } | 1435 } |
| 1349 | 1436 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1476 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1390 } | 1477 } |
| 1391 | 1478 |
| 1392 TimestampedData<String> getContents(Source source) => source.contents; | 1479 TimestampedData<String> getContents(Source source) => source.contents; |
| 1393 | 1480 |
| 1394 noSuchMethod(Invocation invocation) { | 1481 noSuchMethod(Invocation invocation) { |
| 1395 print('noSuchMethod: ${invocation.memberName}'); | 1482 print('noSuchMethod: ${invocation.memberName}'); |
| 1396 return super.noSuchMethod(invocation); | 1483 return super.noSuchMethod(invocation); |
| 1397 } | 1484 } |
| 1398 } | 1485 } |
| OLD | NEW |