Skip to content

Commit

Permalink
Privatize some elements in LintRuleTest
Browse files Browse the repository at this point in the history
* `assertDiagnosticsIn` can always be replaced by the simpler
  `assertDiagnosticsInFile`, which makes tests simpler. Then
  `assertDiagnosticsIn` can be made private.
* `assertNoDiagnosticsIn` can always be replaced by the simpler
  `assertNoDiagnosticsInFile`, which makes tests simpler. Then
  `assertNoDiagnosticsIn` can be removed.
* Then the `errors` getter can be made private.
* Privatize the `ExpectedError` and `ExpectedLint` classes, as they are
  not meant to be consumed. Also make them final.
* Move `findElement`, `findElement2`, and `findNode` to `scope_util_test.dart`.
* Remove the public `lintRules` getter.

Change-Id: Ie994745b06268a449a1b5613bfdcfa4785335d7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391684
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and Commit Queue committed Oct 24, 2024
1 parent c0126fc commit de058e0
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 379 deletions.
308 changes: 144 additions & 164 deletions pkg/linter/test/rule_test_support.dart

Large diffs are not rendered by default.

35 changes: 10 additions & 25 deletions pkg/linter/test/rules/always_declare_return_types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
await assertNoDiagnosticsInFile(a.path);
await assertDiagnosticsInFile(b.path, [
lint(39, 1),
]);
}
Expand All @@ -52,11 +49,8 @@ part of 'a.dart';
f() { }
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
await assertNoDiagnosticsInFile(a.path);
await assertDiagnosticsInFile(b.path, [
lint(19, 1),
]);
}
Expand All @@ -80,13 +74,10 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(28, 1),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentedTopLevelFunction() async {
Expand All @@ -102,13 +93,10 @@ part of 'a.dart';
augment f() { }
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(16, 1),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentedTopLevelFunction_chain() async {
Expand All @@ -125,13 +113,10 @@ augment dynamic f() { }
augment f() { }
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(16, 1),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_extensionMethod() async {
Expand Down
3 changes: 1 addition & 2 deletions pkg/linter/test/rules/always_use_package_imports_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class C {}
import 'package:test/lib.dart';
''');
await resolveTestFile();
var result = await resolveFile(bin.path);
await assertNoDiagnosticsIn(result.errors);
await assertNoDiagnosticsInFile(bin.path);
}

test_samePackage_packageSchema_inPart() async {
Expand Down
7 changes: 2 additions & 5 deletions pkg/linter/test/rules/annotate_overrides_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ augment class C implements HasLength {
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(a.path);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentationClass_methodWithoutAnnotation() async {
Expand Down
42 changes: 12 additions & 30 deletions pkg/linter/test/rules/avoid_annotating_with_dynamic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
await assertNoDiagnosticsInFile(a.path);
await assertDiagnosticsInFile(b.path, [
lint(46, 9),
]);
}
Expand All @@ -52,11 +49,8 @@ part of 'a.dart';
void f(dynamic o) { }
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
await assertNoDiagnosticsInFile(a.path);
await assertDiagnosticsInFile(b.path, [
lint(26, 9),
]);
}
Expand All @@ -77,11 +71,8 @@ augment void f(int i) {
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
await assertNoDiagnosticsInFile(a.path);
await assertDiagnosticsInFile(b.path, [
lint(54, 9),
]);
}
Expand All @@ -103,13 +94,10 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(35, 9),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentedTopLevelFunction() async {
Expand All @@ -125,13 +113,10 @@ part of 'a.dart';
augment void f(dynamic o) { }
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(23, 9),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentedTopLevelFunction_multiple() async {
Expand All @@ -148,13 +133,10 @@ augment void f(dynamic o) { }
augment void f(dynamic o) { }
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(23, 9),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

// TODO(srawlins): Test parameter of function-typed typedef (both old and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(a.path);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentationClass_staticField() async {
Expand All @@ -57,13 +54,11 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(16, 10),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentationClass_staticMethod() async {
Expand All @@ -81,13 +76,11 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
await assertDiagnosticsInFile(a.path, [
lint(16, 10),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_basicClass() async {
Expand Down Expand Up @@ -119,11 +112,9 @@ part of 'a.dart';
augment class A {}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(a.path);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(b.path);
}

test_class_extendingValidClass() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ augment class A {
augment class A { }
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(a.path);
await assertNoDiagnosticsInFile(b.path);
}

test_mutableClass() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ augment class A {
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
await assertNoDiagnosticsInFile(a.path);
await assertNoDiagnosticsInFile(b.path);
}

test_augmentedClass_augmentedConstructor() async {
Expand Down
6 changes: 2 additions & 4 deletions pkg/linter/test/rules/avoid_relative_lib_imports_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class C {}
/// This provides [C].
import '../lib/lib.dart';
''');
var lib2Result = await resolveFile(test.path);
await assertDiagnosticsIn(lib2Result.errors, [
await assertDiagnosticsInFile(test.path, [
lint(30, 17),
]);
}
Expand All @@ -56,8 +55,7 @@ part of 'a.dart';
/// This provides [C].
import '../lib/lib.dart';
''');
var lib2Result = await resolveFile(test.path);
await assertDiagnosticsIn(lib2Result.errors, [
await assertDiagnosticsInFile(test.path, [
lint(49, 17),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ class B extends A {
void m(int q) {}
}
''');
var result = await resolveFile(lib.path);
await assertNoDiagnosticsIn(result.errors);
await assertNoDiagnosticsInFile(lib.path);
}

test_positional_sameName() async {
Expand Down
15 changes: 5 additions & 10 deletions pkg/linter/test/rules/avoid_web_libraries_in_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ environment:
// ignore: unused_import
import 'dart:html';
''');
result = await resolveFile(mainFile.path);
await assertNoDiagnosticsIn(result.errors);
await assertNoDiagnosticsInFile(mainFile.path);
}

test_nonWebApp() async {
Expand All @@ -68,8 +67,7 @@ flutter:
// ignore: unused_import
import 'dart:html';
''');
result = await resolveFile(mainFile.path);
await assertDiagnosticsIn(result.errors, [
await assertDiagnosticsInFile(mainFile.path, [
lint(25, 19),
]);
}
Expand All @@ -79,8 +77,7 @@ import 'dart:html';
// ignore: unused_import
import 'dart:html';
''');
result = await resolveFile(mainFile.path);
await assertNoDiagnosticsIn(result.errors);
await assertNoDiagnosticsInFile(mainFile.path);
}

test_webApp() async {
Expand Down Expand Up @@ -108,8 +105,7 @@ flutter:
import 'dart:html';
''');
newFile('$testPackageRootPath/web/README', 'Placeholder.');
result = await resolveFile(mainFile.path);
await assertDiagnosticsIn(result.errors, [
await assertDiagnosticsInFile(mainFile.path, [
// Even in a package with a `web/` directory, do not use web libraries.
// Note(srawlins): This seems weird to me, but this is the expectation
// from the previous version of this test.
Expand Down Expand Up @@ -145,7 +141,6 @@ flutter:
// ignore: unused_import
import 'dart:html';
''');
result = await resolveFile(mainFile.path);
await assertNoDiagnosticsIn(result.errors);
await assertNoDiagnosticsInFile(mainFile.path);
}
}
Loading

0 comments on commit de058e0

Please sign in to comment.