2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'dart:io' ;
5
+ import 'dart:io' show Platform ;
6
6
7
7
import 'package:analysis_server/protocol/protocol_generated.dart' ;
8
- import 'package:analysis_server/src/edit/edit_domain.dart' ;
9
8
import 'package:analysis_server/src/services/linter/lint_names.dart' ;
9
+ import 'package:analyzer/file_system/file_system.dart' ;
10
10
import 'package:analyzer_plugin/protocol/protocol_common.dart' ;
11
11
import 'package:linter/src/rules.dart' ;
12
12
import 'package:test/test.dart' ;
13
13
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
14
14
15
- import '../analysis_abstract .dart' ;
15
+ import '../analysis_server_base .dart' ;
16
16
17
17
void main () {
18
18
defineReflectiveSuite (() {
@@ -21,7 +21,7 @@ void main() {
21
21
}
22
22
23
23
@reflectiveTest
24
- class BulkFixesTest extends AbstractAnalysisTest {
24
+ class BulkFixesTest extends PubPackageAnalysisServerTest {
25
25
void assertContains (List <BulkFix > details,
26
26
{required String path, required String code, required int count}) {
27
27
for (var detail in details) {
@@ -37,11 +37,12 @@ class BulkFixesTest extends AbstractAnalysisTest {
37
37
fail ('No match found for: $path :$code ->$count in $details ' );
38
38
}
39
39
40
- Future <void > assertEditEquals (String expectedSource) async {
40
+ Future <void > assertEditEquals (File file, String expectedSource) async {
41
41
await waitForTasksFinished ();
42
42
var edits = await _getBulkEdits ();
43
43
expect (edits, hasLength (1 ));
44
- var editedSource = SourceEdit .applySequence (testCode, edits[0 ].edits);
44
+ var editedSource =
45
+ SourceEdit .applySequence (file.readAsStringSync (), edits[0 ].edits);
45
46
expect (editedSource, expectedSource);
46
47
}
47
48
@@ -55,12 +56,11 @@ class BulkFixesTest extends AbstractAnalysisTest {
55
56
Future <void > setUp () async {
56
57
super .setUp ();
57
58
registerLintRules ();
58
- handler = EditDomainHandler (server);
59
- await createProject ();
59
+ await setRoots (included: [workspaceRootPath], excluded: []);
60
60
}
61
61
62
62
Future <void > test_annotateOverrides_excludedFile () async {
63
- newAnalysisOptionsYamlFile2 (projectPath , '''
63
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
64
64
analyzer:
65
65
exclude:
66
66
- test/**
@@ -69,7 +69,7 @@ linter:
69
69
- annotate_overrides
70
70
''' );
71
71
72
- newFile2 ('$projectPath /test/test.dart' , '''
72
+ newFile2 ('$testPackageRootPath /test/test.dart' , '''
73
73
class A {
74
74
void f() {}
75
75
}
@@ -83,14 +83,14 @@ class B extends A {
83
83
84
84
Future <void > test_annotateOverrides_excludedSubProject () async {
85
85
// Root project.
86
- newAnalysisOptionsYamlFile2 (projectPath , '''
86
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
87
87
analyzer:
88
88
exclude:
89
89
- test/data/**
90
90
''' );
91
91
92
92
// Sub-project.
93
- var subprojectRoot = '$projectPath /test/data/subproject' ;
93
+ var subprojectRoot = '$testPackageRootPath /test/data/subproject' ;
94
94
newAnalysisOptionsYamlFile2 (subprojectRoot, '''
95
95
linter:
96
96
rules:
@@ -114,7 +114,7 @@ class B extends A {
114
114
}
115
115
116
116
Future <void > test_annotateOverrides_subProject () async {
117
- var subprojectRoot = '$projectPath /test/data/subproject' ;
117
+ var subprojectRoot = '$testPackageRootPath /test/data/subproject' ;
118
118
newAnalysisOptionsYamlFile2 (subprojectRoot, '''
119
119
linter:
120
120
rules:
@@ -125,8 +125,7 @@ linter:
125
125
name: subproject
126
126
''' );
127
127
128
- testFile = '$subprojectRoot /test.dart' ;
129
- addTestFile ('''
128
+ var file = newFile2 ('$subprojectRoot /test.dart' , '''
130
129
class A {
131
130
void f() {}
132
131
}
@@ -135,7 +134,9 @@ class B extends A {
135
134
}
136
135
''' );
137
136
138
- await assertEditEquals ('''
137
+ await waitForTasksFinished ();
138
+
139
+ await assertEditEquals (file, '''
139
140
class A {
140
141
void f() {}
141
142
}
@@ -147,15 +148,14 @@ class B extends A {
147
148
}
148
149
149
150
Future <void > test_details () async {
150
- newAnalysisOptionsYamlFile2 (projectPath , '''
151
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
151
152
linter:
152
153
rules:
153
154
- annotate_overrides
154
155
- unnecessary_new
155
156
''' );
156
157
157
- var fileA = convertPath ('$projectPath /a.dart' );
158
- newFile2 (fileA, '''
158
+ var a = newFile2 ('$testPackageLibPath /a.dart' , '''
159
159
class A {
160
160
A f() => new A();
161
161
}
@@ -173,15 +173,15 @@ A f() => new A();
173
173
var details = await _getBulkFixDetails ();
174
174
expect (details, hasLength (2 ));
175
175
assertContains (details,
176
- path: fileA , code: LintNames .unnecessary_new, count: 2 );
176
+ path: a.path , code: LintNames .unnecessary_new, count: 2 );
177
177
assertContains (details,
178
- path: fileA , code: LintNames .annotate_overrides, count: 1 );
178
+ path: a.path , code: LintNames .annotate_overrides, count: 1 );
179
179
assertContains (details,
180
- path: testFile, code: LintNames .unnecessary_new, count: 1 );
180
+ path: testFile.path , code: LintNames .unnecessary_new, count: 1 );
181
181
}
182
182
183
183
Future <void > test_unnecessaryNew () async {
184
- newAnalysisOptionsYamlFile2 (projectPath , '''
184
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
185
185
linter:
186
186
rules:
187
187
- unnecessary_new
@@ -191,21 +191,20 @@ class A {}
191
191
A f() => new A();
192
192
''' );
193
193
194
- await assertEditEquals ('''
194
+ await assertEditEquals (testFile, '''
195
195
class A {}
196
196
A f() => A();
197
197
''' );
198
198
}
199
199
200
- @FailingTest (issue: 'https://github.com/dart-lang/sdk/issues/44080' )
201
200
Future <void > test_unnecessaryNew_collectionLiteral_overlap () async {
202
201
// The test case currently drops the 'new' but does not convert the code to
203
202
// use a set literal. The code is no longer mangled, but we need to run the
204
203
// BulkFixProcessor iteratively to solve the second case.
205
204
if (Platform .isWindows) {
206
205
fail ('Should not be passing on Windows, but it does' );
207
206
}
208
- newAnalysisOptionsYamlFile2 (projectPath , '''
207
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
209
208
linter:
210
209
rules:
211
210
- prefer_collection_literals
@@ -219,7 +218,7 @@ class A {
219
218
}
220
219
''' );
221
220
222
- await assertEditEquals ('''
221
+ await assertEditEquals (testFile, '''
223
222
class A {
224
223
Map<String, Object> _map = {};
225
224
Set<String> _set = <String>{};
@@ -228,7 +227,7 @@ class A {
228
227
}
229
228
230
229
Future <void > test_unnecessaryNew_ignoredInOptions () async {
231
- newAnalysisOptionsYamlFile2 (projectPath , '''
230
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
232
231
analyzer:
233
232
errors:
234
233
unnecessary_new: ignore
@@ -244,7 +243,7 @@ A f() => new A();
244
243
}
245
244
246
245
Future <void > test_unnecessaryNew_ignoredInSource () async {
247
- newAnalysisOptionsYamlFile2 (projectPath , '''
246
+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
248
247
linter:
249
248
rules:
250
249
- unnecessary_new
@@ -268,8 +267,8 @@ A f() => new A();
268
267
}
269
268
270
269
Future <EditBulkFixesResult > _getBulkFixes () async {
271
- var request = EditBulkFixesParams ([projectPath ]).toRequest ('0' );
272
- var response = await waitResponse (request);
270
+ var request = EditBulkFixesParams ([workspaceRootPath ]).toRequest ('0' );
271
+ var response = await handleSuccessfulRequest (request);
273
272
return EditBulkFixesResult .fromResponse (response);
274
273
}
275
274
}
0 commit comments