| 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/error/codes.dart'; | 5 import 'package:analyzer/src/error/codes.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 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 9 | 9 |
| 10 import 'resolver_test_case.dart'; | 10 import 'resolver_test_case.dart'; |
| 11 | 11 |
| 12 main() { | 12 main() { |
| 13 defineReflectiveSuite(() { | 13 defineReflectiveSuite(() { |
| 14 defineReflectiveTests(ErrorSuppressionTest); | 14 defineReflectiveTests(ErrorSuppressionTest); |
| 15 }); | 15 }); |
| 16 } | 16 } |
| 17 | 17 |
| 18 @reflectiveTest | 18 @reflectiveTest |
| 19 class ErrorSuppressionTest extends ResolverTestCase { | 19 class ErrorSuppressionTest extends ResolverTestCase { |
| 20 test_error_code_mismatch() async { | 20 test_error_code_mismatch() async { |
| 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 await assertErrors(source, [ | 26 await computeAnalysisResult(source); |
| 27 assertErrors(source, [ |
| 27 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 28 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 28 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 29 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 29 ]); | 30 ]); |
| 30 } | 31 } |
| 31 | 32 |
| 32 test_ignore_first() async { | 33 test_ignore_first() async { |
| 33 Source source = addSource(''' | 34 Source source = addSource(''' |
| 34 // ignore: invalid_assignment | 35 // ignore: invalid_assignment |
| 35 int x = ''; | 36 int x = ''; |
| 36 // ... but no ignore here ... | 37 // ... but no ignore here ... |
| 37 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 38 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 38 '''); | 39 '''); |
| 39 await assertErrors(source, | 40 await computeAnalysisResult(source); |
| 41 assertErrors(source, |
| 40 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 42 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 41 } | 43 } |
| 42 | 44 |
| 43 test_ignore_first_trailing() async { | 45 test_ignore_first_trailing() async { |
| 44 Source source = addSource(''' | 46 Source source = addSource(''' |
| 45 int x = ''; // ignore: invalid_assignment | 47 int x = ''; // ignore: invalid_assignment |
| 46 // ... but no ignore here ... | 48 // ... but no ignore here ... |
| 47 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 49 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 48 '''); | 50 '''); |
| 49 await assertErrors(source, | 51 await computeAnalysisResult(source); |
| 52 assertErrors(source, |
| 50 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 53 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 51 } | 54 } |
| 52 | 55 |
| 53 test_ignore_only_trailing() async { | 56 test_ignore_only_trailing() async { |
| 54 Source source = addSource(''' | 57 Source source = addSource(''' |
| 55 int x = ''; // ignore: invalid_assignment | 58 int x = ''; // ignore: invalid_assignment |
| 56 '''); | 59 '''); |
| 57 await assertErrors(source, []); | 60 await computeAnalysisResult(source); |
| 61 assertErrors(source, []); |
| 58 } | 62 } |
| 59 | 63 |
| 60 test_ignore_second() async { | 64 test_ignore_second() async { |
| 61 Source source = addSource(''' | 65 Source source = addSource(''' |
| 62 //INVALID_ASSIGNMENT | 66 //INVALID_ASSIGNMENT |
| 63 int x = ''; | 67 int x = ''; |
| 64 // ignore: const_initialized_with_non_constant_value | 68 // ignore: const_initialized_with_non_constant_value |
| 65 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 69 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 66 '''); | 70 '''); |
| 67 await assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 71 await computeAnalysisResult(source); |
| 72 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 68 } | 73 } |
| 69 | 74 |
| 70 test_ignore_second_trailing() async { | 75 test_ignore_second_trailing() async { |
| 71 Source source = addSource(''' | 76 Source source = addSource(''' |
| 72 //INVALID_ASSIGNMENT | 77 //INVALID_ASSIGNMENT |
| 73 int x = ''; | 78 int x = ''; |
| 74 const y = x; // ignore: const_initialized_with_non_constant_value | 79 const y = x; // ignore: const_initialized_with_non_constant_value |
| 75 '''); | 80 '''); |
| 76 await assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 81 await computeAnalysisResult(source); |
| 82 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 77 } | 83 } |
| 78 | 84 |
| 79 test_ignore_upper_case() async { | 85 test_ignore_upper_case() async { |
| 80 Source source = addSource(''' | 86 Source source = addSource(''' |
| 81 int x = ''; // ignore: INVALID_ASSIGNMENT | 87 int x = ''; // ignore: INVALID_ASSIGNMENT |
| 82 '''); | 88 '''); |
| 83 await assertErrors(source, []); | 89 await computeAnalysisResult(source); |
| 90 assertErrors(source, []); |
| 84 } | 91 } |
| 85 | 92 |
| 86 test_invalid_error_code() async { | 93 test_invalid_error_code() async { |
| 87 Source source = addSource(''' | 94 Source source = addSource(''' |
| 88 // ignore: right_format_wrong_code | 95 // ignore: right_format_wrong_code |
| 89 int x = ''; | 96 int x = ''; |
| 90 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 97 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 91 '''); | 98 '''); |
| 92 await assertErrors(source, [ | 99 await computeAnalysisResult(source); |
| 100 assertErrors(source, [ |
| 93 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 101 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 94 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 102 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 95 ]); | 103 ]); |
| 96 } | 104 } |
| 97 | 105 |
| 98 test_missing_error_codes() async { | 106 test_missing_error_codes() async { |
| 99 Source source = addSource(''' | 107 Source source = addSource(''' |
| 100 int x = 3; | 108 int x = 3; |
| 101 // ignore: | 109 // ignore: |
| 102 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 110 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 103 '''); | 111 '''); |
| 104 await assertErrors(source, [ | 112 await computeAnalysisResult(source); |
| 113 assertErrors(source, [ |
| 105 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 114 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 106 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 115 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 107 ]); | 116 ]); |
| 108 } | 117 } |
| 109 | 118 |
| 110 test_missing_metadata_suffix() async { | 119 test_missing_metadata_suffix() async { |
| 111 Source source = addSource(''' | 120 Source source = addSource(''' |
| 112 // ignore invalid_assignment | 121 // ignore invalid_assignment |
| 113 String y = 3; //INVALID_ASSIGNMENT | 122 String y = 3; //INVALID_ASSIGNMENT |
| 114 '''); | 123 '''); |
| 115 await assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 124 await computeAnalysisResult(source); |
| 125 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 116 } | 126 } |
| 117 | 127 |
| 118 test_multiple_comments() async { | 128 test_multiple_comments() async { |
| 119 Source source = addSource(''' | 129 Source source = addSource(''' |
| 120 int x = ''; //This is the first comment... | 130 int x = ''; //This is the first comment... |
| 121 // ignore: const_initialized_with_non_constant_value | 131 // ignore: const_initialized_with_non_constant_value |
| 122 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 132 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 123 '''); | 133 '''); |
| 124 await assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 134 await computeAnalysisResult(source); |
| 135 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 125 } | 136 } |
| 126 | 137 |
| 127 test_multiple_ignores() async { | 138 test_multiple_ignores() async { |
| 128 Source source = addSource(''' | 139 Source source = addSource(''' |
| 129 int x = 3; | 140 int x = 3; |
| 130 // ignore: invalid_assignment, const_initialized_with_non_constant_value | 141 // ignore: invalid_assignment, const_initialized_with_non_constant_value |
| 131 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 142 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 132 '''); | 143 '''); |
| 133 await assertErrors(source, []); | 144 await computeAnalysisResult(source); |
| 145 assertErrors(source, []); |
| 134 } | 146 } |
| 135 | 147 |
| 136 test_multiple_ignores_traling() async { | 148 test_multiple_ignores_traling() async { |
| 137 Source source = addSource(''' | 149 Source source = addSource(''' |
| 138 int x = 3; | 150 int x = 3; |
| 139 const String y = x; // ignore: invalid_assignment, const_initialized_with_non_co
nstant_value | 151 const String y = x; // ignore: invalid_assignment, const_initialized_with_non_co
nstant_value |
| 140 '''); | 152 '''); |
| 141 await assertErrors(source, []); | 153 await computeAnalysisResult(source); |
| 154 assertErrors(source, []); |
| 142 } | 155 } |
| 143 | 156 |
| 144 test_multiple_ignores_whitespace_variant_1() async { | 157 test_multiple_ignores_whitespace_variant_1() async { |
| 145 Source source = addSource(''' | 158 Source source = addSource(''' |
| 146 int x = 3; | 159 int x = 3; |
| 147 //ignore:invalid_assignment,const_initialized_with_non_constant_value | 160 //ignore:invalid_assignment,const_initialized_with_non_constant_value |
| 148 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 161 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 149 '''); | 162 '''); |
| 150 await assertErrors(source, []); | 163 await computeAnalysisResult(source); |
| 164 assertErrors(source, []); |
| 151 } | 165 } |
| 152 | 166 |
| 153 test_multiple_ignores_whitespace_variant_2() async { | 167 test_multiple_ignores_whitespace_variant_2() async { |
| 154 Source source = addSource(''' | 168 Source source = addSource(''' |
| 155 int x = 3; | 169 int x = 3; |
| 156 //ignore: invalid_assignment,const_initialized_with_non_constant_value | 170 //ignore: invalid_assignment,const_initialized_with_non_constant_value |
| 157 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 171 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 158 '''); | 172 '''); |
| 159 await assertErrors(source, []); | 173 await computeAnalysisResult(source); |
| 174 assertErrors(source, []); |
| 160 } | 175 } |
| 161 | 176 |
| 162 test_multiple_ignores_whitespace_variant_3() async { | 177 test_multiple_ignores_whitespace_variant_3() async { |
| 163 Source source = addSource(''' | 178 Source source = addSource(''' |
| 164 int x = 3; | 179 int x = 3; |
| 165 // ignore: invalid_assignment,const_initialized_with_non_constant_value | 180 // ignore: invalid_assignment,const_initialized_with_non_constant_value |
| 166 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 181 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 167 '''); | 182 '''); |
| 168 await assertErrors(source, []); | 183 await computeAnalysisResult(source); |
| 184 assertErrors(source, []); |
| 169 } | 185 } |
| 170 | 186 |
| 171 test_no_ignores() async { | 187 test_no_ignores() async { |
| 172 Source source = addSource(''' | 188 Source source = addSource(''' |
| 173 int x = ''; //INVALID_ASSIGNMENT | 189 int x = ''; //INVALID_ASSIGNMENT |
| 174 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 190 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 175 '''); | 191 '''); |
| 176 await assertErrors(source, [ | 192 await computeAnalysisResult(source); |
| 193 assertErrors(source, [ |
| 177 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 194 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 178 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 195 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 179 ]); | 196 ]); |
| 180 } | 197 } |
| 181 } | 198 } |
| OLD | NEW |