Skip to content

Commit de058e0

Browse files
srawlinsCommit Queue
authored andcommitted
Privatize some elements in LintRuleTest
* `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 <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent c0126fc commit de058e0

23 files changed

+256
-379
lines changed

pkg/linter/test/rule_test_support.dart

Lines changed: 144 additions & 164 deletions
Large diffs are not rendered by default.

pkg/linter/test/rules/always_declare_return_types_test.dart

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ augment class A {
3232
}
3333
''');
3434

35-
result = await resolveFile(a.path);
36-
await assertNoDiagnosticsIn(errors);
37-
38-
result = await resolveFile(b.path);
39-
await assertDiagnosticsIn(errors, [
35+
await assertNoDiagnosticsInFile(a.path);
36+
await assertDiagnosticsInFile(b.path, [
4037
lint(39, 1),
4138
]);
4239
}
@@ -52,11 +49,8 @@ part of 'a.dart';
5249
f() { }
5350
''');
5451

55-
result = await resolveFile(a.path);
56-
await assertNoDiagnosticsIn(errors);
57-
58-
result = await resolveFile(b.path);
59-
await assertDiagnosticsIn(errors, [
52+
await assertNoDiagnosticsInFile(a.path);
53+
await assertDiagnosticsInFile(b.path, [
6054
lint(19, 1),
6155
]);
6256
}
@@ -80,13 +74,10 @@ augment class A {
8074
}
8175
''');
8276

83-
result = await resolveFile(a.path);
84-
await assertDiagnosticsIn(errors, [
77+
await assertDiagnosticsInFile(a.path, [
8578
lint(28, 1),
8679
]);
87-
88-
result = await resolveFile(b.path);
89-
await assertNoDiagnosticsIn(errors);
80+
await assertNoDiagnosticsInFile(b.path);
9081
}
9182

9283
test_augmentedTopLevelFunction() async {
@@ -102,13 +93,10 @@ part of 'a.dart';
10293
augment f() { }
10394
''');
10495

105-
result = await resolveFile(a.path);
106-
await assertDiagnosticsIn(errors, [
96+
await assertDiagnosticsInFile(a.path, [
10797
lint(16, 1),
10898
]);
109-
110-
result = await resolveFile(b.path);
111-
await assertNoDiagnosticsIn(errors);
99+
await assertNoDiagnosticsInFile(b.path);
112100
}
113101

114102
test_augmentedTopLevelFunction_chain() async {
@@ -125,13 +113,10 @@ augment dynamic f() { }
125113
augment f() { }
126114
''');
127115

128-
result = await resolveFile(a.path);
129-
await assertDiagnosticsIn(errors, [
116+
await assertDiagnosticsInFile(a.path, [
130117
lint(16, 1),
131118
]);
132-
133-
result = await resolveFile(b.path);
134-
await assertNoDiagnosticsIn(errors);
119+
await assertNoDiagnosticsInFile(b.path);
135120
}
136121

137122
test_extensionMethod() async {

pkg/linter/test/rules/always_use_package_imports_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class C {}
5353
import 'package:test/lib.dart';
5454
''');
5555
await resolveTestFile();
56-
var result = await resolveFile(bin.path);
57-
await assertNoDiagnosticsIn(result.errors);
56+
await assertNoDiagnosticsInFile(bin.path);
5857
}
5958

6059
test_samePackage_packageSchema_inPart() async {

pkg/linter/test/rules/annotate_overrides_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ augment class C implements HasLength {
4040
}
4141
''');
4242

43-
result = await resolveFile(a.path);
44-
await assertNoDiagnosticsIn(errors);
45-
46-
result = await resolveFile(b.path);
47-
await assertNoDiagnosticsIn(errors);
43+
await assertNoDiagnosticsInFile(a.path);
44+
await assertNoDiagnosticsInFile(b.path);
4845
}
4946

5047
test_augmentationClass_methodWithoutAnnotation() async {

pkg/linter/test/rules/avoid_annotating_with_dynamic_test.dart

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ augment class A {
3232
}
3333
''');
3434

35-
result = await resolveFile(a.path);
36-
await assertNoDiagnosticsIn(errors);
37-
38-
result = await resolveFile(b.path);
39-
await assertDiagnosticsIn(errors, [
35+
await assertNoDiagnosticsInFile(a.path);
36+
await assertDiagnosticsInFile(b.path, [
4037
lint(46, 9),
4138
]);
4239
}
@@ -52,11 +49,8 @@ part of 'a.dart';
5249
void f(dynamic o) { }
5350
''');
5451

55-
result = await resolveFile(a.path);
56-
await assertNoDiagnosticsIn(errors);
57-
58-
result = await resolveFile(b.path);
59-
await assertDiagnosticsIn(errors, [
52+
await assertNoDiagnosticsInFile(a.path);
53+
await assertDiagnosticsInFile(b.path, [
6054
lint(26, 9),
6155
]);
6256
}
@@ -77,11 +71,8 @@ augment void f(int i) {
7771
}
7872
''');
7973

80-
result = await resolveFile(a.path);
81-
await assertNoDiagnosticsIn(errors);
82-
83-
result = await resolveFile(b.path);
84-
await assertDiagnosticsIn(errors, [
74+
await assertNoDiagnosticsInFile(a.path);
75+
await assertDiagnosticsInFile(b.path, [
8576
lint(54, 9),
8677
]);
8778
}
@@ -103,13 +94,10 @@ augment class A {
10394
}
10495
''');
10596

106-
result = await resolveFile(a.path);
107-
await assertDiagnosticsIn(errors, [
97+
await assertDiagnosticsInFile(a.path, [
10898
lint(35, 9),
10999
]);
110-
111-
result = await resolveFile(b.path);
112-
await assertNoDiagnosticsIn(errors);
100+
await assertNoDiagnosticsInFile(b.path);
113101
}
114102

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

128-
result = await resolveFile(a.path);
129-
await assertDiagnosticsIn(errors, [
116+
await assertDiagnosticsInFile(a.path, [
130117
lint(23, 9),
131118
]);
132-
133-
result = await resolveFile(b.path);
134-
await assertNoDiagnosticsIn(errors);
119+
await assertNoDiagnosticsInFile(b.path);
135120
}
136121

137122
test_augmentedTopLevelFunction_multiple() async {
@@ -148,13 +133,10 @@ augment void f(dynamic o) { }
148133
augment void f(dynamic o) { }
149134
''');
150135

151-
result = await resolveFile(a.path);
152-
await assertDiagnosticsIn(errors, [
136+
await assertDiagnosticsInFile(a.path, [
153137
lint(23, 9),
154138
]);
155-
156-
result = await resolveFile(b.path);
157-
await assertNoDiagnosticsIn(errors);
139+
await assertNoDiagnosticsInFile(b.path);
158140
}
159141

160142
// TODO(srawlins): Test parameter of function-typed typedef (both old and

pkg/linter/test/rules/avoid_classes_with_only_static_members_test.dart

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ augment class A {
3535
}
3636
''');
3737

38-
result = await resolveFile(a.path);
39-
await assertNoDiagnosticsIn(errors);
40-
41-
result = await resolveFile(b.path);
42-
await assertNoDiagnosticsIn(errors);
38+
await assertNoDiagnosticsInFile(a.path);
39+
await assertNoDiagnosticsInFile(b.path);
4340
}
4441

4542
test_augmentationClass_staticField() async {
@@ -57,13 +54,11 @@ augment class A {
5754
}
5855
''');
5956

60-
result = await resolveFile(a.path);
61-
await assertDiagnosticsIn(errors, [
57+
await assertDiagnosticsInFile(a.path, [
6258
lint(16, 10),
6359
]);
6460

65-
result = await resolveFile(b.path);
66-
await assertNoDiagnosticsIn(errors);
61+
await assertNoDiagnosticsInFile(b.path);
6762
}
6863

6964
test_augmentationClass_staticMethod() async {
@@ -81,13 +76,11 @@ augment class A {
8176
}
8277
''');
8378

84-
result = await resolveFile(a.path);
85-
await assertDiagnosticsIn(errors, [
79+
await assertDiagnosticsInFile(a.path, [
8680
lint(16, 10),
8781
]);
8882

89-
result = await resolveFile(b.path);
90-
await assertNoDiagnosticsIn(errors);
83+
await assertNoDiagnosticsInFile(b.path);
9184
}
9285

9386
test_basicClass() async {
@@ -119,11 +112,9 @@ part of 'a.dart';
119112
augment class A {}
120113
''');
121114

122-
result = await resolveFile(a.path);
123-
await assertNoDiagnosticsIn(errors);
115+
await assertNoDiagnosticsInFile(a.path);
124116

125-
result = await resolveFile(b.path);
126-
await assertNoDiagnosticsIn(errors);
117+
await assertNoDiagnosticsInFile(b.path);
127118
}
128119

129120
test_class_extendingValidClass() async {

pkg/linter/test/rules/avoid_equals_and_hash_code_on_mutable_classes_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ augment class A {
7878
augment class A { }
7979
''');
8080

81-
result = await resolveFile(a.path);
82-
await assertNoDiagnosticsIn(errors);
83-
84-
result = await resolveFile(b.path);
85-
await assertNoDiagnosticsIn(errors);
81+
await assertNoDiagnosticsInFile(a.path);
82+
await assertNoDiagnosticsInFile(b.path);
8683
}
8784

8885
test_mutableClass() async {

pkg/linter/test/rules/avoid_field_initializers_in_non_const_classes_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ augment class A {
3535
}
3636
''');
3737

38-
result = await resolveFile(a.path);
39-
await assertNoDiagnosticsIn(errors);
40-
41-
result = await resolveFile(b.path);
42-
await assertNoDiagnosticsIn(errors);
38+
await assertNoDiagnosticsInFile(a.path);
39+
await assertNoDiagnosticsInFile(b.path);
4340
}
4441

4542
test_augmentedClass_augmentedConstructor() async {

pkg/linter/test/rules/avoid_relative_lib_imports_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class C {}
3535
/// This provides [C].
3636
import '../lib/lib.dart';
3737
''');
38-
var lib2Result = await resolveFile(test.path);
39-
await assertDiagnosticsIn(lib2Result.errors, [
38+
await assertDiagnosticsInFile(test.path, [
4039
lint(30, 17),
4140
]);
4241
}
@@ -56,8 +55,7 @@ part of 'a.dart';
5655
/// This provides [C].
5756
import '../lib/lib.dart';
5857
''');
59-
var lib2Result = await resolveFile(test.path);
60-
await assertDiagnosticsIn(lib2Result.errors, [
58+
await assertDiagnosticsInFile(test.path, [
6159
lint(49, 17),
6260
]);
6361
}

pkg/linter/test/rules/avoid_renaming_method_parameters_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ class B extends A {
141141
void m(int q) {}
142142
}
143143
''');
144-
var result = await resolveFile(lib.path);
145-
await assertNoDiagnosticsIn(result.errors);
144+
await assertNoDiagnosticsInFile(lib.path);
146145
}
147146

148147
test_positional_sameName() async {

0 commit comments

Comments
 (0)