Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
test diagnostic cleanup (#2996)
Browse files Browse the repository at this point in the history
  • Loading branch information
pq authored Oct 4, 2021
1 parent 60b7402 commit aa8f12c
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 88 deletions.
7 changes: 7 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,36 @@ import 'avoid_function_literals_in_foreach_calls.dart'
import 'avoid_init_to_null.dart' as avoid_init_to_null;
import 'missing_whitespace_between_adjacent_strings.dart'
as missing_whitespace_between_adjacent_strings;
import 'null_closures.dart' as null_closures;
import 'overridden_fields.dart' as overridden_fields;
import 'prefer_asserts_in_initializer_lists.dart'
as prefer_asserts_in_initializer_lists;
import 'prefer_collection_literals.dart' as prefer_collection_literals;
import 'prefer_const_constructors.dart' as prefer_const_constructors;
import 'prefer_const_constructors_in_immutables.dart'
as prefer_const_constructors_in_immutables;
import 'prefer_const_literals_to_create_immutables.dart'
as prefer_const_literals_to_create_immutables;
import 'prefer_contains.dart' as prefer_contains;
import 'prefer_spread_collections.dart' as prefer_spread_collections;
import 'type_init_formals.dart' as type_init_formals;
import 'unawaited_futures.dart' as unawaited_futures;
import 'void_checks.dart' as void_checks;

void main() {
avoid_function_literals_in_foreach_calls.main();
avoid_init_to_null.main();
missing_whitespace_between_adjacent_strings.main();
null_closures.main();
overridden_fields.main();
prefer_asserts_in_initializer_lists.main();
prefer_collection_literals.main();
prefer_const_constructors.main();
prefer_const_constructors_in_immutables.main();
prefer_const_literals_to_create_immutables.main();
prefer_contains.main();
prefer_spread_collections.main();
type_init_formals.main();
unawaited_futures.main();
void_checks.main();
}
40 changes: 40 additions & 0 deletions test/rules/null_closures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2021, 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

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

@reflectiveTest
class NullClosuresTest extends LintRuleTest {
@override
String get lintRule => 'null_closures';

///https://github.com/dart-lang/linter/issues/1414
test_recursiveInterfaceInheritance() async {
await assertDiagnostics(r'''
class A extends B {
A(int x);
}
class B extends A {}
void test_cycle() {
A(null);
}
''', [
// No lint
error(CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 6, 1),
error(CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 41, 1),
error(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, 41, 1),
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 81, 4),
]);
}
}
50 changes: 50 additions & 0 deletions test/rules/prefer_const_literals_to_create_immutables.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2021, 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

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

@reflectiveTest
class PreferConstLiteralsToCreateImmutablesTest extends LintRuleTest {
@override
bool get addMetaPackageDep => true;

@override
String get lintRule => 'prefer_const_literals_to_create_immutables.dart';

test_missingRequiredArgument() async {
await assertDiagnostics(r'''
import 'package:meta/meta.dart';
@immutable
class K {
final List<K> children;
const K({required this.children});
}
final k = K(
children: <K>[for (var i = 0; i < 5; ++i) K()], // OK
);
''', [
// No lint
error(CompileTimeErrorCode.MISSING_REQUIRED_ARGUMENT, 178, 1),
]);
}

test_newWithNonType() async {
await assertDiagnostics(r'''
var e1 = new B([]); // OK
''', [
// No lint
error(CompileTimeErrorCode.NEW_WITH_NON_TYPE, 13, 1),
]);
}
}
31 changes: 31 additions & 0 deletions test/rules/unawaited_futures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2021, 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:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

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

@reflectiveTest
class UnawaitedFuturesTest extends LintRuleTest {
@override
String get lintRule => 'unawaited_futures';

test_undefinedIdentifier() async {
await assertDiagnostics(r'''
f() async {
Duration d = Duration();
Future.delayed(d, bar);
}
''', [
// No lint
error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 59, 3),
]);
}
}
10 changes: 0 additions & 10 deletions test_data/rules/experiments/nnbd/rules/null_closures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
import 'dart:async';
import 'dart:core';

class A extends B {
A(int x);
}
class B extends A {}

