Skip to content

Commit 42d2996

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Analyzer: Move NON_BOOL_* tests to diagnostics/
Change-Id: I5bc58d78bf4f15e860759176d2e6abc670666e46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153260 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 69aba23 commit 42d2996

6 files changed

+158
-141
lines changed

pkg/analyzer/test/generated/static_type_warning_code_test.dart

-131
Original file line numberDiff line numberDiff line change
@@ -502,137 +502,6 @@ f() {
502502
]);
503503
}
504504

505-
test_nonBoolCondition_conditional() async {
506-
await assertErrorsInCode('''
507-
f() { return 3 ? 2 : 1; }
508-
''', [
509-
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 13, 1),
510-
]);
511-
}
512-
513-
test_nonBoolCondition_do() async {
514-
await assertErrorsInCode(r'''
515-
f() {
516-
do {} while (3);
517-
}
518-
''', [
519-
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 21, 1),
520-
]);
521-
}
522-
523-
test_nonBoolCondition_for() async {
524-
// https://github.com/dart-lang/sdk/issues/24713
525-
await assertErrorsInCode(r'''
526-
f() {
527-
for (;3;) {}
528-
}
529-
''', [
530-
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 14, 1),
531-
]);
532-
}
533-
534-
test_nonBoolCondition_if() async {
535-
await assertErrorsInCode(r'''
536-
f() {
537-
if (3) return 2; else return 1;
538-
}
539-
''', [
540-
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 12, 1),
541-
]);
542-
}
543-
544-
test_nonBoolCondition_while() async {
545-
await assertErrorsInCode(r'''
546-
f() {
547-
while (3) {}
548-
}
549-
''', [
550-
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 15, 1),
551-
]);
552-
}
553-
554-
test_nonBoolExpression_functionType_bool() async {
555-
await assertErrorsInCode(r'''
556-
bool makeAssertion() => true;
557-
f() {
558-
assert(makeAssertion);
559-
}
560-
''', [
561-
error(StaticTypeWarningCode.NON_BOOL_EXPRESSION, 45, 13),
562-
]);
563-
}
564-
565-
test_nonBoolExpression_functionType_int() async {
566-
await assertErrorsInCode(r'''
567-
int makeAssertion() => 1;
568-
f() {
569-
assert(makeAssertion);
570-
}
571-
''', [
572-
error(StaticTypeWarningCode.NON_BOOL_EXPRESSION, 41, 13),
573-
]);
574-
}
575-
576-
test_nonBoolExpression_interfaceType() async {
577-
await assertErrorsInCode(r'''
578-
f() {
579-
assert(0);
580-
}
581-
''', [
582-
error(StaticTypeWarningCode.NON_BOOL_EXPRESSION, 15, 1),
583-
]);
584-
}
585-
586-
test_nonBoolNegationExpression() async {
587-
await assertErrorsInCode(r'''
588-
f() {
589-
!42;
590-
}
591-
''', [
592-
error(StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, 9, 2),
593-
]);
594-
}
595-
596-
test_nonBoolOperand_and_left() async {
597-
await assertErrorsInCode(r'''
598-
bool f(int left, bool right) {
599-
return left && right;
600-
}
601-
''', [
602-
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 40, 4),
603-
]);
604-
}
605-
606-
test_nonBoolOperand_and_right() async {
607-
await assertErrorsInCode(r'''
608-
bool f(bool left, String right) {
609-
return left && right;
610-
}
611-
''', [
612-
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 51, 5),
613-
]);
614-
}
615-
616-
test_nonBoolOperand_or_left() async {
617-
await assertErrorsInCode(r'''
618-
bool f(List<int> left, bool right) {
619-
return left || right;
620-
}
621-
''', [
622-
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 46, 4),
623-
]);
624-
}
625-
626-
test_nonBoolOperand_or_right() async {
627-
await assertErrorsInCode(r'''
628-
bool f(bool left, double right) {
629-
return left || right;
630-
}
631-
''', [
632-
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 51, 5),
633-
]);
634-
}
635-
636505
test_nonTypeAsTypeArgument_notAType() async {
637506
await assertErrorsInCode(r'''
638507
int A;

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

+49-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,41 @@ import '../dart/resolution/driver_resolution.dart';
1313
main() {
1414
defineReflectiveSuite(() {
1515
defineReflectiveTests(NonBoolConditionTest);
16-
defineReflectiveTests(NonBoolConditionWithConstantsTest);
1716
defineReflectiveTests(NonBoolConditionTest_NNBD);
1817
});
1918
}
2019

2120
@reflectiveTest
2221
class NonBoolConditionTest extends DriverResolutionTest {
22+
test_conditional() async {
23+
await assertErrorsInCode('''
24+
f() { return 3 ? 2 : 1; }
25+
''', [
26+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 13, 1),
27+
]);
28+
}
29+
30+
test_do() async {
31+
await assertErrorsInCode(r'''
32+
f() {
33+
do {} while (3);
34+
}
35+
''', [
36+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 21, 1),
37+
]);
38+
}
39+
40+
test_for() async {
41+
// https://github.com/dart-lang/sdk/issues/24713
42+
await assertErrorsInCode(r'''
43+
f() {
44+
for (;3;) {}
45+
}
46+
''', [
47+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 14, 1),
48+
]);
49+
}
50+
2351
test_forElement() async {
2452
await assertErrorsInCode('''
2553
var v = [for (; 0;) 1];
@@ -28,13 +56,33 @@ var v = [for (; 0;) 1];
2856
]);
2957
}
3058

