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