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