diff --git a/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart b/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart index bda20eb03ca..0bfdf0e1373 100644 --- a/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart +++ b/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecordLiteralOnePositionalNoTrailingCommaTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,40 +18,37 @@ main() { class RecordLiteralOnePositionalNoTrailingCommaTest extends PubPackageResolutionTest { test_argument_invalid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) i) { f(('')); +// ^^ +// [diag.argumentTypeNotAssignable] The argument type 'String' can't be assigned to the parameter type '(int,)'. } -''', - [error(diag.argumentTypeNotAssignable, 24, 2)], - ); +'''); } test_argument_notParenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) i) { f(1); +// ^ +// [diag.argumentTypeNotAssignable] The argument type 'int' can't be assigned to the parameter type '(int,)'. } -''', - [error(diag.argumentTypeNotAssignable, 23, 1)], - ); +'''); } test_argument_parenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) i) { f((1)); +// ^^^ +// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma. } -''', - [error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 23, 3)], - ); +'''); } test_argument_valid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) i) { f((1,)); } @@ -58,40 +56,37 @@ void f((int,) i) { } test_assignment_invalid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) r) { r = (''); +// ^^^^ +// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type '(int,)'. } -''', - [error(diag.invalidAssignment, 25, 4)], - ); +'''); } test_assignment_notParenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) r) { r = 1; +// ^ +// [diag.invalidAssignment] A value of type 'int' can't be assigned to a variable of type '(int,)'. } -''', - [error(diag.invalidAssignment, 25, 1)], - ); +'''); } test_assignment_parenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) r) { r = (1); +// ^^^ +// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma. } -''', - [error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 25, 3)], - ); +'''); } test_assignment_valid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f((int,) r) { r = (1,); } @@ -99,89 +94,81 @@ void f((int,) r) { } test_declaration() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) r = (1); -''', - [error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 11, 3)], - ); +// ^^^ +// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma. +'''); } test_declaration_invalid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) r = (''); -''', - [error(diag.invalidAssignment, 12, 2)], - ); +// ^^ +// [diag.invalidAssignment] A value of type 'String' can't be assigned to a variable of type '(int,)'. +'''); } test_declaration_valid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' (int,) r = (1,); '''); } test_return_blockBody_notParenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() { return 1; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of '(int,)'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 22, 1)], - ); +'''); } test_return_blockBody_parenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() { return (1); +// ^^^ +// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma. } -''', - [error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 22, 3)], - ); +'''); } test_return_expressionBody_invalid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() => (''); -''', - [error(diag.returnOfInvalidTypeFromFunction, 14, 4)], - ); +// ^^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of '(int,)'. +'''); } test_return_expressionBody_notParenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() => 1; -''', - [error(diag.returnOfInvalidTypeFromFunction, 14, 1)], - ); +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of '(int,)'. +'''); } test_return_expressionBody_parenthesized() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() => (1); -''', - [error(diag.recordLiteralOnePositionalNoTrailingCommaByType, 14, 3)], - ); +// ^^^ +// [diag.recordLiteralOnePositionalNoTrailingCommaByType] A record literal with exactly one positional field requires a trailing comma. +'''); } test_return_invalid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() { return (''); } -''', - [error(diag.returnOfInvalidTypeFromFunction, 20, 4)], - ); +// ^^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of '(int,)'. +'''); } test_return_valid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' (int,) f() { return (1,); } '''); } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_compile_time_constant_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_compile_time_constant_test.dart index 2309d7bc003..7acaed8b360 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_compile_time_constant_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_compile_time_constant_test.dart @@ -2,73 +2,67 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveCompileTimeConstantTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RecursiveCompileTimeConstantTest extends PubPackageResolutionTest { test_cycle() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const x = y + 1; +// ^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. const y = x + 1; -''', - [ - error(diag.recursiveCompileTimeConstant, 6, 1), - error(diag.recursiveCompileTimeConstant, 23, 1), - ], - ); +// ^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. +'''); } test_enum_constant_values() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v(values); +//^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. const E(Object a); } -''', - [error(diag.recursiveCompileTimeConstant, 11, 1)], - ); +'''); } test_enum_constants() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v1(v2), v2(v1); +//^^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. +// ^^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. const E(E other); } -''', - [ - error(diag.recursiveCompileTimeConstant, 11, 2), - error(diag.recursiveCompileTimeConstant, 19, 2), - ], - ); +'''); } test_enum_fields() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; static const x = y + 1; +// ^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. static const y = x + 1; +// ^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. } -''', - [ - error(diag.recursiveCompileTimeConstant, 29, 1), - error(diag.recursiveCompileTimeConstant, 55, 1), - ], - ); +'''); } test_fromMapLiteral() async { @@ -77,31 +71,29 @@ const int x = y; const int y = x; '''); // No errors, because the cycle is not in this source. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'constants.dart'; final z = {x: 0, y: 1}; '''); } test_singleVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const x = x; -''', - [error(diag.recursiveCompileTimeConstant, 6, 1)], - ); +// ^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. +'''); } test_singleVariable_fromConstList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' const elems = const [ +// ^^^^^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. const [ 1, elems, 3, ], ]; -''', - [error(diag.recursiveCompileTimeConstant, 6, 5)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_constant_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_constant_constructor_test.dart index 012ee79b72a..a3a042bfe83 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_constant_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_constant_constructor_test.dart @@ -2,103 +2,94 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveConstantConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RecursiveConstantConstructorTest extends PubPackageResolutionTest { test_newHead_named_redirectingConstructorInvocation() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const new named() : this.named(); +// ^^^^^^^^^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. +// ^^^^^^^^^^^^ +// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.recursiveConstantConstructor, 18, 9), - error(diag.recursiveConstructorRedirect, 32, 12), - ], - ); +'''); } test_newHead_unnamed_redirectingConstructorInvocation() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const new () : this(); +// ^^^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. +// ^^^^^^ +// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.recursiveConstantConstructor, 18, 3), - error(diag.recursiveConstructorRedirect, 27, 6), - ], - ); +'''); } test_typeName_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(); +// ^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. final m = const A(); } -''', - [error(diag.recursiveConstantConstructor, 18, 1)], - ); +'''); } test_typeName_initializer_after_toplevel_var() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' const y = const C(); +// ^ +// [diag.recursiveCompileTimeConstant] The compile-time constant expression depends on itself. class C { const C() : x = y; +// ^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. final x; } -''', - [ - error(diag.recursiveCompileTimeConstant, 6, 1), - error(diag.recursiveConstantConstructor, 39, 1), - ], - ); +'''); } test_typeName_initializer_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { final A a; const A() : a = const A(); +// ^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. } -''', - [error(diag.recursiveConstantConstructor, 31, 1)], - ); +'''); } test_typeName_initializer_field_multipleClasses() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class B { final A a; const B() : a = const A(); +// ^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. } class A { final B b; const A() : b = const B(); +// ^ +// [diag.recursiveConstantConstructor] The constant constructor depends on itself. } -''', - [ - error(diag.recursiveConstantConstructor, 31, 1), - error(diag.recursiveConstantConstructor, 85, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_constructor_redirect_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_constructor_redirect_test.dart index 15b3aac976b..18c700425ac 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_constructor_redirect_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_constructor_redirect_test.dart @@ -2,47 +2,45 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveConstructorRedirectTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RecursiveConstructorRedirectTest extends PubPackageResolutionTest { test_directSelfReference() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() : this(); +// ^^^^^^ +// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [error(diag.recursiveConstructorRedirect, 18, 6)], - ); +'''); } test_recursive() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.a() : this.b(); +// ^^^^^^^^ +// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly. A.b() : this.a(); +// ^^^^^^^^ +// [diag.recursiveConstructorRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.recursiveConstructorRedirect, 20, 8), - error(diag.recursiveConstructorRedirect, 40, 8), - ], - ); +'''); } test_valid_redirect() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.a() : this.b(); A.b() : this.c(); diff --git a/pkg/analyzer/test/src/diagnostics/recursive_factory_redirect_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_factory_redirect_test.dart index eb1eebc8d3e..da41a2b7be2 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_factory_redirect_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_factory_redirect_test.dart @@ -2,146 +2,152 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveFactoryRedirectTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RecursiveFactoryRedirectTest extends PubPackageResolutionTest { test_directSelfReference() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() = A; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [error(diag.recursiveFactoryRedirect, 26, 1)], - ); +'''); } test_diverging() async { // Analysis should terminate even though the redirections don't reach a // fixed point. (C redirects to C>, then to C>>, and // so on). - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { const factory C() = C>; +// ^^^^^^^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } main() { const C(); } -''', - [error(diag.recursiveFactoryRedirect, 35, 7)], - ); +'''); } test_generic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A implements B { +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A. factory A() = C; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class B implements C { +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A. factory B() = A; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class C implements A { +// ^ +// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A. factory C() = B; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveFactoryRedirect, 45, 1), - error(diag.recursiveInterfaceInheritance, 56, 1), - error(diag.recursiveFactoryRedirect, 95, 1), - error(diag.recursiveInterfaceInheritance, 106, 1), - error(diag.recursiveFactoryRedirect, 145, 1), - ], - ); +'''); } test_loop() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A implements B { +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A. factory A() = C; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class B implements C { +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A. factory B() = A; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class C implements A { +// ^ +// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A. factory C() = B; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveFactoryRedirect, 39, 1), - error(diag.recursiveInterfaceInheritance, 50, 1), - error(diag.recursiveFactoryRedirect, 83, 1), - error(diag.recursiveInterfaceInheritance, 94, 1), - error(diag.recursiveFactoryRedirect, 127, 1), - ], - ); +'''); } test_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A implements B { +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A. factory A.nameA() = C.nameC; +// ^^^^^^^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class B implements C { +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A. factory B.nameB() = A.nameA; +// ^^^^^^^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class C implements A { +// ^ +// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A. factory C.nameC() = B.nameB; +// ^^^^^^^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveFactoryRedirect, 45, 7), - error(diag.recursiveInterfaceInheritance, 62, 1), - error(diag.recursiveFactoryRedirect, 101, 7), - error(diag.recursiveInterfaceInheritance, 118, 1), - error(diag.recursiveFactoryRedirect, 157, 7), - ], - ); +'''); } test_outsideCycle() async { // "A" references "C" which has cycle with "B". But we should not report // problem for "A" - it is not the part of a cycle. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() = C; +// ^ +// [diag.redirectToInvalidReturnType] The return type 'C' of the redirected constructor isn't a subtype of 'A'. } class B implements C { +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B. factory B() = C; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } class C implements A, B { +// ^ +// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B. factory C() = B; +// ^ +// [diag.recursiveFactoryRedirect] Constructors can't redirect to themselves either directly or indirectly. } -''', - [ - error(diag.redirectToInvalidReturnType, 26, 1), - error(diag.recursiveInterfaceInheritance, 37, 1), - error(diag.recursiveFactoryRedirect, 70, 1), - error(diag.recursiveInterfaceInheritance, 81, 1), - error(diag.recursiveFactoryRedirect, 117, 1), - ], - ); +'''); } test_valid_redirect() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() = B; } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_extends_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_extends_test.dart index 62839253e1d..778a0d2ca72 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_extends_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_extends_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveInterfaceInheritanceExtendsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,34 +18,29 @@ main() { class RecursiveInterfaceInheritanceExtendsTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A extends A {} -''', - [error(diag.recursiveInterfaceInheritanceExtends, 6, 1)], - ); +// ^ +// [diag.recursiveInterfaceInheritanceExtends] 'A' can't extend itself. +'''); } test_class_abstract() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C extends C { +// ^ +// [diag.recursiveInterfaceInheritanceExtends] 'C' can't extend itself. var foo = 0; bar(); } -''', - [error(diag.recursiveInterfaceInheritanceExtends, 6, 1)], - ); +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_class_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A extends A {} -''', - [error(diag.recursiveInterfaceInheritanceExtends, 6, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_implements_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_implements_test.dart index 9489ebeefc3..2477fa76ee2 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_implements_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_implements_test.dart @@ -6,10 +6,12 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveInterfaceInheritanceImplementsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,51 +19,46 @@ main() { class RecursiveInterfaceInheritanceImplementsTest extends PubPackageResolutionTest { test_class() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements A {} -''', - [error(diag.recursiveInterfaceInheritanceImplements, 6, 1)], - ); +// ^ +// [diag.recursiveInterfaceInheritanceImplements] 'A' can't implement itself. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_class_inAugmentation() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A {} augment class A implements A {} -''', - [error(diag.recursiveInterfaceInheritanceImplements, 6, 1)], - ); +'''); } test_class_tail() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A implements A {} +// ^ +// [diag.recursiveInterfaceInheritanceImplements] 'A' can't implement itself. class B implements A {} -''', - [error(diag.recursiveInterfaceInheritanceImplements, 15, 1)], - ); +'''); } test_classTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} mixin M {} class B = A with M implements B; -''', - [error(diag.recursiveInterfaceInheritanceImplements, 28, 1)], - ); +// ^ +// [diag.recursiveInterfaceInheritanceImplements] 'B' can't implement itself. +'''); } test_mixin() async { await assertErrorsInCode( r''' mixin A implements B {} -mixin B implements A {}''', +mixin B implements A {} +''', [ error(diag.recursiveInterfaceInheritance, 6, 1), error(diag.recursiveInterfaceInheritance, 30, 1), diff --git a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_on_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_on_test.dart index 8e75a06c993..b35ac89f937 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_on_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_on_test.dart @@ -2,49 +2,44 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveInterfaceInheritanceOnTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RecursiveInterfaceInheritanceOnTest extends PubPackageResolutionTest { test_1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A on A {} -''', - [error(diag.recursiveInterfaceInheritanceOn, 6, 1)], - ); +// ^ +// [diag.recursiveInterfaceInheritanceOn] 'A' can't use itself as a superclass constraint. +'''); } @SkippedTest() // TODO(scheglov): implement augmentation test_1_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A {} augment mixin A on A {} -''', - [error(diag.recursiveInterfaceInheritanceOn, 6, 1)], - ); +'''); } test_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin A on B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. mixin B on A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 22, 1), - ], - ); +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_test.dart index ccc7c0f7673..d45d90b132a 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_test.dart @@ -2,140 +2,124 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveInterfaceInheritanceTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RecursiveInterfaceInheritanceTest extends PubPackageResolutionTest { test_class_extends() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A extends B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. class B extends A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 27, 1), - ], - ); +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. +'''); } test_class_extends_implements() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A extends B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. class B implements A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 27, 1), - ], - ); +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. +'''); } test_class_implements() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. class B implements A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 30, 1), - ], - ); +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. +'''); } test_class_implements_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. class B implements A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 36, 1), - ], - ); +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. +'''); } test_class_implements_generic_typeArgument() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements B> {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. class B implements A> {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 42, 1), - ], - ); +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. +'''); } test_class_implements_tail2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A implements B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: B, A. abstract class B implements A {} +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: B, A. class C implements A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 15, 1), - error(diag.recursiveInterfaceInheritance, 48, 1), - ], - ); +'''); } test_class_implements_tail3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A implements B {} +// ^ +// [diag.recursiveInterfaceInheritance] 'A' can't be a superinterface of itself: C, B, A. abstract class B implements C {} +// ^ +// [diag.recursiveInterfaceInheritance] 'B' can't be a superinterface of itself: C, B, A. abstract class C implements A {} +// ^ +// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: C, B, A. class D implements A {} -''', - [ - error(diag.recursiveInterfaceInheritance, 15, 1), - error(diag.recursiveInterfaceInheritance, 48, 1), - error(diag.recursiveInterfaceInheritance, 81, 1), - ], - ); +'''); } test_classTypeAlias_mixin() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class M1 = Object with M2; +// ^^ +// [diag.recursiveInterfaceInheritance] 'M1' can't be a superinterface of itself: M2, M1. mixin class M2 = Object with M1; -''', - [ - error(diag.recursiveInterfaceInheritance, 12, 2), - error(diag.recursiveInterfaceInheritance, 45, 2), - ], - ); +// ^^ +// [diag.recursiveInterfaceInheritance] 'M2' can't be a superinterface of itself: M2, M1. +'''); } test_classTypeAlias_mixin_superclass() async { // Make sure we don't get CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS in // addition--that would just be confusing. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C = D with M; +// ^ +// [diag.recursiveInterfaceInheritance] 'C' can't be a superinterface of itself: D, C. class D = C with M; +// ^ +// [diag.recursiveInterfaceInheritance] 'D' can't be a superinterface of itself: D, C. mixin M {} -''', - [ - error(diag.recursiveInterfaceInheritance, 6, 1), - error(diag.recursiveInterfaceInheritance, 26, 1), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_with_test.dart b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_with_test.dart index 849e1e8b58b..00f0e9a8e92 100644 --- a/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_with_test.dart +++ b/pkg/analyzer/test/src/diagnostics/recursive_interface_inheritance_with_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RecursiveInterfaceInheritanceWithTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,24 +18,17 @@ main() { class RecursiveInterfaceInheritanceWithTest extends PubPackageResolutionTest { @SkippedTest() // TODO(scheglov): implement augmentation test_class_inAugmentation() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A extends Object {} augment class A with A {} -''', - [ - error(diag.recursiveInterfaceInheritanceWith, 6, 1), - error(diag.classUsedAsMixin, 47, 1), - ], - ); +'''); } test_classTypeAlias() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class M = Object with M; -''', - [error(diag.recursiveInterfaceInheritanceWith, 12, 1)], - ); +// ^ +// [diag.recursiveInterfaceInheritanceWith] 'M' can't use itself as a mixin. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/redeclare_on_non_redeclaring_member_test.dart b/pkg/analyzer/test/src/diagnostics/redeclare_on_non_redeclaring_member_test.dart index e8b3fe732cf..a036626b914 100644 --- a/pkg/analyzer/test/src/diagnostics/redeclare_on_non_redeclaring_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redeclare_on_non_redeclaring_member_test.dart @@ -2,15 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:analyzer_testing/package_config_file_builder.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedeclareOnNonRedeclaringMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -23,8 +24,7 @@ class RedeclareOnNonRedeclaringMemberTest extends PubPackageResolutionTest { } test_getter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C {} @@ -32,14 +32,14 @@ class C {} extension type E(C c) implements C { @redeclare int get i => 0; +// ^ +// [diag.redeclareOnNonRedeclaringMember] The getter doesn't redeclare a getter declared in a superinterface. } -''', - [error(diag.redeclareOnNonRedeclaringMember, 106, 1)], - ); +'''); } test_getter_redeclares() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C { @@ -54,8 +54,7 @@ extension type E(C c) implements C { } test_method() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C {} @@ -63,33 +62,30 @@ class C {} extension type E(C c) implements C { @redeclare void n() {} +// ^ +// [diag.redeclareOnNonRedeclaringMember] The method doesn't redeclare a method declared in a superinterface. } -''', - [error(diag.redeclareOnNonRedeclaringMember, 103, 1)], - ); +'''); } test_method_inClass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C {} class D implements C { + // No REDECLARE_ON_NON_REDECLARING_MEMBER warning. @redeclare +// ^^^^^^^^^ +// [diag.invalidAnnotationTarget] The annotation 'redeclare' can only be used on instance members of extension types. void n() {} } -''', - [ - // No REDECLARE_ON_NON_REDECLARING_MEMBER warning. - error(diag.invalidAnnotationTarget, 72, 9), - ], - ); +'''); } test_method_redeclared() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C { @@ -104,45 +100,42 @@ extension type E(C c) implements C { } test_method_redeclared_private() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { void _foo() {} +// ^^^^ +// [diag.unusedElement] The declaration '_foo' isn't referenced. } extension type E(A it) implements A { @redeclare void _foo() {} +// ^^^^ +// [diag.unusedElement] The declaration '_foo' isn't referenced. } -''', - [error(diag.unusedElement, 51, 4), error(diag.unusedElement, 122, 4)], - ); +'''); } test_method_static() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C {} extension type E(C c) implements C { + // No REDECLARE_ON_NON_REDECLARING_MEMBER warning. @redeclare +// ^^^^^^^^^ +// [diag.invalidAnnotationTarget] The annotation 'redeclare' can only be used on instance members of extension types. static void n() {} } -''', - [ - // No REDECLARE_ON_NON_REDECLARING_MEMBER warning. - error(diag.invalidAnnotationTarget, 86, 9), - ], - ); +'''); } test_setter() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C {} @@ -150,14 +143,14 @@ class C {} extension type E(C c) implements C { @redeclare set i(int i) {} +// ^ +// [diag.redeclareOnNonRedeclaringMember] The setter doesn't redeclare a setter declared in a superinterface. } -''', - [error(diag.redeclareOnNonRedeclaringMember, 102, 1)], - ); +'''); } test_setter_redeclares() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C { diff --git a/pkg/analyzer/test/src/diagnostics/redirect_generative_to_missing_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_generative_to_missing_constructor_test.dart index 6ce7b489d9a..0fd709d55cd 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_generative_to_missing_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_generative_to_missing_constructor_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectGenerativeToMissingConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,48 +18,44 @@ main() { class RedirectGenerativeToMissingConstructorTest extends PubPackageResolutionTest { test_class_primary_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A() { this : this.noSuchConstructor(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [error(diag.primaryConstructorCannotRedirect, 21, 4)], - ); +'''); } test_class_typeName_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() : this.noSuchConstructor(); +// ^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.redirectGenerativeToMissingConstructor] The constructor 'A.noSuchConstructor' couldn't be found in 'A'. } -''', - [error(diag.redirectGenerativeToMissingConstructor, 18, 24)], - ); +'''); } test_enum_primary_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E() { v; this : this.noSuchConstructor(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. } -''', - [error(diag.primaryConstructorCannotRedirect, 25, 4)], - ); +'''); } test_enum_typeName_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' enum E { v; const E() : this.noSuchConstructor(); +// ^^^^^^^^^^^^^^^^^^^^^^^^ +// [diag.redirectGenerativeToMissingConstructor] The constructor 'E.noSuchConstructor' couldn't be found in 'E'. } -''', - [error(diag.redirectGenerativeToMissingConstructor, 28, 24)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/redirect_generative_to_non_generative_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_generative_to_non_generative_constructor_test.dart index 5c9da8610c1..8c77c85767e 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_generative_to_non_generative_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_generative_to_non_generative_constructor_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectGenerativeToNonGenerativeConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,26 +18,24 @@ main() { class RedirectGenerativeToNonGenerativeConstructorTest extends PubPackageResolutionTest { test_primary_toFactory() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A() { this : this.x(); +// ^^^^ +// [diag.primaryConstructorCannotRedirect] A primary constructor can't be a redirecting constructor. factory A.x() => throw 0; } -''', - [error(diag.primaryConstructorCannotRedirect, 21, 4)], - ); +'''); } test_typeName_toFactory() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() : this.x(); +// ^^^^^^^^ +// [diag.redirectGenerativeToNonGenerativeConstructor] Generative constructors can't redirect to a factory constructor. factory A.x() => throw 0; } -''', - [error(diag.redirectGenerativeToNonGenerativeConstructor, 18, 8)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_abstract_class_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_abstract_class_constructor_test.dart index 5120ca65982..e4f1fb84c0a 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_abstract_class_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_abstract_class_constructor_test.dart @@ -2,47 +2,46 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectToAbstractClassConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RedirectToAbstractClassConstructorTest extends PubPackageResolutionTest { test_abstractRedirectsToSelf() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { factory A() = A._; +// ^^^ +// [diag.redirectToAbstractClassConstructor] The redirecting constructor 'A' can't redirect to a constructor of the abstract class 'A'. A._(); } -''', - [error(diag.redirectToAbstractClassConstructor, 35, 3)], - ); +'''); } test_redirectsToAbstractSubclass() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A.named() = B; +// ^ +// [diag.redirectToAbstractClassConstructor] The redirecting constructor 'A.named' can't redirect to a constructor of the abstract class 'B'. A(); } abstract class B extends A {} -''', - [error(diag.redirectToAbstractClassConstructor, 32, 1)], - ); +'''); } test_redirectsToSubclass() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A.named() = B; A(); @@ -53,7 +52,7 @@ class B extends A {} } test_redirectsToSubclass_asTypedef() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A.named() = C; A(); diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_function_type_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_function_type_test.dart index fedb82ad7a8..ebbb76bc3e8 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_function_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_function_type_test.dart @@ -2,34 +2,34 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectToInvalidFunctionTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RedirectToInvalidFunctionTypeTest extends PubPackageResolutionTest { test_redirectToInvalidFunctionType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements B { A(int p) {} } class B { factory B() = A; -}''', - [error(diag.redirectToInvalidFunctionType, 65, 1)], - ); +// ^ +// [diag.redirectToInvalidFunctionType] The redirected constructor 'A Function(int)' has incompatible parameters with 'B Function()'. +}'''); } test_valid_redirect() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A implements B { A(int p) {} } diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_return_type_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_return_type_test.dart index b9c3c644e06..9a2676575f9 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_return_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_invalid_return_type_test.dart @@ -2,29 +2,29 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectToInvalidReturnTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RedirectToInvalidReturnTypeTest extends PubPackageResolutionTest { test_redirectToInvalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { A() {} } class B { factory B() = A; -}''', - [error(diag.redirectToInvalidReturnType, 47, 1)], - ); +// ^ +// [diag.redirectToInvalidReturnType] The return type 'A' of the redirected constructor isn't a subtype of 'B'. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_missing_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_missing_constructor_test.dart index 0299887ac87..58c76332afb 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_missing_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_missing_constructor_test.dart @@ -2,42 +2,41 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectToMissingConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RedirectToMissingConstructorTest extends PubPackageResolutionTest { test_named() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements B{ A() {} } class B { factory B() = A.name; -}''', - [error(diag.redirectToMissingConstructor, 59, 6)], - ); +// ^^^^^^ +// [diag.redirectToMissingConstructor] The constructor 'A.name' couldn't be found in 'A'. +}'''); } test_unnamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A implements B{ A.name() {} } class B { factory B() = A; -}''', - [error(diag.redirectToMissingConstructor, 64, 1)], - ); +// ^ +// [diag.redirectToMissingConstructor] The constructor 'A' couldn't be found in 'A'. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_non_class_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_non_class_test.dart index 747a99faa94..d0002488355 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_non_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_non_class_test.dart @@ -2,37 +2,36 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectToNonClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RedirectToNonClassTest extends PubPackageResolutionTest { test_notAType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class B { int A = 0; factory B() = A; -}''', - [error(diag.redirectToNonClass, 39, 1)], - ); +// ^ +// [diag.redirectToNonClass] The name 'A' isn't a type and can't be used in a redirected constructor. +}'''); } test_undefinedIdentifier() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class B { factory B() = A; -}''', - [error(diag.redirectToNonClass, 26, 1)], - ); +// ^ +// [diag.redirectToNonClass] The name 'A' isn't a type and can't be used in a redirected constructor. +}'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_non_const_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_non_const_constructor_test.dart index adf7636cca4..65d857d9e23 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_non_const_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_non_const_constructor_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectToNonConstConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,18 +18,17 @@ main() { class RedirectToNonConstConstructorTest extends PubPackageResolutionTest { test_constRedirector_cannotResolveRedirectee() async { // No crash when redirectee cannot be resolved. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const factory A.b() = A.a; +// ^^^ +// [diag.redirectToMissingConstructor] The constructor 'A.a' couldn't be found in 'A'. } -''', - [error(diag.redirectToMissingConstructor, 34, 3)], - ); +'''); } test_constRedirector_constRedirectee() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.a(); const factory A.b() = A.a; @@ -37,7 +37,7 @@ class A { } test_constRedirector_constRedirectee_generic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A(T value) : this._(value); const A._(T value) : value = value; @@ -51,7 +51,7 @@ void main(){ } test_constRedirector_constRedirectee_viaInitializer() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.a(); const A.b() : this.a(); @@ -60,55 +60,51 @@ class A { } test_constRedirector_nonConstRedirectee() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.a(); const factory A.b() = A.a; +// ^^^ +// [diag.redirectToNonConstConstructor] A constant redirecting constructor can't redirect to a non-constant constructor. } -''', - [error(diag.redirectToNonConstConstructor, 43, 3)], - ); +'''); } test_constRedirector_nonConstRedirectee_viaInitializer() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A.a(); const A.b() : this.a(); +// ^ +// [diag.redirectToNonConstConstructor] A constant redirecting constructor can't redirect to a non-constant constructor. } -''', - [error(diag.redirectToNonConstConstructor, 40, 1)], - ); +'''); } test_constRedirector_nonConstRedirectee_viaInitializer_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A(); const A.named() : this(); +// ^^^^ +// [diag.redirectToNonConstConstructor] A constant redirecting constructor can't redirect to a non-constant constructor. } -''', - [error(diag.redirectToNonConstConstructor, 37, 4)], - ); +'''); } test_constRedirector_viaInitializer_cannotResolveRedirectee() async { // No crash when redirectee cannot be resolved. - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.b() : this.a(); +// ^^^^^^^^ +// [diag.redirectGenerativeToMissingConstructor] The constructor 'A.a' couldn't be found in 'A'. } -''', - [error(diag.redirectGenerativeToMissingConstructor, 26, 8)], - ); +'''); } test_redirect_to_const() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.a(); const factory A.b() = A.a; diff --git a/pkg/analyzer/test/src/diagnostics/redirect_to_type_alias_expands_to_type_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/redirect_to_type_alias_expands_to_type_parameter_test.dart index 81c271a00ec..99c66325dc1 100644 --- a/pkg/analyzer/test/src/diagnostics/redirect_to_type_alias_expands_to_type_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/redirect_to_type_alias_expands_to_type_parameter_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RedirectTypeAliasExpandsToTypeParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,8 +18,7 @@ main() { class RedirectTypeAliasExpandsToTypeParameterTest extends PubPackageResolutionTest { test_generic_typeParameter_withArgument_named() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A implements C { A.named(); } @@ -27,44 +27,42 @@ typedef B = T; class C { factory C() = B.named; +// ^ +// [diag.redirectToTypeAliasExpandsToTypeParameter] A redirecting constructor can't redirect to a type alias that expands to a type parameter. } -''', - [error(diag.redirectToTypeAliasExpandsToTypeParameter, 84, 1)], - ); +'''); } test_generic_typeParameter_withArgument_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A implements C {} typedef B = T; class C { factory C() = B; +// ^ +// [diag.redirectToTypeAliasExpandsToTypeParameter] A redirecting constructor can't redirect to a type alias that expands to a type parameter. } -''', - [error(diag.redirectToTypeAliasExpandsToTypeParameter, 70, 1)], - ); +'''); } test_generic_typeParameter_withoutArgument_unnamed() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A implements C {} typedef B = T; class C { factory C() = B; +// ^ +// [diag.redirectToTypeAliasExpandsToTypeParameter] A redirecting constructor can't redirect to a type alias that expands to a type parameter. } -''', - [error(diag.redirectToTypeAliasExpandsToTypeParameter, 70, 1)], - ); +'''); } test_notGeneric_class_named() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A implements C { A.named(); } @@ -78,7 +76,7 @@ class C { } test_notGeneric_class_unnamed() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A implements C {} typedef B = A; diff --git a/pkg/analyzer/test/src/diagnostics/referenced_before_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/referenced_before_declaration_test.dart index 6be7d7afcc7..3b4699ab7ca 100644 --- a/pkg/analyzer/test/src/diagnostics/referenced_before_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/referenced_before_declaration_test.dart @@ -2,49 +2,44 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReferencedBeforeDeclarationTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReferencedBeforeDeclarationTest extends PubPackageResolutionTest { test_block_patternVariable_after() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 0; void f() { v; +//^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. var [v] = [0]; +// ^ +// [context 1] The declaration of 'v' is here. } -''', - [ - error( - diag.referencedBeforeDeclaration, - 24, - 1, - contextMessages: [message(testFile, 34, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@34 + element: v@149 staticType: InvalidType '''); } test_block_patternVariable_before() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' var v = 0; void f() { var [v] = [0]; @@ -54,7 +49,7 @@ void f() { } test_cascade_after_declaration() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' testRequestHandler() {} main() { @@ -68,156 +63,118 @@ main() { } test_forElement_forPartsWithDeclarations_initializer() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { [for (var x = x;;) x]; +// ^ +// [context 1] The declaration of 'x' is here. +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'x' can't be referenced before it is declared. } -''', - [ - error( - diag.referencedBeforeDeclaration, - 27, - 1, - contextMessages: [message(testFile, 23, 1)], - ), - ], - ); +'''); } test_forStatement_forPartsWithDeclarations_initializer() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { for (var x = x;;) { +// ^ +// [context 1] The declaration of 'x' is here. +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'x' can't be referenced before it is declared. x; } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 26, - 1, - contextMessages: [message(testFile, 22, 1)], - ), - ], - ); +'''); } test_hideInBlock_comment() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' main() { /// [v] is a variable. var v = 2; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'v' isn't used. } print(x) {} -''', - [error(diag.unusedLocalVariable, 40, 1)], - ); +'''); } test_hideInBlock_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 1; main() { print(v); +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. v() {} +//^ +// [context 1] The declaration of 'v' is here. } print(x) {} -''', - [ - error( - diag.referencedBeforeDeclaration, - 28, - 1, - contextMessages: [message(testFile, 34, 1)], - ), - ], - ); +'''); } test_hideInBlock_local() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 1; main() { print(v); +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. var v = 2; +// ^ +// [context 1] The declaration of 'v' is here. } print(x) {} -''', - [ - error( - diag.referencedBeforeDeclaration, - 28, - 1, - contextMessages: [message(testFile, 38, 1)], - ), - ], - ); +'''); } test_hideInBlock_local_subBlock() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 1; main() { { print(v); +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. } var v = 2; +// ^ +// [context 1] The declaration of 'v' is here. } print(x) {} -''', - [ - error( - diag.referencedBeforeDeclaration, - 34, - 1, - contextMessages: [message(testFile, 48, 1)], - ), - ], - ); +'''); } test_hideInSwitchCase_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 0; void f(int a) { switch (a) { case 0: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. void v() {} +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 61, - 1, - contextMessages: [message(testFile, 75, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@75 + element: v@194 staticType: void Function() '''); } test_hideInSwitchCase_function_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 var v = 0; @@ -225,64 +182,52 @@ void f(int a) { switch (a) { case 0: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. void v() {} +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 77, - 1, - contextMessages: [message(testFile, 91, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@91 + element: v@210 staticType: void Function() '''); } test_hideInSwitchCase_local() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 0; void f(int a) { switch (a) { case 0: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. var v = 1; +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 61, - 1, - contextMessages: [message(testFile, 74, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@74 + element: v@193 staticType: dynamic '''); } test_hideInSwitchCase_local_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 var v = 0; @@ -290,64 +235,52 @@ void f(int a) { switch (a) { case 0: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. var v = 1; +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 77, - 1, - contextMessages: [message(testFile, 90, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@90 + element: v@209 staticType: dynamic '''); } test_hideInSwitchDefault_function() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 0; void f(int a) { switch (a) { default: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. void v() {} +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 62, - 1, - contextMessages: [message(testFile, 76, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@76 + element: v@195 staticType: void Function() '''); } test_hideInSwitchDefault_function_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 var v = 0; @@ -355,64 +288,52 @@ void f(int a) { switch (a) { default: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. void v() {} +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 78, - 1, - contextMessages: [message(testFile, 92, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@92 + element: v@211 staticType: void Function() '''); } test_hideInSwitchDefault_local() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var v = 0; void f(int a) { switch (a) { default: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. var v = 1; +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 62, - 1, - contextMessages: [message(testFile, 75, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@75 + element: v@194 staticType: dynamic '''); } test_hideInSwitchDefault_local_language219() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // @dart = 2.19 var v = 0; @@ -420,67 +341,50 @@ void f(int a) { switch (a) { default: v; +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. var v = 1; +// ^ +// [context 1] The declaration of 'v' is here. } } -''', - [ - error( - diag.referencedBeforeDeclaration, - 78, - 1, - contextMessages: [message(testFile, 91, 1)], - ), - ], - ); +'''); var node = findNode.simple('v;'); assertResolvedNodeText(node, r''' SimpleIdentifier token: v - element: v@91 + element: v@210 staticType: dynamic '''); } test_inInitializer_closure() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' main() { var v = () => v; +// ^ +// [context 1] The declaration of 'v' is here. +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. } -''', - [ - error( - diag.referencedBeforeDeclaration, - 25, - 1, - contextMessages: [message(testFile, 15, 1)], - ), - ], - ); +'''); } test_inInitializer_directly() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' main() { var v = v; +// ^ +// [context 1] The declaration of 'v' is here. +// ^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'v' can't be referenced before it is declared. } -''', - [ - error( - diag.referencedBeforeDeclaration, - 19, - 1, - contextMessages: [message(testFile, 15, 1)], - ), - ], - ); +'''); } test_labeledStatement_function() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_label label: void v() {} @@ -498,7 +402,7 @@ SimpleIdentifier } test_labeledStatement_local() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { // ignore:unused_label label: var v = 0; @@ -516,42 +420,30 @@ SimpleIdentifier } test_type_localFunction() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void testTypeRef() { String s = ''; +//^^^^^^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'String' can't be referenced before it is declared. int String(int x) => x + 1; +// ^^^^^^ +// [context 1] The declaration of 'String' is here. print(s + String); } -''', - [ - error( - diag.referencedBeforeDeclaration, - 23, - 6, - contextMessages: [message(testFile, 44, 6)], - ), - ], - ); +'''); } test_type_localVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void testTypeRef() { String s = ''; +//^^^^^^ +// [diag.referencedBeforeDeclaration][context 1] Local variable 'String' can't be referenced before it is declared. var String = ''; +// ^^^^^^ +// [context 1] The declaration of 'String' is here. print(s + String); } -''', - [ - error( - diag.referencedBeforeDeclaration, - 23, - 6, - contextMessages: [message(testFile, 44, 6)], - ), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/refutable_pattern_in_irrefutable_context_test.dart b/pkg/analyzer/test/src/diagnostics/refutable_pattern_in_irrefutable_context_test.dart index 08cb5a6a5f3..0402eb271c6 100644 --- a/pkg/analyzer/test/src/diagnostics/refutable_pattern_in_irrefutable_context_test.dart +++ b/pkg/analyzer/test/src/diagnostics/refutable_pattern_in_irrefutable_context_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RefutablePatternInIrrefutableContextTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,14 +18,13 @@ main() { class RefutablePatternInIrrefutableContextTest extends PubPackageResolutionTest { test_declaration_constantPattern() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var (0) = 0; +// ^ +// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context. } -''', - [error(diag.refutablePatternInIrrefutableContext, 18, 1)], - ); +'''); var node = findNode.singlePatternVariableDeclaration; assertResolvedNodeText(node, r''' @@ -48,17 +48,15 @@ PatternVariableDeclaration } test_declaration_logicalOrPattern() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var (_ || _) = 0; +// ^^^^^^ +// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context. +// ^^^^ +// [diag.deadCode] Dead code. } -''', - [ - error(diag.refutablePatternInIrrefutableContext, 18, 6), - error(diag.deadCode, 20, 4), - ], - ); +'''); var node = findNode.singlePatternVariableDeclaration; assertResolvedNodeText(node, r''' @@ -86,14 +84,13 @@ PatternVariableDeclaration } test_declaration_nullCheckPattern() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(int? x) { var (_?) = x; +// ^^ +// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context. } -''', - [error(diag.refutablePatternInIrrefutableContext, 24, 2)], - ); +'''); var node = findNode.singlePatternVariableDeclaration; assertResolvedNodeText(node, r''' @@ -119,14 +116,13 @@ PatternVariableDeclaration } test_declaration_relationalPattern() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var (> 0) = 0; +// ^^^ +// [diag.refutablePatternInIrrefutableContext] Refutable patterns can't be used in an irrefutable context. } -''', - [error(diag.refutablePatternInIrrefutableContext, 18, 3)], - ); +'''); var node = findNode.singlePatternVariableDeclaration; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/relational_pattern_operand_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/relational_pattern_operand_type_not_assignable_test.dart index 578db25bbe1..5a8ca7c3830 100644 --- a/pkg/analyzer/test/src/diagnostics/relational_pattern_operand_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/relational_pattern_operand_type_not_assignable_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RelationalPatternArgumentTypeNotAssignableTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +18,7 @@ main() { class RelationalPatternArgumentTypeNotAssignableTest extends PubPackageResolutionTest { test_bangEq_matchedValueNullable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} void f(A? x) { @@ -30,7 +31,7 @@ void f(A? x) { } test_bangEq_operandNull() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} void f(A x) { @@ -43,7 +44,7 @@ void f(A x) { } test_bangEq_operandNullable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} const int? y = 0; @@ -58,7 +59,7 @@ void f(A x) { } test_eqEq() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} void f(A x) { @@ -71,8 +72,7 @@ void f(A x) { } test_eqEq_covariantParameterType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { bool operator ==(covariant A other) => true; } @@ -80,16 +80,16 @@ class A { void f(A x) { switch (x) { case == 0: +// ^ +// [diag.relationalPatternOperandTypeNotAssignable] The constant expression type 'int' is not assignable to the parameter type 'A' of the '==' operator. break; } } -''', - [error(diag.relationalPatternOperandTypeNotAssignable, 101, 1)], - ); +'''); } test_eqEq_externalType_right() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type const A(bool it) {} const True = A(true); @@ -103,7 +103,7 @@ void f(bool x) { } test_eqEq_matchedValueNullable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} void f(A? x) { @@ -116,23 +116,22 @@ void f(A? x) { } test_eqEq_operandNull() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A {} void f(A x) { switch (x) { case == null: break; +// ^^^^^^ +// [diag.deadCode] Dead code. } } -''', - [error(diag.deadCode, 65, 6)], - ); +'''); } test_eqEq_operandNullable() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} const int? y = 0; @@ -147,8 +146,7 @@ void f(A x) { } test_greaterThan() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { bool operator >(A other) => true; } @@ -156,11 +154,11 @@ class A { void f(A x) { switch (x) { case > 0: +// ^ +// [diag.relationalPatternOperandTypeNotAssignable] The constant expression type 'int' is not assignable to the parameter type 'A' of the '>' operator. break; } } -''', - [error(diag.relationalPatternOperandTypeNotAssignable, 89, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/relational_pattern_operator_return_type_not_assignable_to_bool_test.dart b/pkg/analyzer/test/src/diagnostics/relational_pattern_operator_return_type_not_assignable_to_bool_test.dart index 0cb0a14f2e7..dbca047621e 100644 --- a/pkg/analyzer/test/src/diagnostics/relational_pattern_operator_return_type_not_assignable_to_bool_test.dart +++ b/pkg/analyzer/test/src/diagnostics/relational_pattern_operator_return_type_not_assignable_to_bool_test.dart @@ -2,16 +2,17 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests( RelationalPatternOperatorReturnTypeNotAssignableToBoolTest, ); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,7 +20,7 @@ main() { class RelationalPatternOperatorReturnTypeNotAssignableToBoolTest extends PubPackageResolutionTest { test_dynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { dynamic operator >(_) => 42; } @@ -31,44 +32,30 @@ void f(A x) { } test_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int operator >(_) => 42; } void f(A x) { if (x case > 0) {} +// ^ +// [diag.relationalPatternOperatorReturnTypeNotAssignableToBool] The return type of operators used in relational patterns must be assignable to 'bool'. } -''', - [ - error( - diag.relationalPatternOperatorReturnTypeNotAssignableToBool, - 67, - 1, - ), - ], - ); +'''); } test_Object() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { Object operator >(_) => 42; } void f(A x) { if (x case > 0) {} +// ^ +// [diag.relationalPatternOperatorReturnTypeNotAssignableToBool] The return type of operators used in relational patterns must be assignable to 'bool'. } -''', - [ - error( - diag.relationalPatternOperatorReturnTypeNotAssignableToBool, - 70, - 1, - ), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/removed_lint_use_test.dart b/pkg/analyzer/test/src/diagnostics/removed_lint_use_test.dart index ccb32511247..5c7747ee602 100644 --- a/pkg/analyzer/test/src/diagnostics/removed_lint_use_test.dart +++ b/pkg/analyzer/test/src/diagnostics/removed_lint_use_test.dart @@ -2,15 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:analyzer/src/test_utilities/lint_registration_mixin.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RemovedLintUseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -31,23 +32,21 @@ linter: } test_file() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // ignore_for_file: super_goes_last +// ^^^^^^^^^^^^^^^ +// [diag.removedLintUse] 'super_goes_last' was removed in Dart '3.0.0' void f() { } -''', - [error(diag.removedLintUse, 20, 15)], - ); +'''); } test_line() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // ignore: super_goes_last +// ^^^^^^^^^^^^^^^ +// [diag.removedLintUse] 'super_goes_last' was removed in Dart '3.0.0' void f() { } -''', - [error(diag.removedLintUse, 11, 15)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/replaced_lint_use_test.dart b/pkg/analyzer/test/src/diagnostics/replaced_lint_use_test.dart index e89bcf8f690..7f0b915fcd8 100644 --- a/pkg/analyzer/test/src/diagnostics/replaced_lint_use_test.dart +++ b/pkg/analyzer/test/src/diagnostics/replaced_lint_use_test.dart @@ -4,17 +4,16 @@ import 'package:analyzer/analysis_rule/analysis_rule.dart'; import 'package:analyzer/analysis_rule/rule_state.dart'; -import 'package:analyzer/src/diagnostic/diagnostic.dart' - as diag - hide removedLint; import 'package:analyzer/src/test_utilities/lint_registration_mixin.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReplacedLintUseTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -51,44 +50,31 @@ linter: } test_file() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // ignore_for_file: removed_lint +// ^^^^^^^^^^^^ +// [diag.replacedLintUse] 'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'. void f() { } -''', - [error(diag.replacedLintUse, 20, 12)], - ); +'''); } test_line() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // ignore: removed_lint +// ^^^^^^^^^^^^ +// [diag.replacedLintUse] 'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'. void f() { } -''', - [error(diag.replacedLintUse, 11, 12)], - ); +'''); } test_messageText() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' // ignore_for_file: removed_lint +// ^^^^^^^^^^^^ +// [diag.replacedLintUse] 'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'. void f() { } -''', - [ - error( - diag.replacedLintUse, - 20, - 12, - messageContains: [ - "'removed_lint' was replaced by 'replacing_lint' in Dart '3.0.0'", - ], - correctionContains: "Replace 'removed_lint' with 'replacing_lint'.", - ), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/rethrow_outside_catch_test.dart b/pkg/analyzer/test/src/diagnostics/rethrow_outside_catch_test.dart index abc7d1c5910..d4b2a2a80a8 100644 --- a/pkg/analyzer/test/src/diagnostics/rethrow_outside_catch_test.dart +++ b/pkg/analyzer/test/src/diagnostics/rethrow_outside_catch_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(RethrowOutsideCatchTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class RethrowOutsideCatchTest extends PubPackageResolutionTest { test_insideCatch() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { try {} catch (e) { rethrow; @@ -26,22 +27,21 @@ void f() { } test_insideCatch_insideClosure() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { try {} catch (e) { () { rethrow; +// ^^^^^^^ +// [diag.rethrowOutsideCatch] A rethrow must be inside of a catch clause. }; } } -''', - [error(diag.rethrowOutsideCatch, 47, 7)], - ); +'''); } test_insideCatch_insideClosure_insideCatch() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { try {} catch (e1) { () { @@ -55,14 +55,13 @@ void f() { } test_withoutCatch() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { rethrow; +//^^^^^^^ +// [diag.rethrowOutsideCatch] A rethrow must be inside of a catch clause. } -''', - [error(diag.rethrowOutsideCatch, 13, 7)], - ); +'''); var node = findNode.singleRethrowExpression; assertResolvedNodeText(node, r''' diff --git a/pkg/analyzer/test/src/diagnostics/return_in_generative_constructor_test.dart b/pkg/analyzer/test/src/diagnostics/return_in_generative_constructor_test.dart index 2f59470ad21..060aeebc929 100644 --- a/pkg/analyzer/test/src/diagnostics/return_in_generative_constructor_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_in_generative_constructor_test.dart @@ -2,43 +2,42 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnInGenerativeConstructorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnInGenerativeConstructorTest extends PubPackageResolutionTest { test_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() { return 0; } +// ^ +// [diag.returnInGenerativeConstructor] Constructors can't return values. } -''', - [error(diag.returnInGenerativeConstructor, 25, 1)], - ); +'''); } test_expressionFunctionBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() => A(); +// ^^^^^^^ +// [diag.returnInGenerativeConstructor] Constructors can't return values. } -''', - [error(diag.returnInGenerativeConstructor, 16, 7)], - ); +'''); } test_return_without_value() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { A() { return; } } diff --git a/pkg/analyzer/test/src/diagnostics/return_in_generator_test.dart b/pkg/analyzer/test/src/diagnostics/return_in_generator_test.dart index 82b6502d359..6a384e6069b 100644 --- a/pkg/analyzer/test/src/diagnostics/return_in_generator_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_in_generator_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnInGeneratorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnInGeneratorTest extends PubPackageResolutionTest { test_async() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() async { return 0; } @@ -24,18 +25,17 @@ f() async { } test_asyncStar_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() async* { return 0; +//^^^^^^ +// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier. } -''', - [error(diag.returnInGenerator, 15, 6)], - ); +'''); } test_asyncStar_blockBody_noValue() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' Stream f() async* { return; } @@ -43,16 +43,15 @@ Stream f() async* { } test_asyncStar_expressionBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() async* => 0; -''', - [error(diag.returnInGenerator, 11, 2)], - ); +// ^^ +// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier. +'''); } test_sync() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() { return 0; } @@ -60,18 +59,17 @@ f() { } test_syncStar_blockBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() sync* { return 0; +//^^^^^^ +// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier. } -''', - [error(diag.returnInGenerator, 14, 6)], - ); +'''); } test_syncStar_blockBody_noValue() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' Iterable f() sync* { return; } @@ -79,11 +77,10 @@ Iterable f() sync* { } test_syncStar_expressionBody() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' f() sync* => 0; -''', - [error(diag.returnInGenerator, 10, 2)], - ); +// ^^ +// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart b/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart index 8bf4917c8d5..4d0488faa78 100644 --- a/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_of_do_not_store_test.dart @@ -2,15 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnOfDoNotStoreInTestsTest); defineReflectiveTests(ReturnOfDoNotStoreTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -26,7 +27,7 @@ class ReturnOfDoNotStoreInTestsTest extends PubPackageResolutionTest { // Code that is in a test dir (the default for PubPackageResolutionTests) // should not trigger the hint. // (See:https://github.com/dart-lang/sdk/issues/45594) - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -57,8 +58,8 @@ class ReturnOfDoNotStoreTest extends PubPackageResolutionTest { } test_constructor() async { - await assertErrorsInCode( - ''' + // TODO(srawlins): We should report `returnOfDoNotStore`. + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -67,19 +68,15 @@ class A { String getA() { return A(); +// ^^^ +// [diag.returnOfInvalidTypeFromMethod] A value of type 'A' can't be returned from the method 'getA' because it has a return type of 'String'. } } -''', - [ - error(diag.returnOfInvalidTypeFromMethod, 95, 3), - // TODO(srawlins): We should report `returnOfDoNotStore`. - ], - ); +'''); } test_returnFromClosureInFunction() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -87,16 +84,15 @@ String get _v => ''; String f() { var v = () => _v; +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'f' is also annotated. return v(); } -''', - [error(diag.returnOfDoNotStore, 97, 2)], - ); +'''); } test_returnFromFunction() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -104,23 +100,21 @@ String get v => ''; String getV() { return v; +// ^ +// [diag.returnOfDoNotStore] 'v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV' is also annotated. } String getV2() => v; +// ^ +// [diag.returnOfDoNotStore] 'v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV2' is also annotated. @doNotStore String getV3() => v; -''', - [ - error(diag.returnOfDoNotStore, 92, 1, messageContains: ['getV']), - error(diag.returnOfDoNotStore, 116, 1, messageContains: ['getV2']), - ], - ); +'''); } test_returnFromGetter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -128,23 +122,21 @@ String get _v => ''; String get v { return _v; +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated. } String get v2 => _v; +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v2' is also annotated. @doNotStore String get v3 => _v; -''', - [ - error(diag.returnOfDoNotStore, 92, 2, messageContains: ['v']), - error(diag.returnOfDoNotStore, 116, 2, messageContains: ['v2']), - ], - ); +'''); } test_returnFromGetter_binaryExpression() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -154,16 +146,15 @@ String? get _v => ''; String? get _v2 => ''; String? get v => _v ?? _v2; -''', - [ - error(diag.returnOfDoNotStore, 122, 2, messageContains: ['_v']), - error(diag.returnOfDoNotStore, 128, 3, messageContains: ['_v2']), - ], - ); +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated. +// ^^^ +// [diag.returnOfDoNotStore] '_v2' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated. +'''); } test_returnFromGetter_library() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' @doNotStore import 'package:meta/meta.dart'; int get foo => 0; @@ -172,8 +163,7 @@ int get bar => foo; } test_returnFromGetter_ternary() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @doNotStore @@ -185,17 +175,15 @@ String get _v2 => ''; var b = true; String get v => b ? _v : _v2; -''', - [ - error(diag.returnOfDoNotStore, 138, 2), - error(diag.returnOfDoNotStore, 143, 3), - ], - ); +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated. +// ^^^ +// [diag.returnOfDoNotStore] '_v2' is annotated with 'doNotStore' and shouldn't be returned unless 'v' is also annotated. +'''); } test_returnFromMethod() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class A { @@ -204,23 +192,22 @@ class A { String getV() { return _v; +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV' is also annotated. } String getV2() => _v; +// ^^ +// [diag.returnOfDoNotStore] '_v' is annotated with 'doNotStore' and shouldn't be returned unless 'getV2' is also annotated. @doNotStore String getV3() => _v; } -''', - [ - error(diag.returnOfDoNotStore, 111, 2, messageContains: ['getV']), - error(diag.returnOfDoNotStore, 140, 2, messageContains: ['getV2']), - ], - ); +'''); } test_topLevelVariable_awaitExpression() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; void get f async => await v; 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 aa49c1817e6..07637d0dcdb 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 @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnOfInvalidTypeForCatchErrorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnOfInvalidTypeForCatchErrorTest extends PubPackageResolutionTest { test_async_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) async => 0); } @@ -24,20 +25,19 @@ void f(Future future) { } test_blockFunctionBody_async_emptyReturn_nonVoid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) async { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. }); } -''', - [error(diag.returnWithoutValue, 69, 6)], - ); +'''); } test_blockFunctionBody_async_emptyReturn_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) async { return; @@ -47,7 +47,7 @@ void f(Future future) { } test_blockFunctionBody_emptyReturn_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { return; @@ -57,20 +57,19 @@ void f(Future future) { } test_blockFunctionBody_emptyReturn_nonVoid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. }); } -''', - [error(diag.returnWithoutValue, 63, 6)], - ); +'''); } test_blockFunctionBody_emptyReturn_Null() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { return; @@ -80,7 +79,7 @@ void f(Future future) { } test_blockFunctionBody_emptyReturn_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { return; @@ -90,24 +89,23 @@ void f(Future future) { } test_blockFunctionBody_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { if (1 == 2) { return 7; } else { return 0.5; +// ^^^ +// [diag.returnOfInvalidTypeFromCatchError] A value of type 'double' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr'. } }); } -''', - [error(diag.returnOfInvalidTypeFromCatchError, 119, 3)], - ); +'''); } test_blockFunctionBody_withLocalFunction_expression_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { double g() => 0.5; @@ -119,7 +117,7 @@ void f(Future future) { } test_blockFunctionBody_withLocalFunction_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { double g() { @@ -133,18 +131,17 @@ void f(Future future) { } test_expressionFunctionBody_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) => 'c'); +// ^^^ +// [diag.returnOfInvalidTypeFromCatchError] A value of type 'String' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr'. } -''', - [error(diag.returnOfInvalidTypeFromCatchError, 60, 3)], - ); +'''); } test_Null_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) => null); } @@ -152,7 +149,7 @@ void f(Future future) { } test_Null_voidReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function() g) { future.catchError((e, st) => g()); } @@ -160,31 +157,29 @@ void f(Future future, void Function() g) { } test_nullableType_emptyReturn() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. }); } -''', - [error(diag.returnWithoutValue, 64, 6)], - ); +'''); } test_nullableType_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) => ''); +// ^^ +// [diag.returnOfInvalidTypeFromCatchError] A value of type 'String' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr'. } -''', - [error(diag.returnOfInvalidTypeFromCatchError, 61, 2)], - ); +'''); } test_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) => 0); } @@ -192,7 +187,7 @@ void f(Future future) { } test_void_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e, st) => 0); } @@ -200,13 +195,12 @@ void f(Future future) { } test_voidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function() g) { future.catchError((e, st) => g()); +// ^^^ +// [diag.returnOfInvalidTypeFromCatchError] A value of type 'void' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr'. } -''', - [error(diag.returnOfInvalidTypeFromCatchError, 79, 3)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_then_test.dart b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_then_test.dart index 317f6ede553..1acca0603e5 100644 --- a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_then_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_then_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnOfInvalidTypeForThenTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnOfInvalidTypeForThenTest extends PubPackageResolutionTest { test_blockFunctionBody_async_emptyReturn_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) async { return; @@ -26,33 +27,31 @@ void f(Future future) { } test_blockFunctionBody_async_emptyReturn_nonVoid() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) async { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. }); } -''', - [error(diag.returnWithoutValue, 87, 6)], - ); +'''); } test_blockFunctionBody_async_emptyReturn_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) async { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. }); } -''', - [error(diag.returnWithoutValue, 88, 6)], - ); +'''); } test_blockFunctionBody_async_emptyReturn_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) async { return; @@ -62,24 +61,23 @@ void f(Future future) { } test_blockFunctionBody_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) { if (1 == 2) { return 7; } else { return 0.5; +// ^^^ +// [diag.returnOfInvalidTypeFromThen] A value of type 'double' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr', as required by 'Future.then'. } }); } -''', - [error(diag.returnOfInvalidTypeFromThen, 132, 3)], - ); +'''); } test_blockFunctionBody_void_objectQuestionReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) {}, onError: (e, st) { return Future.error(0.5); @@ -89,18 +87,17 @@ void f(Future future) { } test_expressionFunctionBody_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) => 'c'); +// ^^^ +// [diag.returnOfInvalidTypeFromThen] A value of type 'String' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr', as required by 'Future.then'. } -''', - [error(diag.returnOfInvalidTypeFromThen, 73, 3)], - ); +'''); } test_expressionFunctionBody_Null_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => null, onError: (e, st) => null); } @@ -108,7 +105,7 @@ void f(Future future) { } test_expressionFunctionBody_Null_voidReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function(dynamic, StackTrace) callback) { future.then((_) => null, onError: callback); } @@ -116,7 +113,7 @@ void f(Future future, void Function(dynamic, StackTrace) callback) { } test_expressionFunctionBody_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) => 0); } @@ -124,7 +121,7 @@ void f(Future future) { } test_expressionFunctionBody_void_okReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.then((_) => 0, onError: (e, st) => 0); } @@ -132,7 +129,7 @@ void f(Future future) { } test_referencedFunction_FutureOfNull_voidReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function(dynamic, StackTrace) callback) { future.then((_) => null, onError: callback); } @@ -140,7 +137,7 @@ void f(Future future, void Function(dynamic, StackTrace) callback) { } test_referencedFunction_FutureOfNull_voidReturnType2() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function() callback) { future.then((_) => null, onError: (_, _) => callback()); } @@ -148,18 +145,17 @@ void f(Future future, void Function() callback) { } test_referencedFunction_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, double Function(dynamic, StackTrace) callback) { future.then((_) => 0, onError: callback); +// ^^^^^^^^ +// [diag.returnTypeInvalidForThen] The return type 'double' isn't assignable to 'FutureOr', as required by 'Future.then'. } -''', - [error(diag.returnTypeInvalidForThen, 109, 8)], - ); +'''); } test_referencedFunction_void_voidReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(dynamic, StackTrace) callback) { future.then((_) {}, onError: callback); } 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 f29167f9ea7..d185575f639 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 @@ -6,52 +6,51 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnOfInvalidTypeTest); defineReflectiveTests(ReturnOfInvalidTypeWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnOfInvalidTypeTest extends PubPackageResolutionTest { test_closure() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef Td = int Function(); Td f() { return () => "hello"; +// ^^^^^^^ +// [diag.returnOfInvalidTypeFromClosure] The returned type 'String' isn't returnable from a 'int' function, as required by the closure's context. } -''', - [error(diag.returnOfInvalidTypeFromClosure, 53, 7)], - ); +'''); } test_factoryConstructor_named() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { factory C.named() => 7; +// ^ +// [diag.returnOfInvalidTypeFromConstructor] A value of type 'int' can't be returned from the constructor 'C.named' because it has a return type of 'C'. } -''', - [error(diag.returnOfInvalidTypeFromConstructor, 33, 1)], - ); +'''); } test_factoryConstructor_unnamed() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { factory C() => 7; +// ^ +// [diag.returnOfInvalidTypeFromConstructor] A value of type 'int' can't be returned from the constructor 'C' because it has a return type of 'C'. } -''', - [error(diag.returnOfInvalidTypeFromConstructor, 27, 1)], - ); +'''); } test_function_async_block__to_Future_void() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Future f1() async {} Future f2() async { return; } Future f3() async { return null; } @@ -63,47 +62,43 @@ void g2() {} } test_function_async_block_Future_Future_int__to_Future_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Future f(Future> a) async { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'Future>' can't be returned from the function 'f' because it has a return type of 'Future'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 54, 1)], - ); +'''); } test_function_async_block_Future_String__to_Future_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Future f(Future a) async { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'Future' can't be returned from the function 'f' because it has a return type of 'Future'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 49, 1)], - ); +'''); } test_function_async_block_Future_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f1(Future a) async { return a; } dynamic f2(Future a) async { return a; } '''); } test_function_async_block_illegalReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int f() async { +// [diag.illegalAsyncReturnType][column 1][length 3] Functions marked 'async' must have a return type which is a supertype of 'Future'. return 5; } -''', - [error(diag.illegalAsyncReturnType, 0, 3)], - ); +'''); } test_function_async_block_int__to_Future_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Future f() async { return 0; } @@ -111,7 +106,7 @@ Future f() async { } test_function_async_block_int__to_Future_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Future f() async { return 0; } @@ -119,40 +114,37 @@ Future f() async { } test_function_async_block_int__to_Future_String() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Future f() async { return 5; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'Future'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 36, 1)], - ); +'''); } test_function_async_block_int__to_Future_void() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' Future f() async { return 0; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'Future'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 34, 1)], - ); +'''); } test_function_async_block_int__to_void() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() async { return 5; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'void'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 26, 1)], - ); +'''); } test_function_async_block_void__to_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' dynamic f(void a) async { return a; } @@ -160,42 +152,39 @@ dynamic f(void a) async { } test_function_async_block_void__to_Future_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Future f(void a) async { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'Future'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 39, 1)], - ); +'''); } test_function_async_block_void__to_Future_Null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' Future f(void a) async { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'Future'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 40, 1)], - ); +'''); } test_function_async_block_void__to_FutureOr_ObjectQ() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; FutureOr f(void a) async { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'FutureOr'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 67, 1)], - ); +'''); } test_function_async_block_void__to_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void a) async { return a; } @@ -203,36 +192,32 @@ void f(void a) async { } test_function_async_expression_dynamic__to_Future_int() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Future f(dynamic a) async => a; '''); } test_function_asyncStar() async { - await assertErrorsInCode( - ''' + // RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error. + await resolveTestCodeWithDiagnostics(r''' Stream f() async* => 3; -''', - [ - // RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error. - error(diag.returnInGenerator, 23, 2), - ], - ); +// ^^ +// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier. +'''); } test_function_sync_block__invalidType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { return new X(); +// ^ +// [diag.newWithNonType] The name 'X' isn't a class. } -''', - [error(diag.newWithNonType, 24, 1)], - ); +'''); } test_function_sync_block__to_dynamic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' f() { try { return 0; @@ -244,7 +229,7 @@ f() { } test_function_sync_block__to_void() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f1() {} void f2() { return; } void f3() { return null; } @@ -256,7 +241,7 @@ void g2() {} } test_function_sync_block_genericFunction__to_genericFunction() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' U Function(U) foo(T Function(T a) f) { return f; } @@ -264,18 +249,17 @@ U Function(U) foo(T Function(T a) f) { } test_function_sync_block_genericFunction__to_genericFunction_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' U Function(U, int) foo(T Function(T a) f) { return f; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'T Function(T)' can't be returned from the function 'foo' because it has a return type of 'U Function(U, int)'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 59, 1)], - ); +'''); } test_function_sync_block_genericFunction__to_nonGenericFunction() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' int Function(int) foo(T Function(T a) f) { return f; } @@ -283,18 +267,17 @@ int Function(int) foo(T Function(T a) f) { } test_function_sync_block_genericFunction__to_nonGenericFunction_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int Function(int, int) foo(T Function(T a) f) { return f; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'dynamic Function(dynamic)' can't be returned from the function 'foo' because it has a return type of 'int Function(int, int)'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 60, 1)], - ); +'''); } test_function_sync_block_int__to_num() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' num f(int a) { return a; } @@ -302,36 +285,33 @@ num f(int a) { } test_function_sync_block_int__to_void() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f() { return 42; +// ^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'int' can't be returned from the function 'f' because it has a return type of 'void'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 20, 2)], - ); +'''); } test_function_sync_block_num__to_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' int f(num a) { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'num' can't be returned from the function 'f' because it has a return type of 'int'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 24, 1)], - ); +'''); } test_function_sync_block_String__to_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int f() { return '0'; +// ^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of 'int'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 19, 3)], - ); +'''); } test_function_sync_block_typeParameter__to_Type() async { @@ -345,7 +325,7 @@ int f() { // returned out of the TestTypeProvider don't have a mock 'dart.core' // enclosing library element. // See TypeParameterTypeImpl.isMoreSpecificThan(). - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class Foo { Type get t => T; } @@ -353,7 +333,7 @@ class Foo { } test_function_sync_block_void__to_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' dynamic f(void a) { return a; } @@ -361,29 +341,27 @@ dynamic f(void a) { } test_function_sync_block_void__to_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int f(void a) { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'int'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 25, 1)], - ); +'''); } test_function_sync_block_void__to_Null() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Null f(void a) { return a; +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'void' can't be returned from the function 'f' because it has a return type of 'Null'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 26, 1)], - ); +'''); } test_function_sync_block_void__to_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(void a) { return a; } @@ -391,64 +369,58 @@ void f(void a) { } test_function_sync_expression_genericFunction__to_genericFunction() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' U Function(U) foo(T Function(T a) f) => f; '''); } test_function_sync_expression_genericFunction__to_genericFunction_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' U Function(U, int) foo(T Function(T a) f) => f; -''', - [error(diag.returnOfInvalidTypeFromFunction, 51, 1)], - ); +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'T Function(T)' can't be returned from the function 'foo' because it has a return type of 'U Function(U, int)'. +'''); } test_function_sync_expression_genericFunction__to_nonGenericFunction() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' int Function(int) foo(T Function(T a) f) => f; '''); } test_function_sync_expression_genericFunction__to_nonGenericFunction_notAssignable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int Function(int, int) foo(T Function(T a) f) => f; -''', - [error(diag.returnOfInvalidTypeFromFunction, 52, 1)], - ); +// ^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'dynamic Function(dynamic)' can't be returned from the function 'foo' because it has a return type of 'int Function(int, int)'. +'''); } test_function_sync_expression_int__to_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f() => 42; '''); } test_function_sync_expression_String__to_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int f() => '0'; -''', - [error(diag.returnOfInvalidTypeFromFunction, 11, 3)], - ); +// ^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of 'int'. +'''); } test_function_syncStar() async { - await assertErrorsInCode( - ''' + // RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error. + await resolveTestCodeWithDiagnostics(r''' Iterable f() sync* => 3; -''', - [ - // RETURN_OF_INVALID_TYPE shouldn't be reported in addition to this error. - error(diag.returnInGenerator, 24, 2), - ], - ); +// ^^ +// [diag.returnInGenerator] Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier. +'''); } test_functionExpression_async_futureOr_void__to_Object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void a = null; Object Function() f = () async { @@ -458,7 +430,7 @@ Object Function() f = () async { } test_functionExpression_async_futureQ_void__to_Object() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' Future? a = (throw 0); Object Function() f = () async { @@ -468,7 +440,7 @@ Object Function() f = () async { } test_functionExpression_async_void__to_FutureOr_ObjectQ() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void a = (throw 0); @@ -480,55 +452,51 @@ FutureOr Function() f = () async { } test_getter_sync_block_String__to_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int get g { return '0'; +// ^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'g' because it has a return type of 'int'. } -''', - [error(diag.returnOfInvalidTypeFromFunction, 21, 3)], - ); +'''); } test_getter_sync_expression_String__to_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int get g => '0'; -''', - [error(diag.returnOfInvalidTypeFromFunction, 13, 3)], - ); +// ^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'g' because it has a return type of 'int'. +'''); } test_localFunction_sync_block_String__to_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { int g() { return '0'; +// ^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'g' because it has a return type of 'int'. } g(); } -''', - [error(diag.returnOfInvalidTypeFromFunction, 34, 3)], - ); +'''); } test_localFunction_sync_expression_String__to_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { void m() { int f() => '0'; +// ^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'String' can't be returned from the function 'f' because it has a return type of 'int'. f(); } } -''', - [error(diag.returnOfInvalidTypeFromFunction, 38, 3)], - ); +'''); } test_method_async_block_callable_class() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef Fn = void Function(String s); class CanFn { @@ -542,20 +510,19 @@ Future f() async { } test_method_sync_block_String__to_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int m() { return '0'; +// ^^^ +// [diag.returnOfInvalidTypeFromMethod] A value of type 'String' can't be returned from the method 'm' because it has a return type of 'int'. } } -''', - [error(diag.returnOfInvalidTypeFromMethod, 33, 3)], - ); +'''); } test_method_sync_expression_generic() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' abstract class F { T get value; } @@ -567,23 +534,21 @@ abstract class G { } test_method_sync_expression_String__to_int() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { int f() => '0'; +// ^^^ +// [diag.returnOfInvalidTypeFromMethod] A value of type 'String' can't be returned from the method 'f' because it has a return type of 'int'. } -''', - [error(diag.returnOfInvalidTypeFromMethod, 23, 3)], - ); +'''); } test_spread_iterable_in_map_context() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Map f() => {...[1, 2, 3, 4]}; -''', - [error(diag.returnOfInvalidTypeFromFunction, 21, 17)], - ); +// ^^^^^^^^^^^^^^^^^ +// [diag.returnOfInvalidTypeFromFunction] A value of type 'Set' can't be returned from the function 'f' because it has a return type of 'Map'. +'''); } } 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 93297aa59b3..f122e2f8ca8 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 @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnTypeInvalidForCatchErrorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnTypeInvalidForCatchErrorTest extends PubPackageResolutionTest { test_dynamic_returnTypeIsUnrelatedFuture() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f( Future future, Future Function(dynamic, StackTrace) cb) { future.catchError(cb); @@ -25,7 +26,7 @@ void f( } test_dynamic_unrelatedReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String Function(dynamic, StackTrace) cb) { future.catchError(cb); } @@ -33,18 +34,17 @@ void f(Future future, String Function(dynamic, StackTrace) cb) { } test_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String Function(dynamic, StackTrace) cb) { future.catchError(cb); +// ^^ +// [diag.returnTypeInvalidForCatchError] The return type 'String' isn't assignable to 'FutureOr', as required by 'Future.catchError'. } -''', - [error(diag.returnTypeInvalidForCatchError, 90, 2)], - ); +'''); } test_Null_returnTypeIsVoid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function(dynamic, StackTrace) cb) { future.catchError(cb); } @@ -52,18 +52,17 @@ void f(Future future, void Function(dynamic, StackTrace) cb) { } test_nullableReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String? Function(dynamic, StackTrace) cb) { future.catchError(cb); +// ^^ +// [diag.returnTypeInvalidForCatchError] The return type 'String?' isn't assignable to 'FutureOr', as required by 'Future.catchError'. } -''', - [error(diag.returnTypeInvalidForCatchError, 91, 2)], - ); +'''); } test_returnTypeIsFuture() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(dynamic, StackTrace) cb) { future.catchError(cb); } @@ -71,7 +70,7 @@ void f(Future future, Future Function(dynamic, StackTrace) cb) { } test_returnTypeIsFutureOr() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(Future future, FutureOr Function(dynamic, StackTrace) cb) { future.catchError(cb); @@ -80,7 +79,7 @@ void f(Future future, FutureOr Function(dynamic, StackTrace) cb) { } test_sameReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, int Function(dynamic, StackTrace) cb) { future.catchError(cb); } @@ -88,7 +87,7 @@ void f(Future future, int Function(dynamic, StackTrace) cb) { } test_void_returnTypeIsUnrelatedFuture() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(dynamic, StackTrace) cb) { future.catchError(cb); } @@ -96,7 +95,7 @@ void f(Future future, Future Function(dynamic, StackTrace) cb) { } test_void_unrelatedReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String Function(dynamic, StackTrace) cb) { future.catchError(cb); } diff --git a/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_then_test.dart b/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_then_test.dart index 0b60d5c00f9..e3a3d6fab90 100644 --- a/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_then_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_then_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnTypeInvalidForThenTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnTypeInvalidForThenTest extends PubPackageResolutionTest { test_dynamic_returnTypeIsUnrelatedFuture() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f( Future future, Future Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); @@ -25,7 +26,7 @@ void f( } test_dynamic_unrelatedReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); } @@ -33,29 +34,27 @@ void f(Future future, String Function(dynamic, StackTrace) cb) { } test_invalidReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); +// ^^ +// [diag.returnTypeInvalidForThen] The return type 'String' isn't assignable to 'FutureOr', as required by 'Future.then'. } -''', - [error(diag.returnTypeInvalidForThen, 108, 2)], - ); +'''); } test_nullableReturnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, int? Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); +// ^^ +// [diag.returnTypeInvalidForThen] The return type 'int?' isn't assignable to 'FutureOr', as required by 'Future.then'. } -''', - [error(diag.returnTypeInvalidForThen, 101, 2)], - ); +'''); } test_returnTypeIsFuture() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); } @@ -63,7 +62,7 @@ void f(Future future, Future Function(dynamic, StackTrace) cb) { } test_returnTypeIsFutureOr() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:async'; void f(Future future, FutureOr Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); @@ -72,18 +71,17 @@ void f(Future future, FutureOr Function(dynamic, StackTrace) cb) { } test_returnTypeIsVoid_int() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); +// ^^ +// [diag.returnTypeInvalidForThen] The return type 'void' isn't assignable to 'FutureOr', as required by 'Future.then'. } -''', - [error(diag.returnTypeInvalidForThen, 106, 2)], - ); +'''); } test_returnTypeIsVoid_nullableInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, void Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); } @@ -91,7 +89,7 @@ void f(Future future, void Function(dynamic, StackTrace) cb) { } test_sameReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, int Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); } @@ -99,7 +97,7 @@ void f(Future future, int Function(dynamic, StackTrace) cb) { } test_void_returnTypeIsUnrelatedFuture() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, Future Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); } @@ -107,7 +105,7 @@ void f(Future future, Future Function(dynamic, StackTrace) cb) { } test_void_unrelatedReturnType() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future, String Function(dynamic, StackTrace) cb) { future.then((_) => 1, onError: cb); } 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 03b8024e550..5899ca5b9f5 100644 --- a/pkg/analyzer/test/src/diagnostics/return_without_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_without_value_test.dart @@ -2,43 +2,42 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ReturnWithoutValueTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ReturnWithoutValueTest extends PubPackageResolutionTest { test_async_futureInt() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Future f() async { return; +//^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } -''', - [error(diag.returnWithoutValue, 26, 6)], - ); +'''); } test_async_futureObject() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' Future f() async { return; +//^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } -''', - [error(diag.returnWithoutValue, 29, 6)], - ); +'''); } test_catchError_futureOfVoid() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f(Future future) { future.catchError((e) { return; @@ -48,31 +47,29 @@ void f(Future future) { } test_factoryConstructor() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } } -''', - [error(diag.returnWithoutValue, 30, 6)], - ); +'''); } test_function() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int f() { return; +//^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } -''', - [error(diag.returnWithoutValue, 12, 6)], - ); +'''); } test_function_async_block_empty__to_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' dynamic f() async { return; } @@ -82,7 +79,7 @@ dynamic f() async { test_function_Null() async { // Test that block bodied functions with return type Null and an empty // return cause a static warning. - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' Null f() { return; } @@ -90,7 +87,7 @@ Null f() { } test_function_sync_block_empty__to_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' dynamic f() { return; } @@ -98,7 +95,7 @@ dynamic f() { } test_function_sync_block_empty__to_Null() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' Null f() { return; } @@ -106,7 +103,7 @@ Null f() { } test_function_void() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' void f() { return; } @@ -114,23 +111,22 @@ void f() { } test_functionExpression() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f() { return (int y) { if (y < 0) { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } return 0; }; } -''', - [error(diag.returnWithoutValue, 48, 6)], - ); +'''); } test_functionExpression_async_block_empty__to_Object() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' Object Function() f = () async { return; }; @@ -138,31 +134,29 @@ Object Function() f = () async { } test_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { int m() { return; +// ^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } } -''', - [error(diag.returnWithoutValue, 26, 6)], - ); +'''); } test_multipleInconsistentReturns() async { // Tests that only the RETURN_WITHOUT_VALUE warning is created, and no // MIXED_RETURN_TYPES are created. - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' int f(int x) { if (x < 0) { return 1; } return; +//^^^^^^ +// [diag.returnWithoutValue] The return value is missing after 'return'. } -''', - [error(diag.returnWithoutValue, 50, 6)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_gt_gt_gt_operator_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_gt_gt_gt_operator_test.dart index 83d2a9fc469..a6421c39fca 100644 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_gt_gt_gt_operator_test.dart +++ b/pkg/analyzer/test/src/diagnostics/sdk_version_gt_gt_gt_operator_test.dart @@ -3,14 +3,16 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/src/dart/analysis/experiments.dart'; -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; +import 'package:analyzer_testing/utilities/utilities.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; +import '../dart/resolution/node_text_expectations.dart'; import 'sdk_constraint_verifier_support.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SdkVersionGtGtGtOperatorTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,23 +24,24 @@ class SdkVersionGtGtGtOperatorTest extends SdkConstraintVerifierTest { '${ExperimentStatus.currentVersion.minor}'; test_const_equals() async { - await verifyVersion('>=2.15.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0')); + await resolveTestCodeWithDiagnostics(r''' const a = 42 >>> 3; '''); } test_const_lessThan() async { - await verifyVersion( - '>=2.13.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.13.0')); + await resolveTestCodeWithDiagnostics(r''' const a = 42 >>> 3; -''', - expectedDiagnostics: [error(diag.sdkVersionGtGtGtOperator, 13, 3)], - ); +// ^^^ +// [diag.sdkVersionGtGtGtOperator] The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions. +'''); } test_declaration_equals() async { - await verifyVersion('>=2.15.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0')); + await resolveTestCodeWithDiagnostics(r''' class A { A operator >>>(A a) => this; } @@ -46,30 +49,29 @@ class A { } test_declaration_lessThan() async { - await verifyVersion( - '>=2.13.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.13.0')); + await resolveTestCodeWithDiagnostics(r''' class A { A operator >>>(A a) => this; +// ^^^ +// [diag.sdkVersionGtGtGtOperator] The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions. } -''', - expectedDiagnostics: [error(diag.sdkVersionGtGtGtOperator, 23, 3)], - ); +'''); } test_nonConst_equals() async { - await verifyVersion('>=2.15.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0')); + await resolveTestCodeWithDiagnostics(r''' var a = 42 >>> 3; '''); } test_nonConst_lessThan() async { - await verifyVersion( - '>=2.13.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.13.0')); + await resolveTestCodeWithDiagnostics(r''' var a = 42 >>> 3; -''', - expectedDiagnostics: [error(diag.sdkVersionGtGtGtOperator, 11, 3)], - ); +// ^^^ +// [diag.sdkVersionGtGtGtOperator] The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart index 42f99495090..57df9a30ce5 100644 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart +++ b/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart @@ -2,15 +2,17 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:analyzer/src/test_utilities/mock_sdk.dart'; +import 'package:analyzer_testing/utilities/utilities.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; +import '../dart/resolution/node_text_expectations.dart'; import 'sdk_constraint_verifier_support.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SdkVersionSinceTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -26,17 +28,16 @@ import 'dart:_internal'; class A({@Since('2.15') int? foo}); '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(foo: 0); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_class_constructor_formalParameter_default() async { @@ -48,17 +49,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(foo: 0); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_class_constructor_formalParameter_optionalNamed() async { @@ -70,17 +70,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(foo: 0); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_class_constructor_formalParameter_optionalPositional() async { @@ -92,17 +91,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(42); +// ^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 2)], - ); +'''); } test_class_constructor_named_instanceCreation() async { @@ -115,17 +113,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A.named(); +// ^^^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 40, 5)], - ); +'''); } test_class_constructor_named_tearOff() async { @@ -138,17 +135,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A.named; +// ^^^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 40, 5)], - ); +'''); } test_class_constructor_primary_instanceCreation() async { @@ -161,17 +157,16 @@ class A() { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(); +//^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 33, 1)], - ); +'''); } test_class_constructor_unnamed_instanceCreation() async { @@ -184,17 +179,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(); +//^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 33, 1)], - ); +'''); } test_class_field_originPrimaryConstructor() async { @@ -204,17 +198,16 @@ import 'dart:_internal'; class A({@Since('2.15') final int foo = 0}); '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a.foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); } test_class_field_read() async { @@ -227,21 +220,19 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { (a).foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. a.foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [ - error(diag.sdkVersionSince, 40, 3), - error(diag.sdkVersionSince, 49, 3), - ], - ); +'''); } test_class_field_readWrite() async { @@ -254,21 +245,19 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { (a).foo += 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. a.foo += 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [ - error(diag.sdkVersionSince, 40, 3), - error(diag.sdkVersionSince, 54, 3), - ], - ); +'''); } test_class_field_write() async { @@ -281,21 +270,19 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { (a).foo = 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. a.foo = 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [ - error(diag.sdkVersionSince, 40, 3), - error(diag.sdkVersionSince, 53, 3), - ], - ); +'''); } test_class_getter() async { @@ -308,21 +295,19 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { (a).foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. a.foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [ - error(diag.sdkVersionSince, 40, 3), - error(diag.sdkVersionSince, 49, 3), - ], - ); +'''); } test_class_getterSetter_readWrite_both() async { @@ -337,17 +322,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a.foo += 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); } test_class_getterSetter_readWrite_getter() async { @@ -361,17 +345,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a.foo += 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); } test_class_getterSetter_readWrite_setter() async { @@ -385,17 +368,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a.foo += 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); } test_class_indexRead() async { @@ -408,17 +390,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a[0]; +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 37, 1)], - ); +'''); } test_class_indexWrite() async { @@ -431,17 +412,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a[0] = 0; +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 37, 1)], - ); +'''); } test_class_instanceCreation_prefixed() async { @@ -452,17 +432,16 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo' as foo; void f() { foo.A(); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 44, 1)], - ); +'''); } test_class_instanceCreation_unprefixed() async { @@ -473,17 +452,16 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { A(); +//^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 33, 1)], - ); +'''); } test_class_method_call_functionExpressionInvocation() async { @@ -496,17 +474,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a(); +// ^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 37, 2)], - ); +'''); } test_class_method_formalParameter_optionalNamed() async { @@ -520,17 +497,16 @@ void foo( }) {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { foo(0, bar: 1); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 40, 3)], - ); +'''); } test_class_method_formalParameter_optionalPositional() async { @@ -544,17 +520,16 @@ void foo( ]) {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { foo(0, 42); +// ^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 40, 2)], - ); +'''); } test_class_method_methodInvocation() async { @@ -567,17 +542,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a.foo(); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); } test_class_method_methodTearOff_prefixedIdentifier() async { @@ -590,17 +564,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { a.foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); var node = findNode.prefixed('.foo'); assertResolvedNodeText(node, r''' @@ -629,17 +602,16 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { (a).foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 40, 3)], - ); +'''); var node = findNode.propertyAccess('.foo'); assertResolvedNodeText(node, r''' @@ -671,21 +643,19 @@ class A { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) { (a).foo = 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. a.foo = 0; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [ - error(diag.sdkVersionSince, 40, 3), - error(diag.sdkVersionSince, 53, 3), - ], - ); +'''); } test_class_typeAnnotation_prefixed() async { @@ -696,15 +666,14 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo' as foo; void f(foo.A a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_class_typeAnnotation_unprefixed() async { @@ -715,15 +684,14 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_constraints_exact_equal() async { @@ -734,7 +702,8 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion('2.15.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '2.15.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} @@ -749,7 +718,8 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion('2.16.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '2.16.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} @@ -764,15 +734,14 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion( - '2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '2.14.0' don't guarantee it. +'''); } test_constraints_greater_equal() async { @@ -783,7 +752,8 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion('>2.15.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>2.15.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} @@ -798,7 +768,8 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion('>=2.15.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.15.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} @@ -813,7 +784,10 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion('>=2.15.0-pre', ''' + writeTestPackagePubspecYamlFile( + pubspecYamlContent(sdkVersion: '>=2.15.0-pre'), + ); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} @@ -828,7 +802,8 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion('>=2.16.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.16.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} @@ -843,15 +818,14 @@ import 'dart:_internal'; class A {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(A a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_enum_constant() async { @@ -865,21 +839,21 @@ enum E { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { E.v2; +// ^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 2)], - ); +'''); } test_enum_index_onConcreteEnum() async { - await verifyVersion('>=2.12.0', ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.12.0')); + await resolveTestCodeWithDiagnostics(''' enum E { v } void f(E e) { @@ -889,18 +863,16 @@ void f(E e) { } test_enum_index_onDartCoreEnum() async { - await verifyVersion( - '>=2.12.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.12.0')); + await resolveTestCodeWithDiagnostics(''' void f(Enum e) { +// ^^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.14.0, but constraints '>=2.12.0' don't guarantee it. e.index; +// ^^^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.14.0, but constraints '>=2.12.0' don't guarantee it. } -''', - expectedDiagnostics: [ - error(diag.sdkVersionSince, 7, 4), - error(diag.sdkVersionSince, 21, 5), - ], - ); +'''); } test_enum_index_onDartCoreEnum_fromOtherLibrary() async { @@ -908,17 +880,16 @@ void f(Enum e) { Enum get myEnum => throw 0; '''); - await verifyVersion( - '>=2.12.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.12.0')); + await resolveTestCodeWithDiagnostics(''' import 'a.dart'; void f() { myEnum.index; +// ^^^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.14.0, but constraints '>=2.12.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 5)], - ); +'''); } test_enum_typeAnnotation() async { @@ -931,15 +902,14 @@ enum E { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(E a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_extension_getter() async { @@ -952,17 +922,16 @@ extension E on int { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { 0.foo; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_extension_itself_extensionOverride_methodInvocation() async { @@ -975,17 +944,16 @@ extension E on int { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { E(0).foo(); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 38, 3)], - ); +'''); } test_extension_itself_methodInvocation() async { @@ -998,17 +966,16 @@ extension E on int { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { 0.foo(); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_extension_method_methodInvocation() async { @@ -1021,17 +988,16 @@ extension E on int { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { 0.foo(); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_extension_setter() async { @@ -1044,17 +1010,16 @@ extension E on int { } '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { 0.foo = 1; +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 35, 3)], - ); +'''); } test_functionTypeAlias() async { @@ -1065,15 +1030,14 @@ import 'dart:_internal'; typedef void X(int _); '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(X a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_genericTypeAlias() async { @@ -1084,15 +1048,14 @@ import 'dart:_internal'; typedef X = List; '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(X a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_mixin_typeAnnotation() async { @@ -1103,15 +1066,14 @@ import 'dart:_internal'; mixin M {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f(M a) {} -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 27, 1)], - ); +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. +'''); } test_topLevelFunction_prefixed() async { @@ -1122,17 +1084,16 @@ import 'dart:_internal'; void bar() {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo' as foo; void f() { foo.bar(); +// ^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 44, 3)], - ); +'''); } test_topLevelFunction_unprefixed() async { @@ -1143,17 +1104,16 @@ import 'dart:_internal'; void foo() {} '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { foo(); +//^^^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 33, 3)], - ); +'''); } test_topLevelVariable_prefixed() async { @@ -1164,17 +1124,16 @@ import 'dart:_internal'; const v = 0; '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo' as foo; void f() { foo.v; +// ^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 44, 1)], - ); +'''); } test_topLevelVariable_unprefixed() async { @@ -1185,17 +1144,16 @@ import 'dart:_internal'; const v = 0; '''); - await verifyVersion( - '>=2.14.0', - ''' + writeTestPackagePubspecYamlFile(pubspecYamlContent(sdkVersion: '>=2.14.0')); + await resolveTestCodeWithDiagnostics(''' import 'dart:foo'; void f() { v; +//^ +// [diag.sdkVersionSince] This API is available since SDK 2.15.0, but constraints '>=2.14.0' don't guarantee it. } -''', - expectedDiagnostics: [error(diag.sdkVersionSince, 33, 1)], - ); +'''); } void _addDartFooLibrary(String content) { diff --git a/pkg/analyzer/test/src/diagnostics/sealed_class_subtype_outside_of_library_test.dart b/pkg/analyzer/test/src/diagnostics/sealed_class_subtype_outside_of_library_test.dart index ec9e7105e8c..dbf059c14cf 100644 --- a/pkg/analyzer/test/src/diagnostics/sealed_class_subtype_outside_of_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/sealed_class_subtype_outside_of_library_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SealedClassSubtypeOutsideOfLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class SealedClassSubtypeOutsideOfLibraryTest extends PubPackageResolutionTest { test_extends_sealed_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class Foo {} class Bar extends Foo {} '''); @@ -27,13 +28,12 @@ class Bar extends Foo {} sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar extends Foo {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 37, 3)], - ); +// ^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_extends_sealed_outside_viaTypedef_inside() async { @@ -42,13 +42,12 @@ sealed class Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar extends FooTypedef {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 37, 10)], - ); +// ^^^^^^^^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_extends_sealed_outside_viaTypedef_outside() async { @@ -56,14 +55,13 @@ class Bar extends FooTypedef {} sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; class Bar extends FooTypedef {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 63, 10)], - ); +// ^^^^^^^^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_extends_subtypeOfSealed_outside() async { @@ -72,14 +70,14 @@ sealed class Foo {} class Bar extends Foo {} '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar2 extends Bar {} '''); } test_implements_sealed_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class Foo {} class Bar implements Foo {} '''); @@ -90,13 +88,12 @@ class Bar implements Foo {} sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar implements Foo {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 40, 3)], - ); +// ^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_implements_sealed_outside_mixin() async { @@ -104,13 +101,12 @@ class Bar implements Foo {} sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; mixin Bar implements Foo {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 40, 3)], - ); +// ^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_implements_sealed_outside_viaTypedef_inside() async { @@ -119,13 +115,12 @@ sealed class Foo {} typedef FooTypedef = Foo; '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar implements FooTypedef {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 40, 10)], - ); +// ^^^^^^^^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_implements_sealed_outside_viaTypedef_outside() async { @@ -133,14 +128,13 @@ class Bar implements FooTypedef {} sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; typedef FooTypedef = Foo; class Bar implements FooTypedef {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 66, 10)], - ); +// ^^^^^^^^^^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_implements_subtypeOfSealed_outside() async { @@ -149,7 +143,7 @@ sealed class Foo {} class Bar implements Foo {} '''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar2 implements Bar {} '''); @@ -161,13 +155,12 @@ base class Foo {} sealed class B extends Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; base class Bar extends B {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 42, 1)], - ); +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_induced_final_extends() async { @@ -176,13 +169,12 @@ final class Foo {} sealed class B extends Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; final class Bar extends B {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 43, 1)], - ); +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_induced_final_implements() async { @@ -191,13 +183,12 @@ final class Foo {} sealed class B extends Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; final class Bar implements B {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 46, 1)], - ); +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_induced_interface_extends() async { @@ -206,13 +197,12 @@ interface class Foo {} sealed class B extends Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar extends B {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 37, 1)], - ); +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_mixinOutside_rawClass() async { @@ -220,27 +210,24 @@ class Bar extends B {} sealed class Foo {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'foo.dart'; class Bar with Foo {} -''', - [ - error(diag.classUsedAsMixin, 34, 3), - error(diag.sealedClassSubtypeOutsideOfLibrary, 34, 3), - ], - ); +// ^^^ +// [diag.classUsedAsMixin] The class 'Foo' can't be used as a mixin because it's neither a mixin class nor a mixin. +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'Foo' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_on_inside() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} mixin B on A {} '''); } test_on_inside_multiple() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' sealed class A {} sealed class B {} mixin C on A, B {} @@ -252,13 +239,12 @@ mixin C on A, B {} sealed class A {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; mixin B on A {} -''', - [error(diag.sealedClassSubtypeOutsideOfLibrary, 28, 1)], - ); +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'A' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } test_on_outside_multiple() async { @@ -267,15 +253,13 @@ sealed class A {} sealed class B {} '''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'a.dart'; mixin C on A, B {} -''', - [ - error(diag.sealedClassSubtypeOutsideOfLibrary, 28, 1), - error(diag.sealedClassSubtypeOutsideOfLibrary, 31, 1), - ], - ); +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'A' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +// ^ +// [diag.sealedClassSubtypeOutsideOfLibrary] The class 'B' can't be extended, implemented, or mixed in outside of its library because it's a sealed class. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/set_element_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/set_element_from_deferred_library_test.dart index baac40b2cce..73523794c44 100644 --- a/pkg/analyzer/test/src/diagnostics/set_element_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/set_element_from_deferred_library_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SetElementFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -18,55 +19,51 @@ class SetElementFromDeferredLibraryTest extends PubPackageResolutionTest with SetElementFromDeferredLibraryTestCases {} mixin SetElementFromDeferredLibraryTestCases on PubPackageResolutionTest { - @failingTest + @skippedTest test_const_ifElement_thenTrue_elseDeferred() async { // reports wrong error code newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; const cond = true; var v = const {if (cond) null else a.c}; -''', - [error(diag.setElementFromDeferredLibrary, 88, 3)], - ); +// ^^^ +// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal. +'''); } test_const_ifElement_thenTrue_thenDeferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; const cond = true; var v = const {if (cond) a.c}; -''', - [error(diag.setElementFromDeferredLibrary, 80, 1)], - ); +// ^ +// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal. +'''); } test_const_topLevel_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const {a.c}; -''', - [error(diag.setElementFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal. +'''); } test_const_topLevel_deferred_nested() async { newFile('$testPackageLibPath/lib1.dart', r''' const int c = 1;'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; var v = const {a.c + 1}; -''', - [error(diag.setElementFromDeferredLibrary, 51, 1)], - ); +// ^ +// [diag.setElementFromDeferredLibrary] Constant values from a deferred library can't be used as values in a 'const' set literal. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart index 14dd689080d..3d04d52a8d3 100644 --- a/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart +++ b/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart @@ -6,18 +6,20 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SetElementTypeNotAssignableTest); defineReflectiveTests(SetElementTypeNotAssignableWithStrictCastsTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class SetElementTypeNotAssignableTest extends PubPackageResolutionTest { test_const_ifElement_thenElseFalse_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 0; const dynamic b = 0; var v = const {if (1 < 0) a else b}; @@ -25,121 +27,114 @@ var v = const {if (1 < 0) a else b}; } test_const_ifElement_thenElseFalse_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 0; const dynamic b = 'b'; var v = const {if (1 < 0) a else b}; -''', - [error(diag.setElementTypeNotAssignable, 82, 1)], - ); +// ^ +// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'. +'''); } test_const_ifElement_thenFalse_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = const {if (1 < 0) 'a'}; -''', - [error(diag.setElementTypeNotAssignable, 31, 3)], - ); +// ^^^ +// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'. +'''); } test_const_ifElement_thenFalse_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 'a'; var v = const {if (1 < 0) a}; '''); } test_const_ifElement_thenTrue_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 0; var v = const {if (true) a}; '''); } test_const_ifElement_thenTrue_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 'a'; var v = const {if (true) a}; -''', - [error(diag.setElementTypeNotAssignable, 53, 1)], - ); +// ^ +// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'. +'''); } test_const_intInt_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 42; var v = const {a}; '''); } test_const_intInt_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' var v = const {42}; '''); } test_const_intNull_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' const a = null; var v = const {a}; -''', - [error(diag.setElementTypeNotAssignableNullability, 36, 1)], - ); +// ^ +// [diag.setElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the set type 'int'. +'''); } test_const_intNull_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = const {null}; -''', - [error(diag.setElementTypeNotAssignableNullability, 20, 4)], - ); +// ^^^^ +// [diag.setElementTypeNotAssignableNullability] The element type 'Null' can't be assigned to the set type 'int'. +'''); } test_const_intString_dynamic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' const dynamic x = 'abc'; var v = const {x}; -''', - [error(diag.setElementTypeNotAssignable, 45, 1)], - ); +// ^ +// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'. +'''); } test_const_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = const {'abc'}; -''', - [error(diag.setElementTypeNotAssignable, 20, 5)], - ); +// ^^^^^ +// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'. +'''); } test_const_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' var v = const {...[0, 1]}; '''); } test_const_stringQuestion_null_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const a = null; var v = const {a}; '''); } test_const_stringQuestion_null_value() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' var v = const {null}; '''); } test_nonConst_ifElement_thenElseFalse_intDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 'a'; const dynamic b = 'b'; var v = {if (1 < 0) a else b}; @@ -147,7 +142,7 @@ var v = {if (1 < 0) a else b}; } test_nonConst_ifElement_thenElseFalse_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 0; const dynamic b = 0; var v = {if (1 < 0) a else b}; @@ -155,48 +150,46 @@ var v = {if (1 < 0) a else b}; } test_nonConst_ifElement_thenFalse_intString() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = [if (1 < 0) 'a']; -''', - [error(diag.listElementTypeNotAssignable, 25, 3)], - ); +// ^^^ +// [diag.listElementTypeNotAssignable] The element type 'String' can't be assigned to the list type 'int'. +'''); } test_nonConst_ifElement_thenTrue_intDynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 'a'; var v = {if (true) a}; '''); } test_nonConst_ifElement_thenTrue_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic a = 0; var v = {if (true) a}; '''); } test_nonConst_spread_intInt() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' var v = {...[0, 1]}; '''); } test_notConst_intString_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' const dynamic x = 'abc'; var v = {x}; '''); } test_notConst_intString_value() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var v = {'abc'}; -''', - [error(diag.setElementTypeNotAssignable, 14, 5)], - ); +// ^^^^^ +// [diag.setElementTypeNotAssignable] The element type 'String' can't be assigned to the set type 'int'. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/shared_deferred_prefix_test.dart b/pkg/analyzer/test/src/diagnostics/shared_deferred_prefix_test.dart index 062e6544d25..b62adcb9063 100644 --- a/pkg/analyzer/test/src/diagnostics/shared_deferred_prefix_test.dart +++ b/pkg/analyzer/test/src/diagnostics/shared_deferred_prefix_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SharedDeferredPrefixTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -24,14 +25,13 @@ f1() {} library lib2; f2() {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as lib; +// ^^^^^^^^ +// [diag.sharedDeferredPrefix] The prefix of a deferred import can't be used in other import directives. import 'lib2.dart' as lib; main() { lib.f1(); lib.f2(); } -''', - [error(diag.sharedDeferredPrefix, 33, 8)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/size_annotation_dimensions_test.dart b/pkg/analyzer/test/src/diagnostics/size_annotation_dimensions_test.dart index 81f1ecd47fe..0c690ecc838 100644 --- a/pkg/analyzer/test/src/diagnostics/size_annotation_dimensions_test.dart +++ b/pkg/analyzer/test/src/diagnostics/size_annotation_dimensions_test.dart @@ -2,63 +2,61 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SizeAnnotationDimensions); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class SizeAnnotationDimensions extends PubPackageResolutionTest { test_error_array_2_3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Array(8, 8) +//^^^^^^^^^^^^ +// [diag.sizeAnnotationDimensions] 'Array's must have an 'Array' annotation that matches the dimensions. external Array>> a0; } -''', - [error(diag.sizeAnnotationDimensions, 53, 12)], - ); +'''); } test_error_array_3_2() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Array(8, 8, 8) +//^^^^^^^^^^^^^^^ +// [diag.sizeAnnotationDimensions] 'Array's must have an 'Array' annotation that matches the dimensions. external Array> a0; } -''', - [error(diag.sizeAnnotationDimensions, 53, 15)], - ); +'''); } test_error_multi_2_3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { @Array.multi([8, 8]) +//^^^^^^^^^^^^^^^^^^^^ +// [diag.sizeAnnotationDimensions] 'Array's must have an 'Array' annotation that matches the dimensions. external Array>> a0; } -''', - [error(diag.sizeAnnotationDimensions, 53, 20)], - ); +'''); } test_no_error() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'dart:ffi'; final class C extends Struct { diff --git a/pkg/analyzer/test/src/diagnostics/spread_expression_from_deferred_library_test.dart b/pkg/analyzer/test/src/diagnostics/spread_expression_from_deferred_library_test.dart index dce906191c4..8f372523226 100644 --- a/pkg/analyzer/test/src/diagnostics/spread_expression_from_deferred_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/spread_expression_from_deferred_library_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(SpreadExpressionFromDeferredLibraryTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -21,20 +22,19 @@ mixin SpreadExpressionFromDeferredLibraryTestCases on PubPackageResolutionTest { test_inList_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const List c = [];'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; f() { return const [...a.c]; -}''', - [error(diag.spreadExpressionFromDeferredLibrary, 61, 1)], - ); +// ^ +// [diag.spreadExpressionFromDeferredLibrary] Constant values from a deferred library can't be spread into a const literal. +}'''); } test_inList_deferred_notConst() async { newFile('$testPackageLibPath/lib1.dart', r''' const List c = [];'''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; f() { return [...a.c]; @@ -44,7 +44,7 @@ f() { test_inList_notDeferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const List c = [];'''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' as a; f() { return const [...a.c]; @@ -54,20 +54,19 @@ f() { test_inMap_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const Map c = {};'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; f() { return const {...a.c}; -}''', - [error(diag.spreadExpressionFromDeferredLibrary, 61, 1)], - ); +// ^ +// [diag.spreadExpressionFromDeferredLibrary] Constant values from a deferred library can't be spread into a const literal. +}'''); } test_inMap_notConst() async { newFile('$testPackageLibPath/lib1.dart', r''' const Map c = {};'''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; f() { return {...a.c}; @@ -77,7 +76,7 @@ f() { test_inMap_notDeferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const Map c = {};'''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' as a; f() { return const {...a.c}; @@ -87,20 +86,19 @@ f() { test_inSet_deferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const Set c = {};'''); - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; f() { return const {...a.c}; -}''', - [error(diag.spreadExpressionFromDeferredLibrary, 61, 1)], - ); +// ^ +// [diag.spreadExpressionFromDeferredLibrary] Constant values from a deferred library can't be spread into a const literal. +}'''); } test_inSet_notConst() async { newFile('$testPackageLibPath/lib1.dart', r''' const Set c = {};'''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' deferred as a; f() { return {...a.c}; @@ -110,7 +108,7 @@ f() { test_inSet_notDeferred() async { newFile('$testPackageLibPath/lib1.dart', r''' const Set c = {};'''); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'lib1.dart' as a; f() { return const {...a.c}; diff --git a/pkg/analyzer/test/src/diagnostics/static_access_to_instance_member_test.dart b/pkg/analyzer/test/src/diagnostics/static_access_to_instance_member_test.dart index 78d60728198..b4e65d4195c 100644 --- a/pkg/analyzer/test/src/diagnostics/static_access_to_instance_member_test.dart +++ b/pkg/analyzer/test/src/diagnostics/static_access_to_instance_member_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(StaticAccessToInstanceMemberTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class StaticAccessToInstanceMemberTest extends PubPackageResolutionTest { test_annotation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { const A.name(); } @@ -27,126 +28,117 @@ main() { } test_extension_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { int get g => 0; } f() { E.g; +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'g' can't be accessed using static access. } -''', - [error(diag.staticAccessToInstanceMember, 51, 1)], - ); +'''); } test_extension_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void m() {} } f() { E.m(); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'm' can't be accessed using static access. } -''', - [error(diag.staticAccessToInstanceMember, 47, 1)], - ); +'''); } test_extension_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { void set s(int i) {} } f() { E.s = 2; +// ^ +// [diag.staticAccessToInstanceMember] Instance member 's' can't be accessed using static access. } -''', - [error(diag.staticAccessToInstanceMember, 56, 1)], - ); +'''); } test_method_invocation() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { m() {} } main() { A.m(); -}''', - [error(diag.staticAccessToInstanceMember, 34, 1)], - ); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'm' can't be accessed using static access. +}'''); } test_method_reference() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { m() {} } main() { A.m; -}''', - [error(diag.staticAccessToInstanceMember, 34, 1)], - ); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'm' can't be accessed using static access. +}'''); } test_propertyAccess_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { var f; } main() { A.f; -}''', - [error(diag.staticAccessToInstanceMember, 34, 1)], - ); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'f' can't be accessed using static access. +}'''); } test_propertyAccess_field_toplevel_generic() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class C { List t = []; } var x = C.t; -''', - [error(diag.staticAccessToInstanceMember, 43, 1)], - ); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 't' can't be accessed using static access. +'''); } test_propertyAccess_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { get f => 42; } main() { A.f; -}''', - [error(diag.staticAccessToInstanceMember, 40, 1)], - ); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'f' can't be accessed using static access. +}'''); } test_propertyAccess_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { set f(x) {} } main() { A.f = 42; -}''', - [error(diag.staticAccessToInstanceMember, 39, 1)], - ); +// ^ +// [diag.staticAccessToInstanceMember] Instance member 'f' can't be accessed using static access. +}'''); } test_static_method() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static m() {} } @@ -158,7 +150,7 @@ main() { } test_static_propertyAccess_field() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static var f; } @@ -170,7 +162,7 @@ main() { } test_static_propertyAccess_propertyAccessor() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A { static get f => 42; static set f(x) {} diff --git a/pkg/analyzer/test/src/diagnostics/strict_raw_type_test.dart b/pkg/analyzer/test/src/diagnostics/strict_raw_type_test.dart index 0c000b7a3ad..6f2a0b1dfef 100644 --- a/pkg/analyzer/test/src/diagnostics/strict_raw_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/strict_raw_type_test.dart @@ -2,15 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:analyzer_testing/utilities/utilities.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(StrictRawTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -25,7 +26,7 @@ class StrictRawTypeTest extends PubPackageResolutionTest { } test_asExpression() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic x) { print(x as List); } @@ -33,7 +34,7 @@ void f(dynamic x) { } test_asExpression_typeArgument() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic x) { print(x as List); } @@ -41,7 +42,7 @@ void f(dynamic x) { } test_castPattern() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f([(Object, )? l]) { var (_ as List, ) = l!; } @@ -49,7 +50,7 @@ void f([(Object, )? l]) { } test_castPattern_typeArgument() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f([(Object, )? l]) { var (_ as List, ) = l!; } @@ -59,7 +60,7 @@ void f([(Object, )? l]) { test_constantPattern() async { // This is not considered a "strict raw type" here, but a "strict inference" // issue. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(C c) { switch (c) { case const C(): @@ -74,7 +75,7 @@ class C { test_functionParts_optionalTypeArg() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @optionalTypeArgs class C {} @@ -84,20 +85,19 @@ void g(C a) {} } test_genericTypeArgument_extensionType_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int i) {} void f() { >[]; +// ^ +// [diag.strictRawType] The generic type 'E' should have explicit type arguments but doesn't. } -''', - [error(diag.strictRawType, 50, 1)], - ); +'''); } test_genericTypeArgument_extensionType_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int i) {} void f() { @@ -107,70 +107,64 @@ void f() { } test_genericTypeArgument_extensionTypeImplements_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(List i) implements Iterable {} -''', - [error(diag.strictRawType, 41, 8)], - ); +// ^^^^^^^^ +// [diag.strictRawType] The generic type 'Iterable' should have explicit type arguments but doesn't. +'''); } test_genericTypeArgument_extensionTypeImplementsExtensionType_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(Iterable i) {} extension type F(List j) implements E {} -''', - [error(diag.strictRawType, 81, 1)], - ); +// ^ +// [diag.strictRawType] The generic type 'E' should have explicit type arguments but doesn't. +'''); } test_genericTypeArgument_extensionTypeRepresentationType_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(List i) {} -''', - [error(diag.strictRawType, 17, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_genericTypeArgument_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var a = []; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. } -''', - [ - error(diag.unusedLocalVariable, 17, 1), - error(diag.strictRawType, 22, 4), - ], - ); +'''); } test_genericTypeArgument_withTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var a = >[]; +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [error(diag.unusedLocalVariable, 17, 1)], - ); +'''); } test_instanceCreation() async { // This is not considered a "strict raw type" here, but a "strict inference" // issue. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' var c = List.empty(); '''); } test_isExpression() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(dynamic x) { print(x is List); print(x is List); @@ -180,50 +174,45 @@ void f(dynamic x) { } test_localVariable_extensionType_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int i) {} void f() { E e = E(1); +//^ +// [diag.strictRawType] The generic type 'E' should have explicit type arguments but doesn't. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used. } -''', - [ - error(diag.strictRawType, 48, 1), - error(diag.unusedLocalVariable, 50, 1), - ], - ); +'''); } test_localVariable_extensionType_withTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type E(int i) {} void f() { E e = E(1); +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'e' isn't used. } -''', - [error(diag.unusedLocalVariable, 55, 1)], - ); +'''); } test_localVariable_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f() { List a = [1, 2, 3]; +//^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used. } -''', - [ - error(diag.strictRawType, 13, 4), - error(diag.unusedLocalVariable, 18, 1), - ], - ); +'''); } test_localVariable_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { List a = [1, 2, 3]; print(a); @@ -232,17 +221,16 @@ void f() { } test_mixinApplication_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class C {} class D = Object with C; -''', - [error(diag.strictRawType, 42, 1)], - ); +// ^ +// [diag.strictRawType] The generic type 'C' should have explicit type arguments but doesn't. +'''); } test_mixinApplication_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class C {} class D = Object with C; '''); @@ -250,7 +238,7 @@ class D = Object with C; test_nonFunctionTypeAlias_explicitTypeArg() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' typedef List2 = List; void f(List2 a) {} '''); @@ -258,18 +246,17 @@ void f(List2 a) {} test_nonFunctionTypeAlias_missingTypeArg() async { writeTestPackageConfigWithMeta(); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(''' typedef List2 = List; void f(List2 a) {} -''', - [error(diag.strictRawType, 35, 5)], - ); +// ^^^^^ +// [diag.strictRawType] The generic type 'List2' should have explicit type arguments but doesn't. +'''); } test_nonFunctionTypeAlias_optionalTypeArgs() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(''' import 'package:meta/meta.dart'; @optionalTypeArgs typedef List2 = List; @@ -280,7 +267,7 @@ void f(List2 a) {} test_objectPattern() async { // This is not considered a "strict raw type" here, but a "strict inference" // issue. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f(Object o) { switch (o) { case List(): @@ -290,115 +277,103 @@ void f(Object o) { } test_parameter_default_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f({List a = const []}) {} -''', - [error(diag.strictRawType, 8, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_parameter_fieldFormal_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C { Object a; C(List this.a); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. } -''', - [error(diag.strictRawType, 26, 4)], - ); +'''); } test_parameter_functionTyped_parameter_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(void a(List p)) {} -''', - [error(diag.strictRawType, 14, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_parameter_functionTyped_returnType_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(List a()) {} -''', - [error(diag.strictRawType, 7, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_parameter_primaryDeclaring_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C(final List a); -''', - [error(diag.strictRawType, 14, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_parameter_simple_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void f(List a) {} -''', - [error(diag.strictRawType, 7, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_parameter_super_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' abstract class C { Object a; C(this.a); } class D extends C { D(List super.a); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. } -''', - [error(diag.strictRawType, 70, 4)], - ); +'''); } test_returnType_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' List f(int a) => [1, 2, 3]; -''', - [error(diag.strictRawType, 0, 4)], - ); +// [diag.strictRawType][column 1][length 4] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_superclassWith_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' mixin class C {} class D extends Object with C {} -''', - [error(diag.strictRawType, 48, 1)], - ); +// ^ +// [diag.strictRawType] The generic type 'C' should have explicit type arguments but doesn't. +'''); } test_superclassWith_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' mixin class C {} class D extends Object with C {} '''); } test_topLevelField_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' List a = []; -''', - [error(diag.strictRawType, 0, 4)], - ); +// [diag.strictRawType][column 1][length 4] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_topLevelField_optionalTypeArg() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @optionalTypeArgs class C {} @@ -409,7 +384,7 @@ void set s(C a) {} } test_topLevelField_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' List a = []; List get g => []; void set s(List a) {} @@ -417,46 +392,39 @@ void set s(List a) {} } test_topLevelGetter_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' List get g => []; -''', - [error(diag.strictRawType, 0, 4)], - ); +// [diag.strictRawType][column 1][length 4] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_topLevelSetter_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void set s(List a) {} -''', - [error(diag.strictRawType, 11, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_typeAlias_classic_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef T F1(T _); F1 func = (a) => a; -''', - [error(diag.strictRawType, 22, 2)], - ); +// [diag.strictRawType][column 1][length 2] The generic type 'F1' should have explicit type arguments but doesn't. +'''); } test_typeAlias_modern_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F1 = T Function(T); F1 func = (a) => a; -''', - [error(diag.strictRawType, 31, 2)], - ); +// [diag.strictRawType][column 1][length 2] The generic type 'F1' should have explicit type arguments but doesn't. +'''); } test_typeAlias_modern_optionalTypeArgs() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @optionalTypeArgs typedef T F1(T _); @@ -468,7 +436,7 @@ F2 f2 = (a) => a; } test_typeAlias_modern_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef T F1(T _); typedef F2 = T Function(T); typedef F3 = T Function(T); @@ -480,7 +448,7 @@ F3 f3 = (T a) => a; test_typeInClassDeclaration_optionalTypeArgs() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @optionalTypeArgs mixin class C {} @@ -492,7 +460,7 @@ class G implements C {} } test_typeInConstructorName() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C { C(); C.named(); @@ -504,26 +472,24 @@ var d = C.named(); } test_typeInExtendedType_anonymous_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension on List {} -''', - [error(diag.strictRawType, 13, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_typeInExtendedType_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension E on List {} -''', - [error(diag.strictRawType, 15, 4)], - ); +// ^^^^ +// [diag.strictRawType] The generic type 'List' should have explicit type arguments but doesn't. +'''); } test_typeInExtendedType_optionalTypeArgs() async { writeTestPackageConfigWithMeta(); - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; @optionalTypeArgs class C {} @@ -533,48 +499,46 @@ extension on C {} } test_typeInExtendedType_present() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' extension E on List {} extension F on List {} '''); } test_typeInInterface_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C {} class D implements C {} -''', - [error(diag.strictRawType, 33, 1)], - ); +// ^ +// [diag.strictRawType] The generic type 'C' should have explicit type arguments but doesn't. +'''); } test_typeInInterface_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C {} class D implements C {} '''); } test_typeInSuperclass_missing() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C {} class D extends C {} -''', - [error(diag.strictRawType, 30, 1)], - ); +// ^ +// [diag.strictRawType] The generic type 'C' should have explicit type arguments but doesn't. +'''); } test_typeInSuperclass_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C {} class D extends C {} '''); } test_typeLiteral_raw() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' void f() { var t = List; print(t); @@ -583,17 +547,16 @@ void f() { } test_typeParameterBound_missingTypeArg() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class C {} class D {} -''', - [error(diag.strictRawType, 32, 1)], - ); +// ^ +// [diag.strictRawType] The generic type 'C' should have explicit type arguments but doesn't. +'''); } test_typeParameterBound_withTypeArg() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class C {} class D> {} '''); diff --git a/pkg/analyzer/test/src/diagnostics/tearoff_of_generative_constructor_of_abstract_class_test.dart b/pkg/analyzer/test/src/diagnostics/tearoff_of_generative_constructor_of_abstract_class_test.dart index ca117de6821..c0c3b8a1b67 100644 --- a/pkg/analyzer/test/src/diagnostics/tearoff_of_generative_constructor_of_abstract_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/tearoff_of_generative_constructor_of_abstract_class_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TearoffOfGenerativeConstructorOfAbstractClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -17,7 +18,7 @@ main() { class TearoffOfGenerativeConstructorOfAbstractClassTest extends PubPackageResolutionTest { test_abstractClass_factoryConstructor() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { factory A() => B(); } @@ -31,7 +32,7 @@ void foo() { } test_abstractClass_factoryConstructor_viaEquals() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { factory A() = B; } @@ -45,22 +46,21 @@ void foo() { } test_abstractClass_generativeConstructor() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' abstract class A { A(); } void foo() { A.new; +//^^^^^ +// [diag.tearoffOfGenerativeConstructorOfAbstractClass] A generative constructor of an abstract class can't be torn off. } -''', - [error(diag.tearoffOfGenerativeConstructorOfAbstractClass, 44, 5)], - ); +'''); } test_concreteClass_factoryConstructor() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() => A.two(); @@ -74,7 +74,7 @@ void foo() { } test_concreteClass_factoryConstructor_viaEquals() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { factory A() = A.two; @@ -88,7 +88,7 @@ void foo() { } test_concreteClass_generativeConstructor() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' class A { A(); } diff --git a/pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart b/pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart index ad641511da0..3c86fccf136 100644 --- a/pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TearoffWithMustBeConstParameterTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -22,7 +23,7 @@ class TearoffWithMustBeConstParameterTest extends PubPackageResolutionTest { } test_class_method_commentReference_threeNames() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; import '' as self; /// Reference to [self.C.f]. @@ -35,7 +36,7 @@ class C { } test_class_method_commentReference_twoNames() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; /// Reference to [C.f]. var a = 1; @@ -47,21 +48,20 @@ class C { } test_class_method_implicitThis_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; class C { Object get n => m; +// ^ +// [diag.tearoffWithMustBeConstParameter] The function 'm' has a parameter marked as '@mustBeConst' and can't be torn off. // ignore: experimental_member_use void m(@mustBeConst int x) {} } -''', - [error(diag.tearoffWithMustBeConstParameter, 61, 1)], - ); +'''); } test_class_method_invocation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C().m(1); class C { @@ -72,33 +72,31 @@ class C { } test_class_method_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C().m; +// ^ +// [diag.tearoffWithMustBeConstParameter] The function 'm' has a parameter marked as '@mustBeConst' and can't be torn off. class C { // ignore: experimental_member_use void m(@mustBeConst int x) {} } -''', - [error(diag.tearoffWithMustBeConstParameter, 45, 1)], - ); +'''); } test_class_primaryConstructor_named_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C.named; +// ^^^^^^^ +// [diag.tearoffWithMustBeConstParameter] The function 'named' has a parameter marked as '@mustBeConst' and can't be torn off. // ignore: experimental_member_use class C.named(@mustBeConst int x); -''', - [error(diag.tearoffWithMustBeConstParameter, 41, 7)], - ); +'''); } test_class_primaryConstructor_unnamed_invocation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C(1); // ignore: experimental_member_use @@ -107,33 +105,31 @@ class C(@mustBeConst int x); } test_class_primaryConstructor_unnamed_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C.new; +// ^^^^^ +// [diag.tearoffWithMustBeConstParameter] The function 'new' has a parameter marked as '@mustBeConst' and can't be torn off. // ignore: experimental_member_use class C(@mustBeConst int x); -''', - [error(diag.tearoffWithMustBeConstParameter, 41, 5)], - ); +'''); } test_class_secondaryConstructor_named_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C.named; +// ^^^^^^^ +// [diag.tearoffWithMustBeConstParameter] The function 'named' has a parameter marked as '@mustBeConst' and can't be torn off. class C { // ignore: experimental_member_use C.named(@mustBeConst int x); } -''', - [error(diag.tearoffWithMustBeConstParameter, 41, 7)], - ); +'''); } test_class_secondaryConstructor_unnamed_invocation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C.new(1); class C { @@ -144,21 +140,20 @@ class C { } test_class_secondaryConstructor_unnamed_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = C.new; +// ^^^^^ +// [diag.tearoffWithMustBeConstParameter] The function 'new' has a parameter marked as '@mustBeConst' and can't be torn off. class C { // ignore: experimental_member_use C(@mustBeConst int x); } -''', - [error(diag.tearoffWithMustBeConstParameter, 41, 5)], - ); +'''); } test_topLevelFunction_commentReference() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; /// Reference to [f]. var a = 1; @@ -168,19 +163,18 @@ void f(@mustBeConst int x) {} } test_topLevelFunction_instantiated_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = f; +// ^ +// [diag.tearoffWithMustBeConstParameter] The function 'f' has a parameter marked as '@mustBeConst' and can't be torn off. // ignore: experimental_member_use void f(@mustBeConst T x) {} -''', - [error(diag.tearoffWithMustBeConstParameter, 41, 1)], - ); +'''); } test_topLevelFunction_invocation() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = f(1); // ignore: experimental_member_use @@ -189,14 +183,13 @@ void f(@mustBeConst int x) {} } test_topLevelFunction_tearoff() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' import 'package:meta/meta.dart'; var g = f; +// ^ +// [diag.tearoffWithMustBeConstParameter] The function 'f' has a parameter marked as '@mustBeConst' and can't be torn off. // ignore: experimental_member_use void f(@mustBeConst int x) {} -''', - [error(diag.tearoffWithMustBeConstParameter, 41, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart b/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart index ca3e5d5c87a..d1edff603e2 100644 --- a/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart @@ -2,21 +2,22 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ThrowOfInvalidTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class ThrowOfInvalidTypeTest extends PubPackageResolutionTest { test_dynamic() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(dynamic a) { throw a; } @@ -24,7 +25,7 @@ f(dynamic a) { } test_nonNullable() async { - await assertNoErrorsInCode(''' + await resolveTestCodeWithDiagnostics(r''' f(int a) { throw a; } @@ -32,13 +33,12 @@ f(int a) { } test_nullable() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(int? a) { throw a; +// ^ +// [diag.throwOfInvalidType] The type 'int?' of the thrown expression must be assignable to 'Object'. } -''', - [error(diag.throwOfInvalidType, 20, 1)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/top_level_cycle_test.dart b/pkg/analyzer/test/src/diagnostics/top_level_cycle_test.dart index 899dc4aca8b..e35df9ba1b6 100644 --- a/pkg/analyzer/test/src/diagnostics/top_level_cycle_test.dart +++ b/pkg/analyzer/test/src/diagnostics/top_level_cycle_test.dart @@ -2,73 +2,75 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TopLevelCycleTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TopLevelCycleTest extends PubPackageResolutionTest { test_cycle_fields() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static final x = y + 1; +// ^ +// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x, y. static final y = x + 1; +// ^ +// [diag.topLevelCycle] The type of 'y' can't be inferred because it depends on itself through the cycle: x, y. } -''', - [error(diag.topLevelCycle, 25, 1), error(diag.topLevelCycle, 51, 1)], - ); +'''); } test_cycle_fields_chain() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { static final a = b.c; +// ^ +// [diag.topLevelCycle] The type of 'a' can't be inferred because it depends on itself through the cycle: a, c. static final b = A(); final c = a; +// ^ +// [diag.topLevelCycle] The type of 'c' can't be inferred because it depends on itself through the cycle: a, c. } -''', - [error(diag.topLevelCycle, 25, 1), error(diag.topLevelCycle, 66, 1)], - ); +'''); } test_cycle_topLevelVariables() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var x = y + 1; +// ^ +// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x, y. var y = x + 1; -''', - [error(diag.topLevelCycle, 4, 1), error(diag.topLevelCycle, 19, 1)], - ); +// ^ +// [diag.topLevelCycle] The type of 'y' can't be inferred because it depends on itself through the cycle: x, y. +'''); } test_singleVariable() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var x = x; -''', - [error(diag.topLevelCycle, 4, 1)], - ); +// ^ +// [diag.topLevelCycle] The type of 'x' can't be inferred because it depends on itself through the cycle: x. +'''); } test_singleVariable_fromList() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' var elems = [ +// ^^^^^ +// [diag.topLevelCycle] The type of 'elems' can't be inferred because it depends on itself through the cycle: elems. [ 1, elems, 3, ], ]; -''', - [error(diag.topLevelCycle, 4, 5)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart b/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart index 94803d131c7..b27ddde16ab 100644 --- a/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_alias_cannot_reference_itself_test.dart @@ -2,93 +2,86 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeAliasCannotReferenceItselfTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeAliasCannotReferenceItselfTest extends PubPackageResolutionTest { test_functionTypeAlias_typeParameterBounds() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A>(); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_functionTypedParameter_returnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A(A b()); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_generic() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = void Function(List l); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. typedef G = void Function(List l); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. main() { F? foo(G? g) => g; foo(null); } -''', - [ - error(diag.typeAliasCannotReferenceItself, 8, 1), - error(diag.typeAliasCannotReferenceItself, 46, 1), - ], - ); +'''); } test_genericTypeAlias_typeParameterBounds() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A> = void Function(); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_infiniteParameterBoundCycle() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F> = F Function(); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_issue11987() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef void F(List l); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. typedef void G(List l); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. main() { F? foo(G? g) => g; foo(null); } -''', - [ - error(diag.typeAliasCannotReferenceItself, 13, 1), - error(diag.typeAliasCannotReferenceItself, 40, 1), - ], - ); +'''); } test_issue19459() async { // A complex example involving multiple classes. This is legal, since // typedef F references itself only via a class. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' class A {} abstract class D { f(E e); @@ -99,101 +92,90 @@ typedef D F(); } test_nonFunction_aliasedType_cycleOf2() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef T1 = T2; +// ^^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. typedef T2 = T1; -''', - [ - error(diag.typeAliasCannotReferenceItself, 8, 2), - error(diag.typeAliasCannotReferenceItself, 25, 2), - ], - ); +// ^^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_nonFunction_aliasedType_directly_functionWithIt() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef T = void Function(T); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_nonFunction_aliasedType_directly_it_none() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef T = T; -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_nonFunction_aliasedType_directly_it_question() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef T = T?; -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_nonFunction_aliasedType_directly_ListOfIt() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef T = List; -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_nonFunction_typeParameterBounds() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef T> = List; -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_parameterType_named() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A({A a}); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_parameterType_positional() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A([A a]); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_parameterType_required() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A(A a); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_parameterType_typeArgument() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A(List a); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_referencesReturnType_inTypeAlias() async { - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef B A(); class B { A? a; @@ -203,7 +185,7 @@ class B { test_returnClass_withTypeAlias() async { // A typedef is allowed to indirectly reference itself via a class. - await assertNoErrorsInCode(r''' + await resolveTestCodeWithDiagnostics(r''' typedef C A(); typedef A B(); class C { @@ -213,33 +195,29 @@ class C { } test_returnType() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' typedef A A(); -''', - [error(diag.typeAliasCannotReferenceItself, 10, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_returnType_indirect() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef B A(); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. typedef A B(); -''', - [ - error(diag.typeAliasCannotReferenceItself, 10, 1), - error(diag.typeAliasCannotReferenceItself, 25, 1), - ], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } test_usingRecordType_directly() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' typedef F = (F, int) Function(); -''', - [error(diag.typeAliasCannotReferenceItself, 8, 1)], - ); +// ^ +// [diag.typeAliasCannotReferenceItself] Typedefs can't reference themselves directly or recursively via another typedef. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_annotation_deferred_class_test.dart b/pkg/analyzer/test/src/diagnostics/type_annotation_deferred_class_test.dart index d509b2a8dab..bae34f93965 100644 --- a/pkg/analyzer/test/src/diagnostics/type_annotation_deferred_class_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_annotation_deferred_class_test.dart @@ -2,14 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeAnnotationDeferredClassTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @@ -19,96 +20,84 @@ class TypeAnnotationDeferredClassTest extends PubPackageResolutionTest { newFile('$testPackageLibPath/lib1.dart', ''' class D {} '''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; class C { const C(); } @C() main () {} -''', - [ - error( - diag.typeAnnotationDeferredClass, - 77, - 3, - messageContains: ["'a.D'"], - ), - ], - ); +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.D' can't be used in a declaration, cast, or type test. +'''); } test_asExpression() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; f(v) { v as a.A; -}''', - [error(diag.typeAnnotationDeferredClass, 62, 3)], - ); +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +}'''); } test_catchClause() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; f(v) { try { } on a.A { +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. } -}''', - [error(diag.typeAnnotationDeferredClass, 70, 3)], - ); +}'''); } test_fieldFormalParameter() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; class C { var v; C(a.A this.v); -}''', - [error(diag.typeAnnotationDeferredClass, 71, 3)], - ); +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +}'''); } test_functionDeclaration_returnType() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; a.A? f() { return null; } -''', - [error(diag.typeAnnotationDeferredClass, 48, 4)], - ); +// [diag.typeAnnotationDeferredClass][column 1][length 4] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +'''); } test_functionTypedFormalParameter_returnType() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' library root; import 'lib1.dart' deferred as a; -f(a.A g()) {}''', - [error(diag.typeAnnotationDeferredClass, 50, 3)], +f(a.A g()) {} +//^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.''', ); } @@ -116,45 +105,43 @@ f(a.A g()) {}''', newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; f(v) { bool b = v is a.A; -}''', - [ - error(diag.unusedLocalVariable, 62, 1), - error(diag.typeAnnotationDeferredClass, 71, 3), - ], - ); +// ^ +// [diag.unusedLocalVariable] The value of the local variable 'b' isn't used. +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +}'''); } test_methodDeclaration_returnType() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; class C { a.A? m() { return null; } -}''', - [error(diag.typeAnnotationDeferredClass, 60, 4)], - ); +//^^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +}'''); } test_simpleFormalParameter() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' library root; import 'lib1.dart' deferred as a; -f(a.A v) {}''', - [error(diag.typeAnnotationDeferredClass, 50, 3)], +f(a.A v) {} +//^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.''', ); } @@ -162,45 +149,43 @@ f(a.A v) {}''', newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; class C {} C c = C(); -''', - [error(diag.typeAnnotationDeferredClass, 64, 3)], - ); +//^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +'''); } test_typeArgumentList2() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; class C {} C c = C(); -''', - [ - error(diag.typeAnnotationDeferredClass, 67, 3), - error(diag.typeAnnotationDeferredClass, 72, 3), - ], - ); +//^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +'''); } test_typeParameter_bound() async { newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics( + r''' library root; import 'lib1.dart' deferred as a; -class C {}''', - [error(diag.typeAnnotationDeferredClass, 66, 3)], +class C {} +// ^^^ +// [diag.typeAnnotationDeferredClass] The deferred type 'a.A' can't be used in a declaration, cast, or type test.''', ); } @@ -208,13 +193,11 @@ class C {}''', newFile('$testPackageLibPath/lib1.dart', ''' library lib1; class A {}'''); - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' library root; import 'lib1.dart' deferred as a; a.A v = a.A(); -''', - [error(diag.typeAnnotationDeferredClass, 48, 3)], - ); +// [diag.typeAnnotationDeferredClass][column 1][length 3] The deferred type 'a.A' can't be used in a declaration, cast, or type test. +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_check_is_not_null_test.dart b/pkg/analyzer/test/src/diagnostics/type_check_is_not_null_test.dart index 9f74dcdede1..98a1a6a793d 100644 --- a/pkg/analyzer/test/src/diagnostics/type_check_is_not_null_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_check_is_not_null_test.dart @@ -2,27 +2,27 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeCheckIsNotNullTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeCheckIsNotNullTest extends PubPackageResolutionTest { test_not_Null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool m(i) { return i is! Null; +// ^^^^^^^^^^ +// [diag.typeCheckIsNotNull] Tests for non-null should be done with '!= null'. } -''', - [error(diag.typeCheckIsNotNull, 21, 10)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_check_is_null_test.dart b/pkg/analyzer/test/src/diagnostics/type_check_is_null_test.dart index 04b59652e6c..28242838ea3 100644 --- a/pkg/analyzer/test/src/diagnostics/type_check_is_null_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_check_is_null_test.dart @@ -2,27 +2,27 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeCheckIsNullTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeCheckIsNullTest extends PubPackageResolutionTest { test_is_Null() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' bool m(i) { return i is Null; +// ^^^^^^^^^ +// [diag.typeCheckIsNull] Tests for null should be done with '== null'. } -''', - [error(diag.typeCheckIsNull, 21, 9)], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_parameter_referenced_by_static_test.dart b/pkg/analyzer/test/src/diagnostics/type_parameter_referenced_by_static_test.dart index bc5334b6a36..327cb7db6de 100644 --- a/pkg/analyzer/test/src/diagnostics/type_parameter_referenced_by_static_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_parameter_referenced_by_static_test.dart @@ -2,146 +2,136 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeParameterReferencedByStaticTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeParameterReferencedByStaticTest extends PubPackageResolutionTest { test_class_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static T? foo; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 22, 1)], - ); +'''); } test_class_getter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static T? get foo => null; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 22, 1)], - ); +'''); } test_class_method_bodyReference() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static foo() { // ignore:unused_local_variable T v; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } } -''', - [error(diag.typeParameterReferencedByStatic, 70, 1)], - ); +'''); } test_class_method_closure() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static Object foo() { return (T a) {}; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } } -''', - [error(diag.typeParameterReferencedByStatic, 49, 1)], - ); +'''); } test_class_method_parameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static foo(T a) {} +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 26, 1)], - ); +'''); } test_class_method_return() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static T foo() { +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. throw 0; } } -''', - [error(diag.typeParameterReferencedByStatic, 22, 1)], - ); +'''); } test_class_setter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static set foo(T _) {} +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 30, 1)], - ); +'''); } test_expression_method() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { static foo() { T; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } } -''', - [error(diag.typeParameterReferencedByStatic, 34, 1)], - ); +'''); } test_extension_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static T? foo; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 33, 1)], - ); +'''); } test_extension_method_return() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' extension E on int { static T foo() => throw 0; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 33, 1)], - ); +'''); } test_mixin_field() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' mixin A { static T? foo; +// ^ +// [diag.typeParameterReferencedByStatic] Static members can't reference type parameters of the class. } -''', - [error(diag.typeParameterReferencedByStatic, 22, 1)], - ); +'''); } } 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 77928e49a2b..460f0469112 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 @@ -2,135 +2,123 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeParameterSupertypeOfItsBoundTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeParameterSupertypeOfItsBoundTest extends PubPackageResolutionTest { test_1of1() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { +// ^ +// [diag.typeParameterSupertypeOfItsBound] 'T' can't be a supertype of its upper bound. } -''', - [error(diag.typeParameterSupertypeOfItsBound, 8, 1)], - ); +'''); } test_1of1_local() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void m() { void local() {} +// ^ +// [diag.typeParameterSupertypeOfItsBound] 'T' can't be a supertype of its upper bound. local; } -''', - [error(diag.typeParameterSupertypeOfItsBound, 24, 1)], - ); +'''); } test_1of1_local_viaExtensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(T it) {} void m() { void local>() {} +// ^ +// [diag.typeParameterSupertypeOfItsBound] 'U' can't be a supertype of its upper bound. local; } -''', - [error(diag.typeParameterSupertypeOfItsBound, 54, 1)], - ); +'''); } test_1of1_used() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' class A { +// ^ +// [diag.typeParameterSupertypeOfItsBound] 'T' can't be a supertype of its upper bound. void foo(x) { x is T; } } -''', - [error(diag.typeParameterSupertypeOfItsBound, 8, 1)], - ); +'''); } test_1of1_viaExtensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(T it) {} class B> {} -''', - [error(diag.typeParameterSupertypeOfItsBound, 38, 1)], - ); +// ^ +// [diag.typeParameterSupertypeOfItsBound] 'U' can't be a supertype of its upper bound. +'''); } test_2of2_local_viaExtensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(T it) {} void m() { void local, T2 extends T1>() {} +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound. +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T2' can't be a supertype of its upper bound. local; } -''', - [ - error(diag.typeParameterSupertypeOfItsBound, 54, 2), - error(diag.typeParameterSupertypeOfItsBound, 72, 2), - ], - ); +'''); } test_2of2_viaExtensionType() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' extension type A(T it) {} class B, T2 extends T1> {} -''', - [ - error(diag.typeParameterSupertypeOfItsBound, 38, 2), - error(diag.typeParameterSupertypeOfItsBound, 56, 2), - ], - ); +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound. +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T2' can't be a supertype of its upper bound. +'''); } test_2of3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' class A { +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound. +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T3' can't be a supertype of its upper bound. } -''', - [ - error(diag.typeParameterSupertypeOfItsBound, 8, 2), - error(diag.typeParameterSupertypeOfItsBound, 27, 2), - ], - ); +'''); } test_local_2of3() async { - await assertErrorsInCode( - r''' + await resolveTestCodeWithDiagnostics(r''' void m() { void local() {} +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T1' can't be a supertype of its upper bound. +// ^^ +// [diag.typeParameterSupertypeOfItsBound] 'T3' can't be a supertype of its upper bound. local; } -''', - [ - error(diag.typeParameterSupertypeOfItsBound, 24, 2), - error(diag.typeParameterSupertypeOfItsBound, 43, 2), - ], - ); +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_test_with_non_type_test.dart b/pkg/analyzer/test/src/diagnostics/type_test_with_non_type_test.dart index 8f26595d895..7c1bd210b5f 100644 --- a/pkg/analyzer/test/src/diagnostics/type_test_with_non_type_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_test_with_non_type_test.dart @@ -2,28 +2,29 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeTestWithNonTypeTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeTestWithNonTypeTest extends PubPackageResolutionTest { test_parameter() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' var A = 0; f(p) { if (p is A) { - } -}''', - [error(diag.typeTestWithNonType, 29, 1)], - ); +// ^ +// [diag.typeTestWithNonType] The name 'A' isn't a type and can't be used in an 'is' expression. + } +} +'''); } } diff --git a/pkg/analyzer/test/src/diagnostics/type_test_with_undefined_name_test.dart b/pkg/analyzer/test/src/diagnostics/type_test_with_undefined_name_test.dart index f4b0877006b..2f454765bb3 100644 --- a/pkg/analyzer/test/src/diagnostics/type_test_with_undefined_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/type_test_with_undefined_name_test.dart @@ -2,27 +2,28 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; +import '../dart/resolution/node_text_expectations.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(TypeTestWithUndefinedNameTest); + defineReflectiveTests(UpdateNodeTextExpectations); }); } @reflectiveTest class TypeTestWithUndefinedNameTest extends PubPackageResolutionTest { test_undefined() async { - await assertErrorsInCode( - ''' + await resolveTestCodeWithDiagnostics(r''' f(p) { if (p is A) { - } -}''', - [error(diag.typeTestWithUndefinedName, 18, 1)], - ); +// ^ +// [diag.typeTestWithUndefinedName] The name 'A' isn't defined, so it can't be used in an 'is' expression. + } +} +'''); } }