| 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 24 matching lines...) Expand all Loading... |
| 35 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 35 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 36 runReflectiveTests(BuildDirectiveElementsTaskTest); | 36 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 37 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 37 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 38 runReflectiveTests(BuildSourceClosuresTaskTest); | 38 runReflectiveTests(BuildSourceClosuresTaskTest); |
| 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(GatherUsedImportedElementsTaskTest); |
| 45 runReflectiveTests(GatherUsedLocalElementsTaskTest); | 46 runReflectiveTests(GatherUsedLocalElementsTaskTest); |
| 46 runReflectiveTests(GenerateHintsTaskTest); | 47 runReflectiveTests(GenerateHintsTaskTest); |
| 47 runReflectiveTests(ParseDartTaskTest); | 48 runReflectiveTests(ParseDartTaskTest); |
| 48 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 49 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 49 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 50 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 50 runReflectiveTests(ResolveReferencesTaskTest); | 51 runReflectiveTests(ResolveReferencesTaskTest); |
| 51 runReflectiveTests(ResolveVariableReferencesTaskTest); | 52 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 52 runReflectiveTests(ScanDartTaskTest); | 53 runReflectiveTests(ScanDartTaskTest); |
| 53 runReflectiveTests(VerifyUnitTaskTest); | 54 runReflectiveTests(VerifyUnitTaskTest); |
| 54 } | 55 } |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 // validate | 1144 // validate |
| 1144 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; | 1145 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; |
| 1145 expect(typeProvider, isNotNull); | 1146 expect(typeProvider, isNotNull); |
| 1146 expect(typeProvider.boolType, isNotNull); | 1147 expect(typeProvider.boolType, isNotNull); |
| 1147 expect(typeProvider.intType, isNotNull); | 1148 expect(typeProvider.intType, isNotNull); |
| 1148 expect(typeProvider.futureType, isNotNull); | 1149 expect(typeProvider.futureType, isNotNull); |
| 1149 } | 1150 } |
| 1150 } | 1151 } |
| 1151 | 1152 |
| 1152 @reflectiveTest | 1153 @reflectiveTest |
| 1154 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { |
| 1155 UsedImportedElements usedElements; |
| 1156 Set<String> usedElementNames; |
| 1157 |
| 1158 test_perform() { |
| 1159 _newSource('/a.dart', r''' |
| 1160 library lib_a; |
| 1161 class A {} |
| 1162 '''); |
| 1163 _newSource('/b.dart', r''' |
| 1164 library lib_b; |
| 1165 class B {} |
| 1166 '''); |
| 1167 Source source = _newSource('/test.dart', r''' |
| 1168 import 'a.dart'; |
| 1169 import 'b.dart'; |
| 1170 main() { |
| 1171 new A(); |
| 1172 }'''); |
| 1173 _computeUsedElements(source); |
| 1174 // validate |
| 1175 expect(usedElementNames, unorderedEquals(['A'])); |
| 1176 } |
| 1177 |
| 1178 void _computeUsedElements(Source source) { |
| 1179 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1180 _computeResult(target, USED_IMPORTED_ELEMENTS); |
| 1181 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); |
| 1182 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
| 1183 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1184 } |
| 1185 } |
| 1186 |
| 1187 @reflectiveTest |
| 1153 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { | 1188 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { |
| 1154 UsedLocalElements usedElements; | 1189 UsedLocalElements usedElements; |
| 1155 Set<String> usedElementNames; | 1190 Set<String> usedElementNames; |
| 1156 | 1191 |
| 1157 test_perform_localVariable() { | 1192 test_perform_localVariable() { |
| 1158 Source source = _newSource('/test.dart', r''' | 1193 Source source = _newSource('/test.dart', r''' |
| 1159 main() { | 1194 main() { |
| 1160 var v1 = 1; | 1195 var v1 = 1; |
| 1161 var v2 = 2; | 1196 var v2 = 2; |
| 1162 print(v2); | 1197 print(v2); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 } | 1268 } |
| 1234 '''); | 1269 '''); |
| 1235 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1270 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1236 _computeResult(target, HINTS); | 1271 _computeResult(target, HINTS); |
| 1237 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1272 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1238 // validate | 1273 // validate |
| 1239 _fillErrorListener(HINTS); | 1274 _fillErrorListener(HINTS); |
| 1240 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); | 1275 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); |
| 1241 } | 1276 } |
| 1242 | 1277 |
| 1278 test_perform_imports_duplicateImport() { |
| 1279 _newSource('/a.dart', r''' |
| 1280 library lib_a; |
| 1281 class A {} |
| 1282 '''); |
| 1283 Source source = _newSource('/test.dart', r''' |
| 1284 import 'a.dart'; |
| 1285 import 'a.dart'; |
| 1286 main() { |
| 1287 new A(); |
| 1288 } |
| 1289 '''); |
| 1290 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1291 _computeResult(target, HINTS); |
| 1292 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1293 // validate |
| 1294 _fillErrorListener(HINTS); |
| 1295 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); |
| 1296 } |
| 1297 |
| 1298 test_perform_imports_unusedImport_one() { |
| 1299 _newSource('/a.dart', r''' |
| 1300 library lib_a; |
| 1301 class A {} |
| 1302 '''); |
| 1303 _newSource('/b.dart', r''' |
| 1304 library lib_b; |
| 1305 class B {} |
| 1306 '''); |
| 1307 Source source = _newSource('/test.dart', r''' |
| 1308 import 'a.dart'; |
| 1309 import 'b.dart'; |
| 1310 main() { |
| 1311 new A(); |
| 1312 }'''); |
| 1313 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1314 _computeResult(target, HINTS); |
| 1315 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1316 // validate |
| 1317 _fillErrorListener(HINTS); |
| 1318 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); |
| 1319 } |
| 1320 |
| 1321 test_perform_imports_unusedImport_zero() { |
| 1322 _newSource('/a.dart', r''' |
| 1323 library lib_a; |
| 1324 class A {} |
| 1325 '''); |
| 1326 Source source = _newSource('/test.dart', r''' |
| 1327 import 'a.dart'; |
| 1328 main() { |
| 1329 new A(); |
| 1330 }'''); |
| 1331 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1332 _computeResult(target, HINTS); |
| 1333 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1334 // validate |
| 1335 _fillErrorListener(HINTS); |
| 1336 errorListener.assertNoErrors(); |
| 1337 } |
| 1338 |
| 1243 test_perform_overrideVerifier() { | 1339 test_perform_overrideVerifier() { |
| 1244 Source source = _newSource('/test.dart', ''' | 1340 Source source = _newSource('/test.dart', ''' |
| 1245 class A {} | 1341 class A {} |
| 1246 class B { | 1342 class B { |
| 1247 @override | 1343 @override |
| 1248 m() {} | 1344 m() {} |
| 1249 } | 1345 } |
| 1250 '''); | 1346 '''); |
| 1251 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1347 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1252 _computeResult(target, HINTS); | 1348 _computeResult(target, HINTS); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1264 } | 1360 } |
| 1265 '''); | 1361 '''); |
| 1266 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1362 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1267 _computeResult(target, HINTS); | 1363 _computeResult(target, HINTS); |
| 1268 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1364 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1269 // validate | 1365 // validate |
| 1270 _fillErrorListener(HINTS); | 1366 _fillErrorListener(HINTS); |
| 1271 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); | 1367 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); |
| 1272 } | 1368 } |
| 1273 | 1369 |
| 1274 test_perform_unusedElements_class() { | 1370 test_perform_unusedLocalElements_class() { |
| 1275 Source source = _newSource('/test.dart', ''' | 1371 Source source = _newSource('/test.dart', ''' |
| 1276 class _A {} | 1372 class _A {} |
| 1277 class _B {} | 1373 class _B {} |
| 1278 main() { | 1374 main() { |
| 1279 new _A(); | 1375 new _A(); |
| 1280 } | 1376 } |
| 1281 '''); | 1377 '''); |
| 1282 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1378 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1283 _computeResult(target, HINTS); | 1379 _computeResult(target, HINTS); |
| 1284 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1380 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1285 // validate | 1381 // validate |
| 1286 _fillErrorListener(HINTS); | 1382 _fillErrorListener(HINTS); |
| 1287 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); | 1383 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); |
| 1288 } | 1384 } |
| 1289 | 1385 |
| 1290 test_perform_unusedElements_localVariable() { | 1386 test_perform_unusedLocalElements_localVariable() { |
| 1291 Source source = _newSource('/test.dart', ''' | 1387 Source source = _newSource('/test.dart', ''' |
| 1292 main() { | 1388 main() { |
| 1293 var v = 42; | 1389 var v = 42; |
| 1294 } | 1390 } |
| 1295 '''); | 1391 '''); |
| 1296 LibraryUnitTarget target = new LibraryUnitTarget(source, source); | 1392 LibraryUnitTarget target = new LibraryUnitTarget(source, source); |
| 1297 _computeResult(target, HINTS); | 1393 _computeResult(target, HINTS); |
| 1298 expect(task, new isInstanceOf<GenerateHintsTask>()); | 1394 expect(task, new isInstanceOf<GenerateHintsTask>()); |
| 1299 // validate | 1395 // validate |
| 1300 _fillErrorListener(HINTS); | 1396 _fillErrorListener(HINTS); |
| 1301 errorListener | 1397 errorListener |
| 1302 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); | 1398 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); |
| 1303 } | 1399 } |
| 1304 | 1400 |
| 1305 test_perform_unusedElements_method() { | 1401 test_perform_unusedLocalElements_method() { |
| 1306 Source source = _newSource('/my_lib.dart', ''' | 1402 Source source = _newSource('/my_lib.dart', ''' |
| 1307 library my_lib; | 1403 library my_lib; |
| 1308 part 'my_part.dart'; | 1404 part 'my_part.dart'; |
| 1309 class A { | 1405 class A { |
| 1310 _ma() {} | 1406 _ma() {} |
| 1311 _mb() {} | 1407 _mb() {} |
| 1312 _mc() {} | 1408 _mc() {} |
| 1313 } | 1409 } |
| 1314 '''); | 1410 '''); |
| 1315 _newSource('/my_part.dart', ''' | 1411 _newSource('/my_part.dart', ''' |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); | 1859 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); |
| 1764 taskManager.addTaskDescriptor(BuildLibraryConstructorsTask.DESCRIPTOR); | 1860 taskManager.addTaskDescriptor(BuildLibraryConstructorsTask.DESCRIPTOR); |
| 1765 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); | 1861 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); |
| 1766 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); | 1862 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); |
| 1767 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); | 1863 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); |
| 1768 taskManager.addTaskDescriptor(BuildSourceClosuresTask.DESCRIPTOR); | 1864 taskManager.addTaskDescriptor(BuildSourceClosuresTask.DESCRIPTOR); |
| 1769 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); | 1865 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); |
| 1770 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); | 1866 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); |
| 1771 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); | 1867 taskManager.addTaskDescriptor(BuildFunctionTypeAliasesTask.DESCRIPTOR); |
| 1772 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); | 1868 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); |
| 1869 taskManager.addTaskDescriptor(GatherUsedImportedElementsTask.DESCRIPTOR); |
| 1773 taskManager.addTaskDescriptor(GatherUsedLocalElementsTask.DESCRIPTOR); | 1870 taskManager.addTaskDescriptor(GatherUsedLocalElementsTask.DESCRIPTOR); |
| 1774 taskManager.addTaskDescriptor(GenerateHintsTask.DESCRIPTOR); | 1871 taskManager.addTaskDescriptor(GenerateHintsTask.DESCRIPTOR); |
| 1775 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); | 1872 taskManager.addTaskDescriptor(ResolveUnitTypeNamesTask.DESCRIPTOR); |
| 1776 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); | 1873 taskManager.addTaskDescriptor(ResolveLibraryTypeNamesTask.DESCRIPTOR); |
| 1777 taskManager.addTaskDescriptor(ResolveReferencesTask.DESCRIPTOR); | 1874 taskManager.addTaskDescriptor(ResolveReferencesTask.DESCRIPTOR); |
| 1778 taskManager.addTaskDescriptor(ResolveVariableReferencesTask.DESCRIPTOR); | 1875 taskManager.addTaskDescriptor(ResolveVariableReferencesTask.DESCRIPTOR); |
| 1779 taskManager.addTaskDescriptor(VerifyUnitTask.DESCRIPTOR); | 1876 taskManager.addTaskDescriptor(VerifyUnitTask.DESCRIPTOR); |
| 1780 // prepare AnalysisDriver | 1877 // prepare AnalysisDriver |
| 1781 analysisDriver = new AnalysisDriver(taskManager, context); | 1878 analysisDriver = new AnalysisDriver(taskManager, context); |
| 1782 } | 1879 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1926 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1830 } | 1927 } |
| 1831 | 1928 |
| 1832 TimestampedData<String> getContents(Source source) => source.contents; | 1929 TimestampedData<String> getContents(Source source) => source.contents; |
| 1833 | 1930 |
| 1834 noSuchMethod(Invocation invocation) { | 1931 noSuchMethod(Invocation invocation) { |
| 1835 print('noSuchMethod: ${invocation.memberName}'); | 1932 print('noSuchMethod: ${invocation.memberName}'); |
| 1836 return super.noSuchMethod(invocation); | 1933 return super.noSuchMethod(invocation); |
| 1837 } | 1934 } |
| 1838 } | 1935 } |
| OLD | NEW |