Skip to content

Commit

Permalink
analyzer: move tests to 4 new test files in diagnostics/
Browse files Browse the repository at this point in the history
Change-Id: Ied68dc6a383c7ca0a44dbcd8381f3a94832d44fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153903
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
srawlins authored and commit-bot@chromium.org committed Jul 10, 2020
1 parent 90ce990 commit 6e687d1
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 188 deletions.
191 changes: 3 additions & 188 deletions pkg/analyzer/test/generated/static_type_warning_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,36 +190,6 @@ void main() {
]);
}

test_expectedOneListTypeArgument() async {
await assertErrorsInCode(r'''
main() {
<int, int> [];
}
''', [
error(StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, 11, 10),
]);
}

test_expectedOneSetTypeArgument() async {
await assertErrorsInCode(r'''
main() {
<int, int, int>{2, 3};
}
''', [
error(StaticTypeWarningCode.EXPECTED_ONE_SET_TYPE_ARGUMENTS, 11, 15),
]);
}

test_expectedTwoMapTypeArguments_three() async {
await assertErrorsInCode(r'''
main() {
<int, int, int> {};
}
''', [
error(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, 11, 15),
]);
}

test_forIn_declaredVariableRightType() async {
await assertErrorsInCode('''
f() {
Expand Down Expand Up @@ -476,106 +446,9 @@ class C {
]);
}

test_instanceAccessToStaticMember_method_reference() async {
await assertErrorsInCode(r'''
class A {
static m() {}
}
main(A a) {
a.m;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
]);
}

test_instanceAccessToStaticMember_propertyAccess_field() async {
await assertErrorsInCode(r'''
class A {
static var f;
}
main(A a) {
a.f;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
]);
}

test_instanceAccessToStaticMember_propertyAccess_getter() async {
await assertErrorsInCode(r'''
class A {
static get f => 42;
}
main(A a) {
a.f;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 50, 1),
]);
}

test_instanceAccessToStaticMember_propertyAccess_setter() async {
await assertErrorsInCode(r'''
class A {
static set f(x) {}
}
main(A a) {
a.f = 42;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 49, 1),
]);
}

test_invocationOfNonFunctionExpression_literal() async {
await assertErrorsInCode(r'''
f() {
3(5);
}
''', [
error(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 8, 1),
]);
}

test_nonTypeAsTypeArgument_notAType() async {
await assertErrorsInCode(r'''
int A;
class B<E> {}
f(B<A> b) {}
''', [
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 25, 1),
]);
}

test_nonTypeAsTypeArgument_undefinedIdentifier() async {
await assertErrorsInCode(r'''
class B<E> {}
f(B<A> b) {}
''', [
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 18, 1),
]);
}

test_typeParameterSupertypeOfItsBound_1of1() async {
await assertErrorsInCode(r'''
class A<T extends T> {
}
''', [
error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 11),
]);
}

test_typeParameterSupertypeOfItsBound_2of3() async {
await assertErrorsInCode(r'''
class A<T1 extends T3, T2, T3 extends T1> {
}
''', [
error(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 8, 13),
error(
StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, 27, 13),
]);
}
// TODO(srawlins) Figure out what to do with the rest of these tests.
// The names do not correspond to diagnostic codes, so it isn't clear what
// they're testing.

test_typePromotion_booleanAnd_useInRight_accessedInClosureRight_mutated() async {
await assertErrorsInCode(r'''
Expand Down Expand Up @@ -823,64 +696,6 @@ main(A<V> p) {
]);
}

test_unqualifiedReferenceToNonLocalStaticMember_getter() async {
await assertErrorsInCode(r'''
class A {
static int get a => 0;
}
class B extends A {
int b() {
return a;
}
}
''', [
error(
StaticTypeWarningCode
.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
80,
1),
]);
}

test_unqualifiedReferenceToNonLocalStaticMember_getter_invokeTarget() async {
await assertErrorsInCode(r'''
class A {
static int foo;
}
class B extends A {
static bar() {
foo.abs();
}
}
''', [
error(
StaticTypeWarningCode
.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
72,
3),
]);
}

test_unqualifiedReferenceToNonLocalStaticMember_setter() async {
await assertErrorsInCode(r'''
class A {
static set a(x) {}
}
class B extends A {
b(y) {
a = y;
}
}
''', [
error(
StaticTypeWarningCode
.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
66,
1),
]);
}

test_wrongNumberOfTypeArguments() async {
await assertErrorsInCode(r'''
class A<E> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,56 @@ f(C c) {
findElement.setter('a'),
);
}

test_method_reference() async {
await assertErrorsInCode(r'''
class A {
static m() {}
}
main(A a) {
a.m;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
]);
}

test_propertyAccess_field() async {
await assertErrorsInCode(r'''
class A {
static var f;
}
main(A a) {
a.f;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 44, 1),
]);
}

test_propertyAccess_getter() async {
await assertErrorsInCode(r'''
class A {
static get f => 42;
}
main(A a) {
a.f;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 50, 1),
]);
}

test_propertyAccess_setter() async {
await assertErrorsInCode(r'''
class A {
static set f(x) {}
}
main(A a) {
a.f = 42;
}
''', [
error(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, 49, 1),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../dart/resolution/driver_resolution.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(InvocationOfNonFunctionExpressionTest);
});
}

@reflectiveTest
class InvocationOfNonFunctionExpressionTest extends DriverResolutionTest {
test_invocationOfNonFunctionExpression_literal() async {
await assertErrorsInCode(r'''
f() {
3(5);
}
''', [
error(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 8, 1),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../dart/resolution/driver_resolution.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(NonTypeAsTypeArgumentTest);
});
}

@reflectiveTest
class NonTypeAsTypeArgumentTest extends DriverResolutionTest {
test_notAType() async {
await assertErrorsInCode(r'''
int A;
class B<E> {}
f(B<A> b) {}
''', [
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 25, 1),
]);
}

test_undefinedIdentifier() async {
await assertErrorsInCode(r'''
class B<E> {}
f(B<A> b) {}
''', [
error(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 18, 1),
]);
}
}
Loading

0 comments on commit 6e687d1

Please sign in to comment.