//https://github.com/dart-lang/linter/issues/1414
void test_cycle() {
new A(null);
}

void list_firstWhere() {
// firstWhere has a _named_ closure argument.
<int>[2, 4, 6].firstWhere((e) => e.isEven, orElse: null); // LINT
Expand Down
30 changes: 15 additions & 15 deletions test_data/rules/experiments/nnbd/rules/overridden_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Bad3 extends Object with Base {
}

class Ok extends Base {
Object newField; // OK
Object newField = 0; // OK

final Object newFinal = 'ignore'; // OK
}
Expand All @@ -36,7 +36,7 @@ class OK2 implements Base {
Object something = 'done'; // OK

@override
Object field;
Object field = 0;
}

abstract class OK3 implements Base {
Expand Down Expand Up @@ -121,7 +121,7 @@ class Sub1 extends Super1 {
}

class Super2 {
int x, y;
int x = 0, y = 0;
}

class Sub2 extends Super2 {
Expand All @@ -130,15 +130,15 @@ class Sub2 extends Super2 {
}

class Super3 {
int x;
int x = 0;
}

class Sub3 extends Super3 {
int x; // LINT
int x = 0; // LINT
}

class A1 {
int f;
int f = 0;
}

class B1 extends A1 {}
Expand All @@ -147,27 +147,27 @@ abstract class C1 implements A1 {}

class D1 extends B1 implements C1 {
@override
int f; // LINT
int f = 0; // LINT
}

class A extends B {}
class B extends A {
int field;
int field = 0;
}

class StaticsNo {
static int a;
static int a = 0;
}

class VerifyStatic extends StaticsNo {
static int a;
static int a = 0;
}

mixin M on A1 {
@override
int f; // LINT
int f = 0; // LINT

int g; // OK
int g = 0; // OK
}

abstract class BB {
Expand All @@ -177,12 +177,12 @@ abstract class BB {
class AA extends BB {
/// Overriding abstracts in NNBD is OK.
@override
String s; // OK
String s = ''; // OK
}

class AAA with BB {
@override
String s; // OK
String s = ''; // OK
}

abstract class BBB {
Expand All @@ -191,5 +191,5 @@ abstract class BBB {

class AAA extends BBB {
@override
String s; // OK
String s = ''; // OK
}
14 changes: 7 additions & 7 deletions test_data/rules/invariant_booleans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ int bar = 1;
int baz = 2;

int foo = 0;
bool setting;
bool setting = false;

class A {
bool foo;
int fooNumber;
bool foo = false;
int fooNumber = 0;
}

class B {
bool bar;
int barNumber;
bool bar = false;
int barNumber = 0;
}

A a = new A();
Expand Down Expand Up @@ -358,7 +358,7 @@ someFunction() {
}

class Foo {
bool bar;
bool bar = false;
void sayHello() {
if (bar ?? false) print('hello');
}
Expand Down Expand Up @@ -453,7 +453,7 @@ void test337_5() {
}

void bug658() {
String text;
String? text;
if ((text?.length ?? 0) != 0) {}
}

Expand Down
10 changes: 0 additions & 10 deletions test_data/rules/null_closures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
import 'dart:async';
import 'dart:core';

class A extends B {
A(int x);
}
class B extends A {}

//https://github.com/dart-lang/linter/issues/1414
void test_cycle() {
new A(null);
}

void list_firstWhere() {
// firstWhere has a _named_ closure argument.
<int>[2, 4, 6].firstWhere((e) => e.isEven, orElse: null); // LINT
Expand Down
12 changes: 0 additions & 12 deletions test_data/rules/prefer_const_literals_to_create_immutables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,7 @@ var m13 = new A({1: 1.0}); // LINT
var m14 = new A({1: ''}); // LINT
var m15 = new A({1: null}); // LINT

// ignore: undefined_class
var e1 = new B([]); // OK

// optional new
class C {}
var m16 = A([C()]); // OK

@immutable
class K {
final List<K> children;
const K({this.children});
}

final k = K(
children: <K>[for (var i = 0; i < 5; ++i) K()], // OK
);
Loading

0 comments on commit aa8f12c

Please sign in to comment.