Skip to content

Commit 088fbb8

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Replace newly added uses of assertErrorCodesInCode and deprecate it
Change-Id: I9937cf88ec57452a97d9b4110bd6d6da36bac159 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110320 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent eb057fe commit 088fbb8

9 files changed

+100
-46
lines changed

pkg/analyzer/test/src/dart/resolution/extension_method_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ f() {
128128
}
129129

130130
test_method_noMatch() async {
131-
await assertErrorCodesInCode(r'''
131+
await assertErrorsInCode(r'''
132132
class B { }
133133
134134
extension A on B {
@@ -139,7 +139,9 @@ f() {
139139
B b = B();
140140
b.c();
141141
}
142-
''', [StaticTypeWarningCode.UNDEFINED_METHOD]);
142+
''', [
143+
error(StaticTypeWarningCode.UNDEFINED_METHOD, 73, 1),
144+
]);
143145
}
144146

145147
test_method_noMostSpecificExtension() async {
@@ -189,14 +191,16 @@ extension _ on B {
189191
void a() { }
190192
}
191193
''');
192-
await assertErrorCodesInCode(r'''
194+
await assertErrorsInCode(r'''
193195
import 'lib.dart';
194196
195197
f() {
196198
B b = B();
197199
b.a();
198200
}
199-
''', [StaticTypeWarningCode.UNDEFINED_METHOD]);
201+
''', [
202+
error(StaticTypeWarningCode.UNDEFINED_METHOD, 43, 1),
203+
]);
200204
}
201205

202206
test_method_resolvesToStatic() async {
@@ -306,14 +310,16 @@ extension on B {
306310
void a() { }
307311
}
308312
''');
309-
await assertErrorCodesInCode(r'''
313+
await assertErrorsInCode(r'''
310314
import 'lib.dart';
311315
312316
f() {
313317
B b = B();
314318
b.a();
315319
}
316-
''', [StaticTypeWarningCode.UNDEFINED_METHOD]);
320+
''', [
321+
error(StaticTypeWarningCode.UNDEFINED_METHOD, 43, 1),
322+
]);
317323
}
318324