59+
test_if() async {
60+
await assertErrorsInCode(r'''
61+
f() {
62+
if (3) return 2; else return 1;
63+
}
64+
''', [
65+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 12, 1),
66+
]);
67+
}
68+
3169
test_ifElement() async {
3270
await assertErrorsInCode('''
3371
var v = [if (3) 1];
3472
''', [
3573
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 13, 1),
3674
]);
3775
}
76+
77+
test_while() async {
78+
await assertErrorsInCode(r'''
79+
f() {
80+
while (3) {}
81+
}
82+
''', [
83+
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 15, 1),
84+
]);
85+
}
3886
}
3987

4088
@reflectiveTest
@@ -67,12 +115,3 @@ m() {
67115
]);
68116
}
69117
}
70-
71-
@reflectiveTest
72-
class NonBoolConditionWithConstantsTest extends NonBoolConditionTest {
73-
@override
74-
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
75-
..contextFeatures = FeatureSet.fromEnableFlags(
76-
[EnableString.constant_update_2018],
77-
);
78-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2020, 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:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(NonBoolExpressionTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class NonBoolExpressionTest extends DriverResolutionTest {
18+
test_functionType_bool() async {
19+
await assertErrorsInCode(r'''
20+
bool makeAssertion() => true;
21+
f() {
22+
assert(makeAssertion);
23+
}
24+
''', [
25+
error(StaticTypeWarningCode.NON_BOOL_EXPRESSION, 45, 13),
26+
]);
27+
}
28+
29+
test_functionType_int() async {
30+
await assertErrorsInCode(r'''
31+
int makeAssertion() => 1;
32+
f() {
33+
assert(makeAssertion);
34+
}
35+
''', [
36+
error(StaticTypeWarningCode.NON_BOOL_EXPRESSION, 41, 13),
37+
]);
38+
}
39+
40+
test_interfaceType() async {
41+
await assertErrorsInCode(r'''
42+
f() {
43+
assert(0);
44+
}
45+
''', [
46+
error(StaticTypeWarningCode.NON_BOOL_EXPRESSION, 15, 1),
47+
]);
48+
}
49+
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@ import '../dart/resolution/driver_resolution.dart';
1212

1313
main() {
1414
defineReflectiveSuite(() {
15+
defineReflectiveTests(NonBoolNegationExpressionTest);
1516
defineReflectiveTests(NonBoolNegationExpressionTest_NNBD);
1617
});
1718
}
1819

20+
@reflectiveTest
21+
class NonBoolNegationExpressionTest extends DriverResolutionTest {
22+
test_nonBool() async {
23+
await assertErrorsInCode(r'''
24+
f() {
25+
!42;
26+
}
27+
''', [
28+
error(StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, 9, 2),
29+
]);
30+
}
31+
}
32+
1933
@reflectiveTest
2034
class NonBoolNegationExpressionTest_NNBD extends DriverResolutionTest {
2135
@override

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

+44
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,54 @@ import '../dart/resolution/driver_resolution.dart';
1212

1313
main() {
1414
defineReflectiveSuite(() {
15+
defineReflectiveTests(NonBoolOperandTest);
1516
defineReflectiveTests(NonBoolOperandTest_NNBD);
1617
});
1718
}
1819

20+
@reflectiveTest
21+
class NonBoolOperandTest extends DriverResolutionTest {
22+
test_and_left() async {
23+
await assertErrorsInCode(r'''
24+
bool f(int left, bool right) {
25+
return left && right;
26+
}
27+
''', [
28+
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 40, 4),
29+
]);
30+
}
31+
32+
test_and_right() async {
33+
await assertErrorsInCode(r'''
34+
bool f(bool left, String right) {
35+
return left && right;
36+
}
37+
''', [
38+
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 51, 5),
39+
]);
40+
}
41+
42+
test_or_left() async {
43+
await assertErrorsInCode(r'''
44+
bool f(List<int> left, bool right) {
45+
return left || right;
46+
}
47+
''', [
48+
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 46, 4),
49+
]);
50+
}
51+
52+
test_or_right() async {
53+
await assertErrorsInCode(r'''
54+
bool f(bool left, double right) {
55+
return left || right;
56+
}
57+
''', [
58+
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 51, 5),
59+
]);
60+
}
61+
}
62+
1963
@reflectiveTest
2064
class NonBoolOperandTest_NNBD extends DriverResolutionTest {
2165
@override

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

+2
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ import 'no_default_super_constructor_test.dart' as no_default_super_constructor;
321321
import 'non_abstract_class_inherits_abstract_member_test.dart'
322322
as non_abstract_class_inherits_abstract_member;
323323
import 'non_bool_condition_test.dart' as non_bool_condition;
324+
import 'non_bool_expression_test.dart' as non_bool_expression;
324325
import 'non_bool_negation_expression_test.dart' as non_bool_negation_expression;
325326
import 'non_bool_operand_test.dart' as non_bool_operand;
326327
import 'non_constant_case_expression_from_deferred_library_test.dart'
@@ -750,6 +751,7 @@ main() {
750751
no_default_super_constructor.main();
751752
non_abstract_class_inherits_abstract_member.main();
752753
non_bool_condition.main();
754+
non_bool_expression.main();
753755
non_bool_negation_expression.main();
754756
non_bool_operand.main();
755757
non_constant_list_element.main();

0 commit comments

Comments
 (0)