mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:13:04 +00:00
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 <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
eb057fe495
commit
088fbb8d42
|
@ -128,7 +128,7 @@ f() {
|
|||
}
|
||||
|
||||
test_method_noMatch() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
class B { }
|
||||
|
||||
extension A on B {
|
||||
|
@ -139,7 +139,9 @@ f() {
|
|||
B b = B();
|
||||
b.c();
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_METHOD]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_METHOD, 73, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_method_noMostSpecificExtension() async {
|
||||
|
@ -189,14 +191,16 @@ extension _ on B {
|
|||
void a() { }
|
||||
}
|
||||
''');
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'lib.dart';
|
||||
|
||||
f() {
|
||||
B b = B();
|
||||
b.a();
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_METHOD]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_METHOD, 43, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_method_resolvesToStatic() async {
|
||||
|
@ -306,14 +310,16 @@ extension on B {
|
|||
void a() { }
|
||||
}
|
||||
''');
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
import 'lib.dart';
|
||||
|
||||
f() {
|
||||
B b = B();
|
||||
b.a();
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_METHOD]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_METHOD, 43, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_multipleExtensions() async {
|
||||
|
|
|
@ -148,6 +148,7 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
|||
expect(element.enclosingElement, expectedEnclosing);
|
||||
}
|
||||
|
||||
@Deprecated('Use assertErrorsInCode')
|
||||
Future<void> assertErrorCodesInCode(
|
||||
String code, List<ErrorCode> errors) async {
|
||||
addTestFile(code);
|
||||
|
|
|
@ -11,12 +11,12 @@ import '../dart/resolution/driver_resolution.dart';
|
|||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(InvalidUseOfNullValue);
|
||||
defineReflectiveTests(InvalidUseOfNullValueTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class InvalidUseOfNullValue extends DriverResolutionTest {
|
||||
class InvalidUseOfNullValueTest extends DriverResolutionTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get analysisOptions =>
|
||||
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
|
||||
|
@ -40,12 +40,14 @@ m() async {
|
|||
}
|
||||
|
||||
test_cascade() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x..toString;
|
||||
}
|
||||
''', [StaticWarningCode.INVALID_USE_OF_NULL_VALUE]);
|
||||
''', [
|
||||
error(StaticWarningCode.INVALID_USE_OF_NULL_VALUE, 18, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_eq() async {
|
||||
|
@ -58,12 +60,15 @@ m() {
|
|||
}
|
||||
|
||||
test_forLoop() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
for (var y in x) {}
|
||||
}
|
||||
''', [StaticWarningCode.INVALID_USE_OF_NULL_VALUE]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 27, 1),
|
||||
error(StaticWarningCode.INVALID_USE_OF_NULL_VALUE, 32, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_is() async {
|
||||
|
|
|
@ -41,21 +41,25 @@ class NonBoolConditionTest_NNBD extends DriverResolutionTest {
|
|||
AnalysisOptionsImpl get analysisOptions =>
|
||||
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
|
||||
test_if_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
if (x) {}
|
||||
}
|
||||
''', [StaticTypeWarningCode.NON_BOOL_CONDITION]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 22, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_ternary_condition_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x ? 0 : 1;
|
||||
}
|
||||
''', [StaticTypeWarningCode.NON_BOOL_CONDITION]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.NON_BOOL_CONDITION, 18, 1),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,14 @@ class NonBoolNegationExpressionTest_NNBD extends DriverResolutionTest {
|
|||
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
|
||||
|
||||
test_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
!x;
|
||||
}
|
||||
''', [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, 19, 1),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,20 +22,24 @@ class NonBoolOperandTest_NNBD extends DriverResolutionTest {
|
|||
AnalysisOptionsImpl()..enabledExperiments = [EnableString.non_nullable];
|
||||
|
||||
test_and_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
if(x && true) {}
|
||||
}
|
||||
''', [StaticTypeWarningCode.NON_BOOL_OPERAND]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 21, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_or_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
if(x || false) {}
|
||||
}
|
||||
''', [StaticTypeWarningCode.NON_BOOL_OPERAND]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.NON_BOOL_OPERAND, 21, 1),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -623,12 +623,14 @@ m() {
|
|||
}
|
||||
|
||||
test_spread_nullable() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
List? list;
|
||||
[...list];
|
||||
}
|
||||
''', [StaticWarningCode.UNCHECKED_USE_OF_NULLABLE_VALUE]);
|
||||
''', [
|
||||
error(StaticWarningCode.UNCHECKED_USE_OF_NULLABLE_VALUE, 26, 4),
|
||||
]);
|
||||
}
|
||||
|
||||
test_spread_nullable_question() async {
|
||||
|
|
|
@ -92,12 +92,14 @@ f(Object x) {
|
|||
}
|
||||
|
||||
test_nullMember_undefined() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null _null;
|
||||
_null.foo;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_GETTER]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_GETTER, 28, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
test_promotedTypeParameter_regress35305() async {
|
||||
|
|
|
@ -45,12 +45,14 @@ f(var a) {
|
|||
}
|
||||
|
||||
test_index_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x[0];
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 19, 3),
|
||||
]);
|
||||
}
|
||||
|
||||
test_indexBoth() async {
|
||||
|
@ -143,48 +145,61 @@ f(var a) {
|
|||
}
|
||||
|
||||
test_minus_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x - 3;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_minusEq_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x -= 1;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_plus_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x + 3;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_plusEq_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x += 1;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 20, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_postfixDec_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x--;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 19, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_postfixExpression() async {
|
||||
|
@ -213,21 +228,27 @@ f(var a) {
|
|||
}
|
||||
|
||||
test_postfixInc_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
x++;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 19, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_prefixDec_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
--x;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 18, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_prefixExpression() async {
|
||||
|
@ -256,20 +277,26 @@ f(var a) {
|
|||
}
|
||||
|
||||
test_prefixInc_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
++x;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 18, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_unaryMinus_null() async {
|
||||
await assertErrorCodesInCode(r'''
|
||||
await assertErrorsInCode(r'''
|
||||
m() {
|
||||
Null x;
|
||||
-x;
|
||||
}
|
||||
''', [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
|
||||
''', [
|
||||
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
|
||||
error(StaticTypeWarningCode.UNDEFINED_OPERATOR, 18, 1),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue