| 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 import 'package:analyzer/src/generated/error.dart'; | 5 import 'package:analyzer/src/generated/error.dart'; |
| 6 import 'package:analyzer/src/generated/source.dart'; | 6 import 'package:analyzer/src/generated/source.dart'; |
| 7 import 'package:analyzer/src/generated/source_io.dart'; | 7 import 'package:analyzer/src/generated/source_io.dart'; |
| 8 | 8 |
| 9 import '../reflective_tests.dart'; | 9 import '../reflective_tests.dart'; |
| 10 import '../utils.dart'; | 10 import '../utils.dart'; |
| 11 import 'resolver_test.dart'; | 11 import 'resolver_test.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 initializeTestEnvironment(); | 14 initializeTestEnvironment(); |
| 15 runReflectiveTests(ErrorSuppressionTest); | 15 runReflectiveTests(ErrorSuppressionTest); |
| 16 } | 16 } |
| 17 | 17 |
| 18 @reflectiveTest | 18 @reflectiveTest |
| 19 class ErrorSuppressionTest extends ResolverTestCase { | 19 class ErrorSuppressionTest extends ResolverTestCase { |
| 20 void test_error_code_mismatch() { | 20 void test_error_code_mismatch() { |
| 21 Source source = addSource(''' | 21 Source source = addSource(''' |
| 22 //# ignore: const_initialized_with_non_constant_value | 22 // ignore: const_initialized_with_non_constant_value |
| 23 int x = ''; | 23 int x = ''; |
| 24 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 24 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 25 '''); | 25 '''); |
| 26 computeLibrarySourceErrors(source); | 26 computeLibrarySourceErrors(source); |
| 27 assertErrors(source, [ | 27 assertErrors(source, [ |
| 28 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 28 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 29 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 29 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 30 ]); | 30 ]); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void test_ignore_first() { | 33 void test_ignore_first() { |
| 34 Source source = addSource(''' | 34 Source source = addSource(''' |
| 35 //# ignore: invalid_assignment | 35 // ignore: invalid_assignment |
| 36 int x = ''; | 36 int x = ''; |
| 37 // ... but no ignore here ... | 37 // ... but no ignore here ... |
| 38 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 38 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 39 '''); | 39 '''); |
| 40 computeLibrarySourceErrors(source); | 40 computeLibrarySourceErrors(source); |
| 41 assertErrors(source, | 41 assertErrors(source, |
| 42 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 42 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void test_ignore_second() { | 45 void test_ignore_second() { |
| 46 Source source = addSource(''' | 46 Source source = addSource(''' |
| 47 //INVALID_ASSIGNMENT | 47 //INVALID_ASSIGNMENT |
| 48 int x = ''; | 48 int x = ''; |
| 49 //# ignore: const_initialized_with_non_constant_value | 49 // ignore: const_initialized_with_non_constant_value |
| 50 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 50 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 51 '''); | 51 '''); |
| 52 computeLibrarySourceErrors(source); | 52 computeLibrarySourceErrors(source); |
| 53 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 53 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void test_invalid_error_code() { | 56 void test_invalid_error_code() { |
| 57 Source source = addSource(''' | 57 Source source = addSource(''' |
| 58 //# ignore: right_format_wrong_code | 58 // ignore: right_format_wrong_code |
| 59 int x = ''; | 59 int x = ''; |
| 60 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 60 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 61 '''); | 61 '''); |
| 62 computeLibrarySourceErrors(source); | 62 computeLibrarySourceErrors(source); |
| 63 assertErrors(source, [ | 63 assertErrors(source, [ |
| 64 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 64 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 65 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 65 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 66 ]); | 66 ]); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void test_missing_error_codes() { | 69 void test_missing_error_codes() { |
| 70 Source source = addSource(''' | 70 Source source = addSource(''' |
| 71 int x = 3; | 71 int x = 3; |
| 72 //# ignore: | 72 // ignore: |
| 73 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 73 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 74 '''); | 74 '''); |
| 75 computeLibrarySourceErrors(source); | 75 computeLibrarySourceErrors(source); |
| 76 assertErrors(source, [ | 76 assertErrors(source, [ |
| 77 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 77 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 78 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 78 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 79 ]); | 79 ]); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void test_missing_metadata_prefix() { | 82 void test_missing_metadata_suffix() { |
| 83 Source source = addSource(''' | 83 Source source = addSource(''' |
| 84 // ignore: invalid_assignment | 84 // ignore invalid_assignment |
| 85 String y = 3; //INVALID_ASSIGNMENT | 85 String y = 3; //INVALID_ASSIGNMENT |
| 86 '''); | 86 '''); |
| 87 computeLibrarySourceErrors(source); | 87 computeLibrarySourceErrors(source); |
| 88 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 88 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void test_multiple_comments() { | 91 void test_multiple_comments() { |
| 92 Source source = addSource(''' | 92 Source source = addSource(''' |
| 93 int x = ''; //This is the first comment... | 93 int x = ''; //This is the first comment... |
| 94 //# ignore: const_initialized_with_non_constant_value | 94 // ignore: const_initialized_with_non_constant_value |
| 95 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 95 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 96 '''); | 96 '''); |
| 97 computeLibrarySourceErrors(source); | 97 computeLibrarySourceErrors(source); |
| 98 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 98 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void test_multiple_ignores() { | 101 void test_multiple_ignores() { |
| 102 Source source = addSource(''' | 102 Source source = addSource(''' |
| 103 int x = 3; | 103 int x = 3; |
| 104 //# ignore: invalid_assignment, const_initialized_with_non_constant_value | 104 // ignore: invalid_assignment, const_initialized_with_non_constant_value |
| 105 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 105 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 106 '''); | 106 '''); |
| 107 computeLibrarySourceErrors(source); | 107 computeLibrarySourceErrors(source); |
| 108 assertErrors(source, []); | 108 assertErrors(source, []); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void test_multiple_ignores_whitespace_variant_1() { | 111 void test_multiple_ignores_whitespace_variant_1() { |
| 112 Source source = addSource(''' | 112 Source source = addSource(''' |
| 113 int x = 3; | 113 int x = 3; |
| 114 //#ignore:invalid_assignment,const_initialized_with_non_constant_value | 114 //ignore:invalid_assignment,const_initialized_with_non_constant_value |
| 115 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 115 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 116 '''); | 116 '''); |
| 117 computeLibrarySourceErrors(source); | 117 computeLibrarySourceErrors(source); |
| 118 assertErrors(source, []); | 118 assertErrors(source, []); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void test_multiple_ignores_whitespace_variant_2() { | 121 void test_multiple_ignores_whitespace_variant_2() { |
| 122 Source source = addSource(''' | 122 Source source = addSource(''' |
| 123 int x = 3; | 123 int x = 3; |
| 124 //#ignore: invalid_assignment,const_initialized_with_non_constant_value | 124 //ignore: invalid_assignment,const_initialized_with_non_constant_value |
| 125 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 125 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 126 '''); | 126 '''); |
| 127 computeLibrarySourceErrors(source); | 127 computeLibrarySourceErrors(source); |
| 128 assertErrors(source, []); | 128 assertErrors(source, []); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void test_multiple_ignores_whitespace_variant_3() { | 131 void test_multiple_ignores_whitespace_variant_3() { |
| 132 Source source = addSource(''' | 132 Source source = addSource(''' |
| 133 int x = 3; | 133 int x = 3; |
| 134 //# ignore: invalid_assignment,const_initialized_with_non_constant_value | 134 // ignore: invalid_assignment,const_initialized_with_non_constant_value |
| 135 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 135 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 136 '''); | 136 '''); |
| 137 computeLibrarySourceErrors(source); | 137 computeLibrarySourceErrors(source); |
| 138 assertErrors(source, []); | 138 assertErrors(source, []); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void test_no_ignores() { | 141 void test_no_ignores() { |
| 142 Source source = addSource(''' | 142 Source source = addSource(''' |
| 143 int x = ''; //INVALID_ASSIGNMENT | 143 int x = ''; //INVALID_ASSIGNMENT |
| 144 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 144 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 145 '''); | 145 '''); |
| 146 computeLibrarySourceErrors(source); | 146 computeLibrarySourceErrors(source); |
| 147 assertErrors(source, [ | 147 assertErrors(source, [ |
| 148 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 148 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 149 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 149 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 150 ]); | 150 ]); |
| 151 } | 151 } |
| 152 } | 152 } |
| OLD | NEW |