diff --git a/pkg/analyzer/test/src/dart/resolution/language_version_test.dart b/pkg/analyzer/test/src/dart/resolution/language_version_test.dart index c94064bcfd1..bafbda4b930 100644 --- a/pkg/analyzer/test/src/dart/resolution/language_version_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/language_version_test.dart @@ -18,8 +18,7 @@ main() { } @reflectiveTest -class NullSafetyExperimentGlobalTest extends _FeaturesTest - with WithNullSafetyMixin { +class NullSafetyExperimentGlobalTest extends _FeaturesTest { test_jsonConfig_legacyContext_nonNullDependency() async { _configureTestWithJsonConfig(''' { diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/local_variable_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/local_variable_test.dart index 5d3126f62f6..556c1d0b07c 100644 --- a/pkg/analyzer/test/src/dart/resolution/type_inference/local_variable_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/type_inference/local_variable_test.dart @@ -9,13 +9,25 @@ import '../context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(LocalVariableTest); - defineReflectiveTests(LocalVariableWithNullSafetyTest); + defineReflectiveTests(LocalVariableWithoutNullSafetyTest); }); } @reflectiveTest class LocalVariableTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with LocalVariableTestCases { + test_Never() async { + await resolveTestCode(''' +void f(Never a) { + var v = a; + v; +} +'''); + _assertTypeOfV('Never'); + } +} + +mixin LocalVariableTestCases on PubPackageResolutionTest { test_int() async { await resolveTestCode(''' void f() { @@ -43,15 +55,5 @@ void f() { } @reflectiveTest -class LocalVariableWithNullSafetyTest extends LocalVariableTest - with WithNullSafetyMixin { - test_Never() async { - await resolveTestCode(''' -void f(Never a) { - var v = a; - v; -} -'''); - _assertTypeOfV('Never'); - } -} +class LocalVariableWithoutNullSafetyTest extends PubPackageResolutionTest + with LocalVariableTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart b/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart index e3523e4e933..7ea89723564 100644 --- a/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart +++ b/pkg/analyzer/test/src/diagnostics/missing_enum_constant_in_switch_test.dart @@ -10,13 +10,63 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MissingEnumConstantInSwitchTest); - defineReflectiveTests(MissingEnumConstantInSwitchWithNullSafetyTest); + defineReflectiveTests(MissingEnumConstantInSwitchWithoutNullSafetyTest); }); } @reflectiveTest class MissingEnumConstantInSwitchTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with MissingEnumConstantInSwitchTestCases { + test_nullable() async { + await assertErrorsInCode(''' +enum E { one, two } + +void f(E? e) { + switch (e) { + case E.one: + case E.two: + break; + } +} +''', [ + error(StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH, 38, 10), + ]); + } + + test_nullable_default() async { + await assertNoErrorsInCode(''' +enum E { one, two } + +void f(E? e) { + switch (e) { + case E.one: + break; + default: + break; + } +} +'''); + } + + test_nullable_null() async { + await assertNoErrorsInCode(''' +enum E { one, two } + +void f(E? e) { + switch (e) { + case E.one: + break; + case E.two: + break; + case null: + break; + } +} +'''); + } +} + +mixin MissingEnumConstantInSwitchTestCases on PubPackageResolutionTest { test_default() async { await assertNoErrorsInCode(''' enum E { one, two, three } @@ -99,53 +149,6 @@ void f(E e) { } @reflectiveTest -class MissingEnumConstantInSwitchWithNullSafetyTest - extends MissingEnumConstantInSwitchTest with WithNullSafetyMixin { - test_nullable() async { - await assertErrorsInCode(''' -enum E { one, two } - -void f(E? e) { - switch (e) { - case E.one: - case E.two: - break; - } -} -''', [ - error(StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH, 38, 10), - ]); - } - - test_nullable_default() async { - await assertNoErrorsInCode(''' -enum E { one, two } - -void f(E? e) { - switch (e) { - case E.one: - break; - default: - break; - } -} -'''); - } - - test_nullable_null() async { - await assertNoErrorsInCode(''' -enum E { one, two } - -void f(E? e) { - switch (e) { - case E.one: - break; - case E.two: - break; - case null: - break; - } -} -'''); - } -} +class MissingEnumConstantInSwitchWithoutNullSafetyTest + extends PubPackageResolutionTest + with MissingEnumConstantInSwitchTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart index 53935facc73..47c9fd2ed0b 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_of_non_class_test.dart @@ -10,13 +10,23 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinOfNonClassTest); - defineReflectiveTests(MixinOfNonClassWithNullSafetyTest); + defineReflectiveTests(MixinOfNonClassWithoutNullSafetyTest); }); } @reflectiveTest class MixinOfNonClassTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with MixinOfNonClassTestCases { + test_Never() async { + await assertErrorsInCode(''' +class A with Never {} +''', [ + error(CompileTimeErrorCode.MIXIN_OF_NON_CLASS, 13, 5), + ]); + } +} + +mixin MixinOfNonClassTestCases on PubPackageResolutionTest { test_class() async { await assertErrorsInCode(r''' int A = 7; @@ -165,13 +175,5 @@ class C with p.M {} } @reflectiveTest -class MixinOfNonClassWithNullSafetyTest extends MixinOfNonClassTest - with WithNullSafetyMixin { - test_Never() async { - await assertErrorsInCode(''' -class A with Never {} -''', [ - error(CompileTimeErrorCode.MIXIN_OF_NON_CLASS, 13, 5), - ]); - } -} +class MixinOfNonClassWithoutNullSafetyTest extends PubPackageResolutionTest + with MixinOfNonClassTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart index 204e6140f54..08db55e2ad2 100644 --- a/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mixin_super_class_constraint_non_interface_test.dart @@ -10,18 +10,12 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(MixinSuperClassConstraintNonInterfaceTest); - defineReflectiveTests( - MixinSuperClassConstraintNonInterfaceWithNullSafetyTest); }); } @reflectiveTest -class MixinSuperClassConstraintNonInterfaceTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin {} - -@reflectiveTest -class MixinSuperClassConstraintNonInterfaceWithNullSafetyTest - extends MixinSuperClassConstraintNonInterfaceTest with WithNullSafetyMixin { +class MixinSuperClassConstraintNonInterfaceTest + extends PubPackageResolutionTest { test_Never() async { await assertErrorsInCode(''' mixin M on Never {} diff --git a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart index d36da7526c3..d77df25dfb5 100644 --- a/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart +++ b/pkg/analyzer/test/src/diagnostics/non_constant_case_expression_test.dart @@ -10,13 +10,15 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NonConstantCaseExpressionTest); - defineReflectiveTests(NonConstantCaseExpressionWithNullSafetyTest); + defineReflectiveTests(NonConstantCaseExpressionWithoutNullSafetyTest); }); } @reflectiveTest class NonConstantCaseExpressionTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with NonConstantCaseExpressionTestCases {} + +mixin NonConstantCaseExpressionTestCases on PubPackageResolutionTest { test_constField() async { await assertNoErrorsInCode(r''' void f(C e) { @@ -66,5 +68,6 @@ void f(var e) { } @reflectiveTest -class NonConstantCaseExpressionWithNullSafetyTest - extends NonConstantCaseExpressionTest with WithNullSafetyMixin {} +class NonConstantCaseExpressionWithoutNullSafetyTest + extends PubPackageResolutionTest + with NonConstantCaseExpressionTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart b/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart index c0257146b2a..3c008f90f6e 100644 --- a/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart +++ b/pkg/analyzer/test/src/diagnostics/not_map_spread_test.dart @@ -10,13 +10,13 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(NotMapSpreadTest); - defineReflectiveTests(NotMapSpreadNullSafetyTest); + defineReflectiveTests(NotMapSpreadWithoutNullSafetyTest); }); } @reflectiveTest -class NotMapSpreadNullSafetyTest extends NotMapSpreadTest - with WithNullSafetyMixin { +class NotMapSpreadTest extends PubPackageResolutionTest + with NotMapSpreadTestCases { test_map_typeParameter_bound_mapQuestion() async { await assertNoErrorsInCode(''' void f?>(T a) { @@ -27,9 +27,7 @@ void f?>(T a) { } } -@reflectiveTest -class NotMapSpreadTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { +mixin NotMapSpreadTestCases on PubPackageResolutionTest { test_map() async { await assertNoErrorsInCode(''' var a = {0: 0}; @@ -100,3 +98,7 @@ void f(T a) { ]); } } + +@reflectiveTest +class NotMapSpreadWithoutNullSafetyTest extends PubPackageResolutionTest + with NotMapSpreadTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart index 1e976ed871a..9a5d8e7d0cd 100644 --- a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart @@ -10,13 +10,46 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnOfInvalidTypeForCatchErrorTest); - defineReflectiveTests(ReturnOfInvalidTypeForCatchErrorWithNullSafetyTest); + defineReflectiveTests( + ReturnOfInvalidTypeForCatchErrorWithoutNullSafetyTest); }); } @reflectiveTest class ReturnOfInvalidTypeForCatchErrorTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with ReturnOfInvalidTypeForCatchErrorTestCases { + test_nullableType_emptyBody() async { + await assertNoErrorsInCode(''' +void f(Future future) { + future.catchError((e, st) {}); +} +'''); + } + + test_nullableType_emptyReturn() async { + await assertErrorsInCode(''' +void f(Future future) { + future.catchError((e, st) { + return; + }); +} +''', [ + error(CompileTimeErrorCode.RETURN_WITHOUT_VALUE, 64, 6), + ]); + } + + test_nullableType_invalidReturnType() async { + await assertErrorsInCode(''' +void f(Future future) { + future.catchError((e, st) => ''); +} +''', [ + error(HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 61, 2), + ]); + } +} + +mixin ReturnOfInvalidTypeForCatchErrorTestCases on PubPackageResolutionTest { test_async_okReturnType() async { await assertNoErrorsInCode(''' void f(Future future) { @@ -167,35 +200,6 @@ void f(Future future, void Function() g) { } @reflectiveTest -class ReturnOfInvalidTypeForCatchErrorWithNullSafetyTest - extends ReturnOfInvalidTypeForCatchErrorTest with WithNullSafetyMixin { - test_nullableType_emptyBody() async { - await assertNoErrorsInCode(''' -void f(Future future) { - future.catchError((e, st) {}); -} -'''); - } - - test_nullableType_emptyReturn() async { - await assertErrorsInCode(''' -void f(Future future) { - future.catchError((e, st) { - return; - }); -} -''', [ - error(CompileTimeErrorCode.RETURN_WITHOUT_VALUE, 64, 6), - ]); - } - - test_nullableType_invalidReturnType() async { - await assertErrorsInCode(''' -void f(Future future) { - future.catchError((e, st) => ''); -} -''', [ - error(HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 61, 2), - ]); - } -} +class ReturnOfInvalidTypeForCatchErrorWithoutNullSafetyTest + extends PubPackageResolutionTest + with ReturnOfInvalidTypeForCatchErrorTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_test.dart b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_test.dart index cfe890278ca..5f7f7cb33ea 100644 --- a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_test.dart @@ -11,13 +11,85 @@ main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnOfInvalidTypeTest); defineReflectiveTests(ReturnOfInvalidTypeWithNoImplicitCastsTest); - defineReflectiveTests(ReturnOfInvalidTypeWithNullSafetyTest); + defineReflectiveTests(ReturnOfInvalidTypeWithoutNullSafetyTest); }); } @reflectiveTest class ReturnOfInvalidTypeTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with ReturnOfInvalidTypeTestCases { + test_function_async_block_int__to_Future_void() async { + await assertErrorsInCode(r''' +Future f() async { + return 0; +} +''', [ + error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 34, 1), + ]); + } + + test_function_async_block_void__to_Future_Null() async { + await assertErrorsInCode(r''' +Future f(void a) async { + return a; +} +''', [ + error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 40, 1), + ]); + } + + test_function_async_block_void__to_FutureOr_ObjectQ() async { + await assertErrorsInCode(r''' +import 'dart:async'; + +FutureOr f(void a) async { + return a; +} +''', [ + error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 67, 1), + ]); + } + + test_function_async_expression_dynamic__to_Future_int() async { + await assertNoErrorsInCode(r''' +Future f(dynamic a) async => a; +'''); + } + + test_functionExpression_async_futureOr_void__to_Object() async { + await assertNoErrorsInCode(r''' +void a = null; + +Object Function() f = () async { + return a; +}; +'''); + } + + test_functionExpression_async_futureQ_void__to_Object() async { + await assertNoErrorsInCode(r''' +Future? a = (throw 0); + +Object Function() f = () async { + return a; +}; +'''); + } + + test_functionExpression_async_void__to_FutureOr_ObjectQ() async { + await assertNoErrorsInCode(r''' +import 'dart:async'; + +void a = (throw 0); + +FutureOr Function() f = () async { + return a; +}; +'''); + } +} + +mixin ReturnOfInvalidTypeTestCases on PubPackageResolutionTest { test_closure() async { await assertErrorsInCode(''' typedef Td = int Function(); @@ -415,75 +487,5 @@ Future> f() async { } @reflectiveTest -class ReturnOfInvalidTypeWithNullSafetyTest extends ReturnOfInvalidTypeTest - with WithNullSafetyMixin { - test_function_async_block_int__to_Future_void() async { - await assertErrorsInCode(r''' -Future f() async { - return 0; -} -''', [ - error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 34, 1), - ]); - } - - test_function_async_block_void__to_Future_Null() async { - await assertErrorsInCode(r''' -Future f(void a) async { - return a; -} -''', [ - error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 40, 1), - ]); - } - - test_function_async_block_void__to_FutureOr_ObjectQ() async { - await assertErrorsInCode(r''' -import 'dart:async'; - -FutureOr f(void a) async { - return a; -} -''', [ - error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 67, 1), - ]); - } - - test_function_async_expression_dynamic__to_Future_int() async { - await assertNoErrorsInCode(r''' -Future f(dynamic a) async => a; -'''); - } - - test_functionExpression_async_futureOr_void__to_Object() async { - await assertNoErrorsInCode(r''' -void a = null; - -Object Function() f = () async { - return a; -}; -'''); - } - - test_functionExpression_async_futureQ_void__to_Object() async { - await assertNoErrorsInCode(r''' -Future? a = (throw 0); - -Object Function() f = () async { - return a; -}; -'''); - } - - test_functionExpression_async_void__to_FutureOr_ObjectQ() async { - await assertNoErrorsInCode(r''' -import 'dart:async'; - -void a = (throw 0); - -FutureOr Function() f = () async { - return a; -}; -'''); - } -} +class ReturnOfInvalidTypeWithoutNullSafetyTest extends PubPackageResolutionTest + with ReturnOfInvalidTypeTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart b/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart index fd534d0849a..b5a19e87c71 100644 --- a/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart @@ -10,13 +10,25 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnTypeInvalidForCatchErrorTest); - defineReflectiveTests(ReturnTypeInvalidForCatchErrorWithNullSafetyTest); + defineReflectiveTests(ReturnTypeInvalidForCatchErrorWithoutNullSafetyTest); }); } @reflectiveTest class ReturnTypeInvalidForCatchErrorTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with ReturnTypeInvalidForCatchErrorTestCases { + test_nullableReturnType() async { + await assertErrorsInCode(''' +void f(Future future, String? Function(dynamic, StackTrace) cb) { + future.catchError(cb); +} +''', [ + error(HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, 91, 2), + ]); + } +} + +mixin ReturnTypeInvalidForCatchErrorTestCases on PubPackageResolutionTest { test_dynamic_returnTypeIsUnrelatedFuture() async { await assertNoErrorsInCode(''' void f( @@ -87,15 +99,6 @@ void f(Future future, String Function(dynamic, StackTrace) cb) { } @reflectiveTest -class ReturnTypeInvalidForCatchErrorWithNullSafetyTest - extends ReturnTypeInvalidForCatchErrorTest with WithNullSafetyMixin { - test_nullableReturnType() async { - await assertErrorsInCode(''' -void f(Future future, String? Function(dynamic, StackTrace) cb) { - future.catchError(cb); -} -''', [ - error(HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, 91, 2), - ]); - } -} +class ReturnTypeInvalidForCatchErrorWithoutNullSafetyTest + extends PubPackageResolutionTest + with ReturnTypeInvalidForCatchErrorTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/return_without_value_test.dart b/pkg/analyzer/test/src/diagnostics/return_without_value_test.dart index f90e7e6f502..b6149bb18a1 100644 --- a/pkg/analyzer/test/src/diagnostics/return_without_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_without_value_test.dart @@ -10,13 +10,15 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnWithoutValueTest); - defineReflectiveTests(ReturnWithoutValueWithNullSafetyTest); + defineReflectiveTests(ReturnWithoutValueWithoutNullSafetyTest); }); } @reflectiveTest class ReturnWithoutValueTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with ReturnWithoutValueTestCases {} + +mixin ReturnWithoutValueTestCases on PubPackageResolutionTest { test_async_futureInt() async { await assertErrorsInCode(''' Future f() async { @@ -163,5 +165,5 @@ int f(int x) { } @reflectiveTest -class ReturnWithoutValueWithNullSafetyTest extends ReturnWithoutValueTest - with WithNullSafetyMixin {} +class ReturnWithoutValueWithoutNullSafetyTest extends PubPackageResolutionTest + with ReturnWithoutValueTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_never_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_never_test.dart index 4773eaeda45..ad2aa2d1f25 100644 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_never_test.dart +++ b/pkg/analyzer/test/src/diagnostics/sdk_version_never_test.dart @@ -11,25 +11,12 @@ import 'sdk_constraint_verifier_support.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SdkVersionNeverTest); - defineReflectiveTests(SdkVersionNeverWithNullSafetyTest); + defineReflectiveTests(SdkVersionNeverWithoutNullSafetyTest); }); } @reflectiveTest -class SdkVersionNeverTest extends SdkConstraintVerifierTest - with WithoutNullSafetyMixin { - test_languageVersionBeforeNullSafety() async { - await verifyVersion('2.7.0', r''' -Never foo; -''', expectedErrors: [ - error(HintCode.SDK_VERSION_NEVER, 0, 5), - ]); - } -} - -@reflectiveTest -class SdkVersionNeverWithNullSafetyTest extends SdkConstraintVerifierTest - with WithNullSafetyMixin { +class SdkVersionNeverTest extends SdkConstraintVerifierTest { test_experimentEnabled() async { await verifyVersion('2.7.0', r''' Never foo = (throw 42); @@ -45,3 +32,15 @@ Never foo = (throw 42); ]); } } + +@reflectiveTest +class SdkVersionNeverWithoutNullSafetyTest extends SdkConstraintVerifierTest + with WithoutNullSafetyMixin { + test_languageVersionBeforeNullSafety() async { + await verifyVersion('2.7.0', r''' +Never foo; +''', expectedErrors: [ + error(HintCode.SDK_VERSION_NEVER, 0, 5), + ]); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart b/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart index 001d9470a86..fdfa18277cc 100644 --- a/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_parameter_supertype_of_its_bound_test.dart @@ -10,13 +10,16 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeParameterSupertypeOfItsBoundTest); - defineReflectiveTests(TypeParameterSupertypeOfItsBoundWithNullSafetyTest); + defineReflectiveTests( + TypeParameterSupertypeOfItsBoundWithoutNullSafetyTest); }); } @reflectiveTest class TypeParameterSupertypeOfItsBoundTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with TypeParameterSupertypeOfItsBoundTestCases {} + +mixin TypeParameterSupertypeOfItsBoundTestCases on PubPackageResolutionTest { test_1of1() async { await assertErrorsInCode(r''' class A { @@ -50,5 +53,6 @@ class A { } @reflectiveTest -class TypeParameterSupertypeOfItsBoundWithNullSafetyTest - extends TypeParameterSupertypeOfItsBoundTest with WithNullSafetyMixin {} +class TypeParameterSupertypeOfItsBoundWithoutNullSafetyTest + extends PubPackageResolutionTest + with TypeParameterSupertypeOfItsBoundTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/undefined_hidden_name_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_hidden_name_test.dart index 6fcfad309a7..cf1eba2b94b 100644 --- a/pkg/analyzer/test/src/diagnostics/undefined_hidden_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/undefined_hidden_name_test.dart @@ -10,13 +10,15 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UndefinedHiddenNameTest); - defineReflectiveTests(UndefinedHiddenNameWithNullSafetyTest); + defineReflectiveTests(UndefinedHiddenNameWithoutNullSafetyTest); }); } @reflectiveTest class UndefinedHiddenNameTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with UndefinedHiddenNameTestCases {} + +mixin UndefinedHiddenNameTestCases on PubPackageResolutionTest { test_export() async { newFile('$testPackageLibPath/lib1.dart'); await assertErrorsInCode(r''' @@ -38,5 +40,5 @@ import 'lib1.dart' hide a; } @reflectiveTest -class UndefinedHiddenNameWithNullSafetyTest extends UndefinedHiddenNameTest - with WithNullSafetyMixin {} +class UndefinedHiddenNameWithoutNullSafetyTest extends PubPackageResolutionTest + with UndefinedHiddenNameTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/undefined_identifier_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_identifier_test.dart index 2b0b5a5c3ab..c339039bf98 100644 --- a/pkg/analyzer/test/src/diagnostics/undefined_identifier_test.dart +++ b/pkg/analyzer/test/src/diagnostics/undefined_identifier_test.dart @@ -11,13 +11,38 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UndefinedIdentifierTest); - defineReflectiveTests(UndefinedIdentifierWithNullSafetyTest); + defineReflectiveTests(UndefinedIdentifierWithoutNullSafetyTest); }); } @reflectiveTest class UndefinedIdentifierTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with UndefinedIdentifierTestCases { + test_get_from_external_variable_final_valid() async { + await assertNoErrorsInCode(''' +external final int x; +int f() => x; +'''); + } + + test_get_from_external_variable_valid() async { + await assertNoErrorsInCode(''' +external int x; +int f() => x; +'''); + } + + test_set_external_variable_valid() async { + await assertNoErrorsInCode(''' +external int x; +void f(int value) { + x = value; +} +'''); + } +} + +mixin UndefinedIdentifierTestCases on PubPackageResolutionTest { test_annotation_favors_scope_resolution_over_this_resolution_class() async { // If an annotation on a class type parameter cannot be resolved using the // normal scope resolution mechanism, it is resolved via implicit `this`. @@ -397,28 +422,5 @@ void f(int p) { } @reflectiveTest -class UndefinedIdentifierWithNullSafetyTest extends UndefinedIdentifierTest - with WithNullSafetyMixin { - test_get_from_external_variable_final_valid() async { - await assertNoErrorsInCode(''' -external final int x; -int f() => x; -'''); - } - - test_get_from_external_variable_valid() async { - await assertNoErrorsInCode(''' -external int x; -int f() => x; -'''); - } - - test_set_external_variable_valid() async { - await assertNoErrorsInCode(''' -external int x; -void f(int value) { - x = value; -} -'''); - } -} +class UndefinedIdentifierWithoutNullSafetyTest extends PubPackageResolutionTest + with UndefinedIdentifierTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/undefined_shown_name_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_shown_name_test.dart index ea89f9a3652..f486367ac00 100644 --- a/pkg/analyzer/test/src/diagnostics/undefined_shown_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/undefined_shown_name_test.dart @@ -10,13 +10,15 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UndefinedShownNameTest); - defineReflectiveTests(UndefinedShownNameWithNullSafetyTest); + defineReflectiveTests(UndefinedShownNameWithoutNullSafetyTest); }); } @reflectiveTest class UndefinedShownNameTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with UndefinedShownNameTestCases {} + +mixin UndefinedShownNameTestCases on PubPackageResolutionTest { test_export() async { newFile('$testPackageLibPath/lib1.dart'); await assertErrorsInCode(r''' @@ -38,5 +40,5 @@ import 'lib1.dart' show a; } @reflectiveTest -class UndefinedShownNameWithNullSafetyTest extends UndefinedShownNameTest - with WithNullSafetyMixin {} +class UndefinedShownNameWithoutNullSafetyTest extends PubPackageResolutionTest + with UndefinedShownNameTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart b/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart index 65e5479c96b..fef92e86e1d 100644 --- a/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart +++ b/pkg/analyzer/test/src/diagnostics/unnecessary_type_check_test.dart @@ -10,15 +10,36 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UnnecessaryTypeCheckFalseTest); - defineReflectiveTests(UnnecessaryTypeCheckFalseWithNullSafetyTest); + defineReflectiveTests(UnnecessaryTypeCheckFalseWithoutNullSafetyTest); defineReflectiveTests(UnnecessaryTypeCheckTrueTest); - defineReflectiveTests(UnnecessaryTypeCheckTrueWithNullSafetyTest); + defineReflectiveTests(UnnecessaryTypeCheckTrueWithoutNullSafetyTest); }); } @reflectiveTest class UnnecessaryTypeCheckFalseTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with UnnecessaryTypeCheckFalseTestCases { + @override + test_type_not_object() async { + await assertNoErrorsInCode(r''' +void f(T a) { + a is! Object; +} +'''); + } + + test_type_not_objectQuestion() async { + await assertErrorsInCode(r''' +void f(T a) { + a is! Object?; +} +''', [ + error(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, 19, 13), + ]); + } +} + +mixin UnnecessaryTypeCheckFalseTestCases on PubPackageResolutionTest { test_null_not_Null() async { await assertErrorsInCode(r''' var b = null is! Null; @@ -49,31 +70,34 @@ void f(T a) { } @reflectiveTest -class UnnecessaryTypeCheckFalseWithNullSafetyTest - extends UnnecessaryTypeCheckFalseTest with WithNullSafetyMixin { +class UnnecessaryTypeCheckFalseWithoutNullSafetyTest + extends PubPackageResolutionTest + with UnnecessaryTypeCheckFalseTestCases, WithoutNullSafetyMixin {} + +@reflectiveTest +class UnnecessaryTypeCheckTrueTest extends PubPackageResolutionTest + with UnnecessaryTypeCheckTrueTestCases { @override - test_type_not_object() async { + test_type_is_object() async { await assertNoErrorsInCode(r''' void f(T a) { - a is! Object; + a is Object; } '''); } - test_type_not_objectQuestion() async { + test_type_is_objectQuestion() async { await assertErrorsInCode(r''' void f(T a) { - a is! Object?; + a is Object?; } ''', [ - error(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, 19, 13), + error(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, 19, 12), ]); } } -@reflectiveTest -class UnnecessaryTypeCheckTrueTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { +mixin UnnecessaryTypeCheckTrueTestCases on PubPackageResolutionTest { test_null_is_Null() async { await assertErrorsInCode(r''' var b = null is Null; @@ -104,24 +128,6 @@ void f(T a) { } @reflectiveTest -class UnnecessaryTypeCheckTrueWithNullSafetyTest - extends UnnecessaryTypeCheckTrueTest with WithNullSafetyMixin { - @override - test_type_is_object() async { - await assertNoErrorsInCode(r''' -void f(T a) { - a is Object; -} -'''); - } - - test_type_is_objectQuestion() async { - await assertErrorsInCode(r''' -void f(T a) { - a is Object?; -} -''', [ - error(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, 19, 12), - ]); - } -} +class UnnecessaryTypeCheckTrueWithoutNullSafetyTest + extends PubPackageResolutionTest + with UnnecessaryTypeCheckTrueTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/yield_of_invalid_type_test.dart b/pkg/analyzer/test/src/diagnostics/yield_of_invalid_type_test.dart index 072b7337943..ddb8c9ce124 100644 --- a/pkg/analyzer/test/src/diagnostics/yield_of_invalid_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/yield_of_invalid_type_test.dart @@ -10,13 +10,15 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(YieldOfInvalidTypeTest); - defineReflectiveTests(YieldOfInvalidTypeWithNullSafetyTest); + defineReflectiveTests(YieldOfInvalidTypeWithoutNullSafetyTest); }); } @reflectiveTest class YieldOfInvalidTypeTest extends PubPackageResolutionTest - with WithoutNullSafetyMixin { + with YieldOfInvalidTypeTestCases {} + +mixin YieldOfInvalidTypeTestCases on PubPackageResolutionTest { test_none_asyncStar_dynamic_to_streamInt() async { await assertErrorsInCode( ''' @@ -448,5 +450,5 @@ Iterable g() => throw 0; } @reflectiveTest -class YieldOfInvalidTypeWithNullSafetyTest extends YieldOfInvalidTypeTest - with WithNullSafetyMixin {} +class YieldOfInvalidTypeWithoutNullSafetyTest extends PubPackageResolutionTest + with YieldOfInvalidTypeTestCases, WithoutNullSafetyMixin {}