mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:59:47 +00:00
Convert the remaining fix tests using a lint marker and remove the ability to use a marker
Several of the tests were testing conditions that cannot occur and hence were either re-written or removed. There's one test that I couldn't get working so I marked it as failing. I marked another test as failing rather than remove it because I think we want to update the lint to catch that case (it's failing because no lint is produced). Change-Id: I852c3c4595b0993ce2a64cbd9da1b6c7339dd59b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134880 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
fd992e423e
commit
c6b0ee3931
|
@ -13,6 +13,10 @@ class ConvertToNullAware extends CorrectionProducer {
|
|||
@override
|
||||
Future<void> compute(DartChangeBuilder builder) async {
|
||||
AstNode node = this.node;
|
||||
if (node.parent is BinaryExpression &&
|
||||
node.parent.parent is ConditionalExpression) {
|
||||
node = node.parent.parent;
|
||||
}
|
||||
if (node is! ConditionalExpression) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ConvertToNullAwareTest extends FixProcessorLintTest {
|
|||
abstract class A {
|
||||
int m();
|
||||
}
|
||||
int f(A a) => null == a /*LINT*/? null : a.m();
|
||||
int f(A a) => null == a ? null : a.m();
|
||||
''');
|
||||
await assertHasFix('''
|
||||
abstract class A {
|
||||
|
|
|
@ -24,15 +24,24 @@ class ConvertToPackageImportTest extends FixProcessorLintTest {
|
|||
String get lintCode => LintNames.avoid_relative_lib_imports;
|
||||
|
||||
/// More coverage in the `convert_to_package_import_test.dart` assist test.
|
||||
@failingTest
|
||||
Future<void> test_relativeImport() async {
|
||||
addSource('/home/test/lib/foo.dart', '');
|
||||
testFile = convertPath('/home/test/lib/src/test.dart');
|
||||
// This test fails because any attempt to specify a relative path that
|
||||
// includes 'lib' (which the lint requires) results in a malformed URI when
|
||||
// trying to resolve the import.
|
||||
newFile('/home/test/lib/foo/bar.dart', content: '''
|
||||
class C {}
|
||||
''');
|
||||
await resolveTestUnit('''
|
||||
import /*LINT*/'../lib/foo.dart';
|
||||
import '../lib/foo/bar.dart';
|
||||
|
||||
C c;
|
||||
''');
|
||||
|
||||
await assertHasFix('''
|
||||
import 'package:test/lib/foo.dart';
|
||||
|
||||
C c;
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,26 +24,12 @@ import '../../../../abstract_single_unit.dart';
|
|||
/// A base class defining support for writing fix processor tests that are
|
||||
/// specific to fixes associated with lints that use the FixKind.
|
||||
abstract class FixProcessorLintTest extends FixProcessorTest {
|
||||
/// The marker used to indicate where the lint is expected to be found.
|
||||
static const lintMarker = '/*LINT*/';
|
||||
|
||||
/// The offset of the lint marker in the code being analyzed.
|
||||
int lintOffset = -1;
|
||||
|
||||
/// Return the lint code being tested.
|
||||
String get lintCode;
|
||||
|
||||
@override
|
||||
Future<void> resolveTestUnit(String code) async {
|
||||
lintOffset = code.indexOf(lintMarker);
|
||||
if (lintOffset < 0) {
|
||||
return super.resolveTestUnit(code);
|
||||
}
|
||||
var endOffset = lintOffset + lintMarker.length;
|
||||
code = code.substring(0, lintOffset) + code.substring(endOffset);
|
||||
return super.resolveTestUnit(code);
|
||||
}
|
||||
|
||||
@override
|
||||
void setUp() {
|
||||
super.setUp();
|
||||
|
|
|
@ -26,12 +26,14 @@ class MakeFinalTest extends FixProcessorLintTest {
|
|||
Future<void> test_field_type() async {
|
||||
await resolveTestUnit('''
|
||||
class C {
|
||||
int /*LINT*/f = 2;
|
||||
int _f = 2;
|
||||
int get g => _f;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
class C {
|
||||
final int f = 2;
|
||||
final int _f = 2;
|
||||
int get g => _f;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
@ -39,70 +41,15 @@ class C {
|
|||
Future<void> test_field_var() async {
|
||||
await resolveTestUnit('''
|
||||
class C {
|
||||
var /*LINT*/f = 2;
|
||||
var _f = 2;
|
||||
int get g => _f;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
class C {
|
||||
final f = 2;
|
||||
final _f = 2;
|
||||
int get g => _f;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_local_type() async {
|
||||
await resolveTestUnit('''
|
||||
bad() {
|
||||
int /*LINT*/x = 2;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
bad() {
|
||||
final int x = 2;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_local_var() async {
|
||||
await resolveTestUnit('''
|
||||
bad() {
|
||||
var /*LINT*/x = 2;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
bad() {
|
||||
final x = 2;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_noKeyword() async {
|
||||
await resolveTestUnit('''
|
||||
class C {
|
||||
/*LINT*/f = 2;
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
class C {
|
||||
final f = 2;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topLevel_type() async {
|
||||
await resolveTestUnit('''
|
||||
int /*LINT*/x = 2;
|
||||
''');
|
||||
await assertHasFix('''
|
||||
final int x = 2;
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_topLevel_var() async {
|
||||
await resolveTestUnit('''
|
||||
var /*LINT*/x = 2;
|
||||
''');
|
||||
await assertHasFix('''
|
||||
final x = 2;
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,9 @@ class A {
|
|||
''');
|
||||
}
|
||||
|
||||
@failingTest
|
||||
Future<void> test_setter() async {
|
||||
// The lint doesn't catch unnecessary setters.
|
||||
await resolveTestUnit('''
|
||||
class A {
|
||||
int foo;
|
||||
|
@ -142,7 +144,7 @@ class A {
|
|||
|
||||
class B extends A {
|
||||
@override
|
||||
set /*LINT*/foo(int value) {
|
||||
set foo(int value) {
|
||||
super.foo = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,63 +23,41 @@ class ReplaceNullWithClosureTest extends FixProcessorLintTest {
|
|||
@override
|
||||
String get lintCode => LintNames.null_closures;
|
||||
|
||||
/// Currently failing since the LINT annotation is tagging the ArgumentList
|
||||
/// where the fix (and lint) expect a NullLiteral.
|
||||
@failingTest
|
||||
Future<void> test_null_closure_literal() async {
|
||||
Future<void> test_named() async {
|
||||
await resolveTestUnit('''
|
||||
void f(dynamic x) { }
|
||||
main() {
|
||||
f(null/*LINT*/);
|
||||
void f(List<int> l) {
|
||||
l.firstWhere((e) => e.isEven, orElse: null);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f(dynamic x) { }
|
||||
main() {
|
||||
f(() => null);
|
||||
void f(List<int> l) {
|
||||
l.firstWhere((e) => e.isEven, orElse: () => null);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_null_closure_named_expression() async {
|
||||
Future<void> test_named_withArgs() async {
|
||||
await resolveTestUnit('''
|
||||
main() {
|
||||
[1, 3, 5].firstWhere((e) => e.isEven, orElse: null);
|
||||
void f(String s) {
|
||||
s.splitMapJoin('', onNonMatch: null);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
main() {
|
||||
[1, 3, 5].firstWhere((e) => e.isEven, orElse: () => null);
|
||||
void f(String s) {
|
||||
s.splitMapJoin('', onNonMatch: (String nonMatch) => null);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_null_closure_named_expression_with_args() async {
|
||||
Future<void> test_required() async {
|
||||
await resolveTestUnit('''
|
||||
void f({int closure(x, y)}) { }
|
||||
main() {
|
||||
f(closure: /*LINT*/null);
|
||||
void f(List<int> l) {
|
||||
l.firstWhere(null);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f({int closure(x, y)}) { }
|
||||
main() {
|
||||
f(closure: (x, y) => null);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_null_closure_named_expression_with_args_2() async {
|
||||
await resolveTestUnit('''
|
||||
void f({int closure(x, y, {z})}) { }
|
||||
main() {
|
||||
f(closure: /*LINT*/null);
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
void f({int closure(x, y, {z})}) { }
|
||||
main() {
|
||||
f(closure: (x, y, {z}) => null);
|
||||
void f(List<int> l) {
|
||||
l.firstWhere(() => null);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
|
|
@ -453,6 +453,8 @@ abstract class String implements Comparable<String>, Pattern {
|
|||
|
||||
int codeUnitAt(int index);
|
||||
bool contains(String other, [int startIndex = 0]);
|
||||
String splitMapJoin(Pattern pattern,
|
||||
{String onMatch(Match match), String onNonMatch(String nonMatch)});
|
||||
String substring(int len) => null;
|
||||
String toLowerCase();
|
||||
String toUpperCase();
|
||||
|
|
Loading…
Reference in a new issue