| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.compile_time_error_code_test; | 5 library analyzer.test.generated.compile_time_error_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart' show expect; | 10 import 'package:unittest/unittest.dart' show expect; |
| 11 | 11 |
| 12 import '../reflective_tests.dart'; | 12 import '../reflective_tests.dart'; |
| 13 import '../utils.dart'; | 13 import '../utils.dart'; |
| 14 import 'resolver_test.dart'; | 14 import 'resolver_test.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; |
| 15 | 16 |
| 16 main() { | 17 main() { |
| 17 initializeTestEnvironment(); | 18 initializeTestEnvironment(); |
| 18 runReflectiveTests(CompileTimeErrorCodeTest); | 19 runReflectiveTests(CompileTimeErrorCodeTest); |
| 19 } | 20 } |
| 20 | 21 |
| 21 @reflectiveTest | 22 @reflectiveTest |
| 22 class CompileTimeErrorCodeTest extends ResolverTestCase { | 23 class CompileTimeErrorCodeTest extends ResolverTestCase { |
| 23 void fail_awaitInWrongContext_sync() { | 24 void fail_awaitInWrongContext_sync() { |
| 24 // This test requires better error recovery than we currently have. In | 25 // This test requires better error recovery than we currently have. In |
| (...skipping 6012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6037 computeLibrarySourceErrors(source); | 6038 computeLibrarySourceErrors(source); |
| 6038 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 6039 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 6039 } | 6040 } |
| 6040 | 6041 |
| 6041 void test_uriDoesNotExist_import() { | 6042 void test_uriDoesNotExist_import() { |
| 6042 Source source = addSource("import 'unknown.dart';"); | 6043 Source source = addSource("import 'unknown.dart';"); |
| 6043 computeLibrarySourceErrors(source); | 6044 computeLibrarySourceErrors(source); |
| 6044 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 6045 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 6045 } | 6046 } |
| 6046 | 6047 |
| 6047 void test_uriDoesNotExist_import_then_fixed() { | 6048 void test_uriDoesNotExist_import_disappears_when_fixed() { |
| 6048 Source source = addSource("import 'target.dart';"); | 6049 Source source = addSource("import 'target.dart';"); |
| 6049 computeLibrarySourceErrors(source); | 6050 computeLibrarySourceErrors(source); |
| 6050 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 6051 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 6051 | 6052 |
| 6052 // Check that the file is represented as missing. | 6053 // Check that the file is represented as missing. |
| 6053 Source target = | 6054 Source target = |
| 6054 analysisContext2.getSourcesWithFullName("/target.dart").first; | 6055 analysisContext2.getSourcesWithFullName("/target.dart").first; |
| 6055 expect(analysisContext2.getModificationStamp(target), -1); | 6056 expect(analysisContext2.getModificationStamp(target), -1); |
| 6056 | 6057 |
| 6057 // Add an overlay in the same way as AnalysisServer. | 6058 // Add an overlay in the same way as AnalysisServer. |
| 6058 analysisContext2 | 6059 analysisContext2 |
| 6059 ..setContents(target, "") | 6060 ..setContents(target, "") |
| 6060 ..handleContentsChanged(target, null, "", true); | 6061 ..handleContentsChanged(target, null, "", true); |
| 6061 | 6062 |
| 6062 // Make sure the error goes away. | 6063 // Make sure the error goes away. |
| 6063 // TODO(skybrian) why isn't there an unused import hint? | |
| 6064 computeLibrarySourceErrors(source); | 6064 computeLibrarySourceErrors(source); |
| 6065 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 6065 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 6066 } | 6066 } |
| 6067 | 6067 |
| 6068 void test_uriDoesNotExist_import_appears_after_deleting_target() { |
| 6069 Source test = addSource("import 'target.dart';"); |
| 6070 Source target = addNamedSource("/target.dart", ""); |
| 6071 computeLibrarySourceErrors(test); |
| 6072 assertErrors(test, [HintCode.UNUSED_IMPORT]); |
| 6073 |
| 6074 // Remove the overlay in the same way as AnalysisServer. |
| 6075 analysisContext2.setContents(target, null); |
| 6076 ChangeSet changeSet = new ChangeSet()..removedSource(target); |
| 6077 analysisContext2.applyChanges(changeSet); |
| 6078 |
| 6079 computeLibrarySourceErrors(test); |
| 6080 assertErrors(test, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 6081 } |
| 6082 |
| 6068 void test_uriDoesNotExist_part() { | 6083 void test_uriDoesNotExist_part() { |
| 6069 Source source = addSource(r''' | 6084 Source source = addSource(r''' |
| 6070 library lib; | 6085 library lib; |
| 6071 part 'unknown.dart';'''); | 6086 part 'unknown.dart';'''); |
| 6072 computeLibrarySourceErrors(source); | 6087 computeLibrarySourceErrors(source); |
| 6073 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 6088 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 6074 } | 6089 } |
| 6075 | 6090 |
| 6076 void test_uriWithInterpolation_constant() { | 6091 void test_uriWithInterpolation_constant() { |
| 6077 Source source = addSource("import 'stuff_\$platform.dart';"); | 6092 Source source = addSource("import 'stuff_\$platform.dart';"); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6306 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 6321 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 6307 verify([source]); | 6322 verify([source]); |
| 6308 reset(); | 6323 reset(); |
| 6309 } | 6324 } |
| 6310 | 6325 |
| 6311 void _check_wrongNumberOfParametersForOperator1(String name) { | 6326 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 6312 _check_wrongNumberOfParametersForOperator(name, ""); | 6327 _check_wrongNumberOfParametersForOperator(name, ""); |
| 6313 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 6328 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 6314 } | 6329 } |
| 6315 } | 6330 } |
| OLD | NEW |