319325
test_multipleExtensions() async {

pkg/analyzer/test/src/dart/resolution/resolution.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ mixin ResolutionTest implements ResourceProviderMixin {
148148
expect(element.enclosingElement, expectedEnclosing);
149149
}
150150

151+
@Deprecated('Use assertErrorsInCode')
151152
Future<void> assertErrorCodesInCode(
152153
String code, List<ErrorCode> errors) async {
153154
addTestFile(code);

pkg/analyzer/test/src/diagnostics/invalid_use_of_null_value_test.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import '../dart/resolution/driver_resolution.dart';
1111

1212
main() {
1313
defineReflectiveSuite(() {
14-
defineReflectiveTests(InvalidUseOfNullValue);
14+
defineReflectiveTests(InvalidUseOfNullValueTest);
1515
});
1616
}
1717

1818
@reflectiveTest
19-
class InvalidUseOfNullValue extends DriverResolutionTest {
19+
class InvalidUseOfNullValueTest extends DriverResolutionTest {
2020
@override
2121
AnalysisOptionsImpl get analysisOptions =>
2222
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
@@ -40,12 +40,14 @@ m() async {
4040
}
4141

4242
test_cascade() async {
43-
await assertErrorCodesInCode(r'''
43+
await assertErrorsInCode(r'''
4444
m() {
4545
Null x;
4646
x..toString;
4747
}
48-
''', [StaticWarningCode.INVALID_USE_OF_NULL_VALUE]);
48+
''', [
49+
error(StaticWarningCode.INVALID_USE_OF_NULL_VALUE, 18, 1),
50+
]);
4951
}
5052

5153
test_eq() async {
@@ -58,12 +60,15 @@ m() {
5860
}
5961

6062
test_forLoop() async {
61-
await assertErrorCodesInCode(r'''
63+
await assertErrorsInCode(r'''
6264
m() {
6365
Null x;
6466
for (var y in x) {}
6567
}
66-
''', [StaticWarningCode.INVALID_USE_OF_NULL_VALUE]);
68+
''', [
69+
error(HintCode.UNUSED_LOCAL_VARIABLE, 27, 1),
70+
error(StaticWarningCode.INVALID_USE_OF_NULL_VALUE, 32, 1),
71+
]);
6772
}
6873

6974
test_is() async {

pkg/analyzer/test/src/diagnostics/non_bool_condition_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,25 @@ class NonBoolConditionTest_NNBD extends DriverResolutionTest {
4141
AnalysisOptionsImpl get analysisOptions =>
4242
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
4343
test_if_null() async {
44-
await assertErrorCodesInCode(r'''
44+
await assertErrorsInCode(r'''
4545
m() {
4646
Null x;
4747
if (x) {}
4848
}
49-
''', [StaticTypeWarningCode.NON_BOOL_CONDITION]);
49+
''', [
50+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 22, 1),
51+
]);
5052
}
5153

5254
test_ternary_condition_null() async {
53-
await assertErrorCodesInCode(r'''
55+
await assertErrorsInCode(r'''
5456
m() {
5557
Null x;
5658
x ? 0 : 1;
5759
}
58-
''', [StaticTypeWarningCode.NON_BOOL_CONDITION]);
60+
''', [
61+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 18, 1),
62+
]);
5963
}
6064
}
6165

pkg/analyzer/test/src/diagnostics/non_bool_negation_expression_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ class NonBoolNegationExpressionTest_NNBD extends DriverResolutionTest {
2222
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
2323

2424
test_null() async {
25-
await assertErrorCodesInCode(r'''
25+
await assertErrorsInCode(r'''
2626
m() {
2727
Null x;
2828
!x;
2929
}
30-
''', [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]);
30+
''', [
31+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
32+
error(StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, 19, 1),
33+
]);
3134
}
3235
}

pkg/analyzer/test/src/diagnostics/non_bool_operand_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,24 @@ class NonBoolOperandTest_NNBD extends DriverResolutionTest {
2222
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
2323

2424
test_and_null() async {
25-
await assertErrorCodesInCode(r'''
25+
await assertErrorsInCode(r'''
2626
m() {
2727
Null x;
2828
if(x && true) {}
2929
}
30-
''', [StaticTypeWarningCode.NON_BOOL_OPERAND]);
30+
''', [
31+
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 21, 1),
32+
]);
3133
}
3234

3335
test_or_null() async {
34-
await assertErrorCodesInCode(r'''
36+
await assertErrorsInCode(r'''
3537
m() {
3638
Null x;
3739
if(x || false) {}
3840
}
39-
''', [StaticTypeWarningCode.NON_BOOL_OPERAND]);
41+
''', [
42+
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 21, 1),
43+
]);
4044
}
4145
}

pkg/analyzer/test/src/diagnostics/unchecked_use_of_nullable_value_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,14 @@ m() {
623623
}
624624

625625
test_spread_nullable() async {
626-
await assertErrorCodesInCode(r'''
626+
await assertErrorsInCode(r'''
627627
m() {
628628
List? list;
629629
[...list];
630630
}
631-
''', [StaticWarningCode.UNCHECKED_USE_OF_NULLABLE_VALUE]);
631+
''', [
632+
error(StaticWarningCode.UNCHECKED_USE_OF_NULLABLE_VALUE, 26, 4),
633+
]);
632634
}
633635

634636
test_spread_nullable_question() async {

pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ f(Object x) {
9292
}
9393

9494
test_nullMember_undefined() async {
95-
await assertErrorCodesInCode(r'''
95+
await assertErrorsInCode(r'''
9696
m() {
9797
Null _null;
9898
_null.foo;
9999
}
100-
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
100+
''', [
101+
error(StaticTypeWarningCode.UNDEFINED_GETTER, 28, 3),
102+
]);
101103
}
102104

103105
test_promotedTypeParameter_regress35305() async {

pkg/analyzer/test/src/diagnostics/undefined_operator_test.dart

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ f(var a) {
4545
}
4646

4747
test_index_null() async {
48-
await assertErrorCodesInCode(r'''
48+
await assertErrorsInCode(r'''
4949
m() {
5050
Null x;
5151
x[0];
5252
}
53-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
53+
''', [
54+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 19, 3),
55+
]);
5456
}
5557

5658
test_indexBoth() async {
@@ -143,48 +145,61 @@ f(var a) {
143145
}
144146

145147
test_minus_null() async {
146-
await assertErrorCodesInCode(r'''
148+
await assertErrorsInCode(r'''
147149
m() {
148150
Null x;
149151
x - 3;
150152
}
151-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
153+
''', [
154+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 1),
155+
]);
152156
}
153157

154158
test_minusEq_null() async {
155-
await assertErrorCodesInCode(r'''
159+
await assertErrorsInCode(r'''
156160
m() {
157161
Null x;
158162
x -= 1;
159163
}
160-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
164+
''', [
165+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
166+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 2),
167+
]);
161168
}
162169

163170
test_plus_null() async {
164-
await assertErrorCodesInCode(r'''
171+
await assertErrorsInCode(r'''
165172
m() {
166173
Null x;
167174
x + 3;
168175
}
169-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
176+
''', [
177+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 1),
178+
]);
170179
}
171180

172181
test_plusEq_null() async {
173-
await assertErrorCodesInCode(r'''
182+
await assertErrorsInCode(r'''
174183
m() {
175184
Null x;
176185
x += 1;
177186
}
178-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
187+
''', [
188+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
189+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 2),
190+
]);
179191
}
180192

181193
test_postfixDec_null() async {
182-
await assertErrorCodesInCode(r'''
194+
await assertErrorsInCode(r'''
183195
m() {
184196
Null x;
185197
x--;
186198
}
187-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
199+
''', [
200+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
201+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 19, 2),
202+
]);
188203
}
189204

190205
test_postfixExpression() async {
@@ -213,21 +228,27 @@ f(var a) {
213228
}
214229

215230
test_postfixInc_null() async {
216-
await assertErrorCodesInCode(r'''
231+
await assertErrorsInCode(r'''
217232
m() {
218233
Null x;
219234
x++;
220235
}
221-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
236+
''', [
237+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
238+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 19, 2),
239+
]);
222240
}
223241

224242
test_prefixDec_null() async {
225-
await assertErrorCodesInCode(r'''
243+
await assertErrorsInCode(r'''
226244
m() {
227245
Null x;
228246
--x;
229247
}
230-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
248+
''', [
249+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
250+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 18, 2),
251+
]);
231252
}
232253

233254
test_prefixExpression() async {
@@ -256,20 +277,26 @@ f(var a) {
256277
}
257278

258279
test_prefixInc_null() async {
259-
await assertErrorCodesInCode(r'''
280+
await assertErrorsInCode(r'''
260281
m() {
261282
Null x;
262283
++x;
263284
}
264-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
285+
''', [
286+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
287+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 18, 2),
288+
]);
265289
}
266290

267291
test_unaryMinus_null() async {
268-
await assertErrorCodesInCode(r'''
292+
await assertErrorsInCode(r'''
269293
m() {
270294
Null x;
271295
-x;
272296
}
273-
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
297+
''', [
298+
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
299+
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 18, 1),
300+
]);
274301
}
275302
}

0 commit comments

Comments
 (0)