22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- import 'dart:io' ;
5+ import 'dart:io' show Platform ;
66
77import 'package:analysis_server/protocol/protocol_generated.dart' ;
8- import 'package:analysis_server/src/edit/edit_domain.dart' ;
98import 'package:analysis_server/src/services/linter/lint_names.dart' ;
9+ import 'package:analyzer/file_system/file_system.dart' ;
1010import 'package:analyzer_plugin/protocol/protocol_common.dart' ;
1111import 'package:linter/src/rules.dart' ;
1212import 'package:test/test.dart' ;
1313import 'package:test_reflective_loader/test_reflective_loader.dart' ;
1414
15- import '../analysis_abstract .dart' ;
15+ import '../analysis_server_base .dart' ;
1616
1717void main () {
1818 defineReflectiveSuite (() {
@@ -21,7 +21,7 @@ void main() {
2121}
2222
2323@reflectiveTest
24- class BulkFixesTest extends AbstractAnalysisTest {
24+ class BulkFixesTest extends PubPackageAnalysisServerTest {
2525 void assertContains (List <BulkFix > details,
2626 {required String path, required String code, required int count}) {
2727 for (var detail in details) {
@@ -37,11 +37,12 @@ class BulkFixesTest extends AbstractAnalysisTest {
3737 fail ('No match found for: $path :$code ->$count in $details ' );
3838 }
3939
40- Future <void > assertEditEquals (String expectedSource) async {
40+ Future <void > assertEditEquals (File file, String expectedSource) async {
4141 await waitForTasksFinished ();
4242 var edits = await _getBulkEdits ();
4343 expect (edits, hasLength (1 ));
44- var editedSource = SourceEdit .applySequence (testCode, edits[0 ].edits);
44+ var editedSource =
45+ SourceEdit .applySequence (file.readAsStringSync (), edits[0 ].edits);
4546 expect (editedSource, expectedSource);
4647 }
4748
@@ -55,12 +56,11 @@ class BulkFixesTest extends AbstractAnalysisTest {
5556 Future <void > setUp () async {
5657 super .setUp ();
5758 registerLintRules ();
58- handler = EditDomainHandler (server);
59- await createProject ();
59+ await setRoots (included: [workspaceRootPath], excluded: []);
6060 }
6161
6262 Future <void > test_annotateOverrides_excludedFile () async {
63- newAnalysisOptionsYamlFile2 (projectPath , '''
63+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
6464analyzer:
6565 exclude:
6666 - test/**
@@ -69,7 +69,7 @@ linter:
6969 - annotate_overrides
7070''' );
7171
72- newFile2 ('$projectPath /test/test.dart' , '''
72+ newFile2 ('$testPackageRootPath /test/test.dart' , '''
7373class A {
7474 void f() {}
7575}
@@ -83,14 +83,14 @@ class B extends A {
8383
8484 Future <void > test_annotateOverrides_excludedSubProject () async {
8585 // Root project.
86- newAnalysisOptionsYamlFile2 (projectPath , '''
86+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
8787analyzer:
8888 exclude:
8989 - test/data/**
9090''' );
9191
9292 // Sub-project.
93- var subprojectRoot = '$projectPath /test/data/subproject' ;
93+ var subprojectRoot = '$testPackageRootPath /test/data/subproject' ;
9494 newAnalysisOptionsYamlFile2 (subprojectRoot, '''
9595linter:
9696 rules:
@@ -114,7 +114,7 @@ class B extends A {
114114 }
115115
116116 Future <void > test_annotateOverrides_subProject () async {
117- var subprojectRoot = '$projectPath /test/data/subproject' ;
117+ var subprojectRoot = '$testPackageRootPath /test/data/subproject' ;
118118 newAnalysisOptionsYamlFile2 (subprojectRoot, '''
119119linter:
120120 rules:
@@ -125,8 +125,7 @@ linter:
125125name: subproject
126126''' );
127127
128- testFile = '$subprojectRoot /test.dart' ;
129- addTestFile ('''
128+ var file = newFile2 ('$subprojectRoot /test.dart' , '''
130129class A {
131130 void f() {}
132131}
@@ -135,7 +134,9 @@ class B extends A {
135134}
136135''' );
137136
138- await assertEditEquals ('''
137+ await waitForTasksFinished ();
138+
139+ await assertEditEquals (file, '''
139140class A {
140141 void f() {}
141142}
@@ -147,15 +148,14 @@ class B extends A {
147148 }
148149
149150 Future <void > test_details () async {
150- newAnalysisOptionsYamlFile2 (projectPath , '''
151+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
151152linter:
152153 rules:
153154 - annotate_overrides
154155 - unnecessary_new
155156''' );
156157
157- var fileA = convertPath ('$projectPath /a.dart' );
158- newFile2 (fileA, '''
158+ var a = newFile2 ('$testPackageLibPath /a.dart' , '''
159159class A {
160160 A f() => new A();
161161}
@@ -173,15 +173,15 @@ A f() => new A();
173173 var details = await _getBulkFixDetails ();
174174 expect (details, hasLength (2 ));
175175 assertContains (details,
176- path: fileA , code: LintNames .unnecessary_new, count: 2 );
176+ path: a.path , code: LintNames .unnecessary_new, count: 2 );
177177 assertContains (details,
178- path: fileA , code: LintNames .annotate_overrides, count: 1 );
178+ path: a.path , code: LintNames .annotate_overrides, count: 1 );
179179 assertContains (details,
180- path: testFile, code: LintNames .unnecessary_new, count: 1 );
180+ path: testFile.path , code: LintNames .unnecessary_new, count: 1 );
181181 }
182182
183183 Future <void > test_unnecessaryNew () async {
184- newAnalysisOptionsYamlFile2 (projectPath , '''
184+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
185185linter:
186186 rules:
187187 - unnecessary_new
@@ -191,21 +191,20 @@ class A {}
191191A f() => new A();
192192''' );
193193
194- await assertEditEquals ('''
194+ await assertEditEquals (testFile, '''
195195class A {}
196196A f() => A();
197197''' );
198198 }
199199
200- @FailingTest (issue: 'https://github.com/dart-lang/sdk/issues/44080' )
201200 Future <void > test_unnecessaryNew_collectionLiteral_overlap () async {
202201 // The test case currently drops the 'new' but does not convert the code to
203202 // use a set literal. The code is no longer mangled, but we need to run the
204203 // BulkFixProcessor iteratively to solve the second case.
205204 if (Platform .isWindows) {
206205 fail ('Should not be passing on Windows, but it does' );
207206 }
208- newAnalysisOptionsYamlFile2 (projectPath , '''
207+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
209208linter:
210209 rules:
211210 - prefer_collection_literals
@@ -219,7 +218,7 @@ class A {
219218}
220219''' );
221220
222- await assertEditEquals ('''
221+ await assertEditEquals (testFile, '''
223222class A {
224223 Map<String, Object> _map = {};
225224 Set<String> _set = <String>{};
@@ -228,7 +227,7 @@ class A {
228227 }
229228
230229 Future <void > test_unnecessaryNew_ignoredInOptions () async {
231- newAnalysisOptionsYamlFile2 (projectPath , '''
230+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
232231analyzer:
233232 errors:
234233 unnecessary_new: ignore
@@ -244,7 +243,7 @@ A f() => new A();
244243 }
245244
246245 Future <void > test_unnecessaryNew_ignoredInSource () async {
247- newAnalysisOptionsYamlFile2 (projectPath , '''
246+ newAnalysisOptionsYamlFile2 (testPackageRootPath , '''
248247linter:
249248 rules:
250249 - unnecessary_new
@@ -268,8 +267,8 @@ A f() => new A();
268267 }
269268
270269 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);
273272 return EditBulkFixesResult .fromResponse (response);
274273 }
275274}
0 commit comments