| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.driver; | 5 library analyzer.test.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/error/error.dart'; | 12 import 'package:analyzer/error/error.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart'; | 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 15 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 15 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 16 import 'package:analyzer/src/dart/analysis/driver.dart'; | 16 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 17 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 17 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/status.dart'; | 18 import 'package:analyzer/src/dart/analysis/status.dart'; |
| 19 import 'package:analyzer/src/error/codes.dart'; | 19 import 'package:analyzer/src/error/codes.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; | 20 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; |
| 21 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
| 22 import 'package:analyzer/src/summary/idl.dart'; |
| 22 import 'package:convert/convert.dart'; | 23 import 'package:convert/convert.dart'; |
| 23 import 'package:crypto/crypto.dart'; | 24 import 'package:crypto/crypto.dart'; |
| 24 import 'package:test/test.dart'; | 25 import 'package:test/test.dart'; |
| 25 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 26 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 26 | 27 |
| 27 import '../../context/mock_sdk.dart'; | 28 import '../../context/mock_sdk.dart'; |
| 28 import 'base.dart'; | 29 import 'base.dart'; |
| 29 | 30 |
| 30 main() { | 31 main() { |
| 31 defineReflectiveSuite(() { | 32 defineReflectiveSuite(() { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 { | 431 { |
| 431 AnalysisError error = result.errors[0]; | 432 AnalysisError error = result.errors[0]; |
| 432 expect(error.offset, 13); | 433 expect(error.offset, 13); |
| 433 expect(error.length, 2); | 434 expect(error.length, 2); |
| 434 expect(error.errorCode, HintCode.UNUSED_LOCAL_VARIABLE); | 435 expect(error.errorCode, HintCode.UNUSED_LOCAL_VARIABLE); |
| 435 expect(error.message, "The value of the local variable 'vv' isn't used."); | 436 expect(error.message, "The value of the local variable 'vv' isn't used."); |
| 436 expect(error.correction, "Try removing the variable, or using it."); | 437 expect(error.correction, "Try removing the variable, or using it."); |
| 437 } | 438 } |
| 438 } | 439 } |
| 439 | 440 |
| 441 test_getResult_hasIndex() async { |
| 442 String content = r''' |
| 443 foo(int p) {} |
| 444 main() { |
| 445 foo(42); |
| 446 } |
| 447 '''; |
| 448 addTestFile(content); |
| 449 |
| 450 AnalysisResult result = await driver.getResult(testFile); |
| 451 |
| 452 AnalysisDriverUnitIndex index = result.index; |
| 453 int unitId = index.strings.indexOf('package:test/test.dart'); |
| 454 int fooId = index.strings.indexOf('foo'); |
| 455 expect(unitId, isNonNegative); |
| 456 expect(fooId, isNonNegative); |
| 457 } |
| 458 |
| 440 test_getResult_inferTypes_finalField() async { | 459 test_getResult_inferTypes_finalField() async { |
| 441 addTestFile( | 460 addTestFile( |
| 442 r''' | 461 r''' |
| 443 class C { | 462 class C { |
| 444 final f = 42; | 463 final f = 42; |
| 445 } | 464 } |
| 446 ''', | 465 ''', |
| 447 priority: true); | 466 priority: true); |
| 448 await _waitForIdle(); | 467 await _waitForIdle(); |
| 449 | 468 |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 await _waitForIdle(); | 1080 await _waitForIdle(); |
| 1062 | 1081 |
| 1063 expect(allResults, hasLength(1)); | 1082 expect(allResults, hasLength(1)); |
| 1064 AnalysisResult result = allResults.single; | 1083 AnalysisResult result = allResults.single; |
| 1065 expect(result.path, testFile); | 1084 expect(result.path, testFile); |
| 1066 expect(result.uri.toString(), 'package:test/test.dart'); | 1085 expect(result.uri.toString(), 'package:test/test.dart'); |
| 1067 expect(result.content, isNull); | 1086 expect(result.content, isNull); |
| 1068 expect(result.contentHash, _md5(content)); | 1087 expect(result.contentHash, _md5(content)); |
| 1069 expect(result.unit, isNull); | 1088 expect(result.unit, isNull); |
| 1070 expect(result.errors, hasLength(0)); | 1089 expect(result.errors, hasLength(0)); |
| 1090 expect(result.index, isNotNull); |
| 1071 } | 1091 } |
| 1072 | 1092 |
| 1073 test_results_status() async { | 1093 test_results_status() async { |
| 1074 addTestFile('int f() => 42;'); | 1094 addTestFile('int f() => 42;'); |
| 1075 await _waitForIdle(); | 1095 await _waitForIdle(); |
| 1076 | 1096 |
| 1077 expect(allStatuses, hasLength(2)); | 1097 expect(allStatuses, hasLength(2)); |
| 1078 expect(allStatuses[0].isAnalyzing, isTrue); | 1098 expect(allStatuses[0].isAnalyzing, isTrue); |
| 1079 expect(allStatuses[0].isIdle, isFalse); | 1099 expect(allStatuses[0].isIdle, isFalse); |
| 1080 expect(allStatuses[1].isAnalyzing, isFalse); | 1100 expect(allStatuses[1].isAnalyzing, isFalse); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 String _p(String path) => provider.convertPath(path); | 1190 String _p(String path) => provider.convertPath(path); |
| 1171 | 1191 |
| 1172 Future<Null> _waitForIdle() async { | 1192 Future<Null> _waitForIdle() async { |
| 1173 await idleStatusMonitor.signal; | 1193 await idleStatusMonitor.signal; |
| 1174 } | 1194 } |
| 1175 | 1195 |
| 1176 static String _md5(String content) { | 1196 static String _md5(String content) { |
| 1177 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 1197 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
| 1178 } | 1198 } |
| 1179 } | 1199 } |
| OLD | NEW |