Skip to content

Commit c224d21

Browse files
scheglovCommit Bot
authored and
Commit Bot
committed
Migrate edit domain tests to PubPackageAnalysisServerTest.
Change-Id: Ia8d2bb4b5739f3b666c842fa318fc0101858905d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240644 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent b566ba1 commit c224d21

10 files changed

+266
-258
lines changed

pkg/analysis_server/test/edit/assists_test.dart

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/protocol/protocol_generated.dart';
6-
import 'package:analysis_server/src/edit/edit_domain.dart';
76
import 'package:analysis_server/src/plugin/plugin_manager.dart';
87
import 'package:analyzer/instrumentation/service.dart';
98
import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
@@ -12,8 +11,7 @@ import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
1211
import 'package:test/test.dart';
1312
import 'package:test_reflective_loader/test_reflective_loader.dart';
1413

15-
import '../analysis_abstract.dart';
16-
import '../mocks.dart';
14+
import '../analysis_server_base.dart';
1715
import '../src/plugin/plugin_manager_test.dart';
1816

1917
void main() {
@@ -23,7 +21,7 @@ void main() {
2321
}
2422

2523
@reflectiveTest
26-
class AssistsTest extends AbstractAnalysisTest {
24+
class AssistsTest extends PubPackageAnalysisServerTest {
2725
late List<SourceChange> changes;
2826

2927
Future<void> prepareAssists(String search, [int length = 0]) async {
@@ -32,17 +30,17 @@ class AssistsTest extends AbstractAnalysisTest {
3230
}
3331

3432
Future<void> prepareAssistsAt(int offset, int length) async {
35-
var request = EditGetAssistsParams(testFile, offset, length).toRequest('0');
36-
var response = await waitResponse(request);
33+
var request =
34+
EditGetAssistsParams(testFile.path, offset, length).toRequest('0');
35+
var response = await handleSuccessfulRequest(request);
3736
var result = EditGetAssistsResult.fromResponse(response);
3837
changes = result.assists;
3938
}
4039

4140
@override
4241
Future<void> setUp() async {
4342
super.setUp();
44-
await createProject();
45-
handler = EditDomainHandler(server);
43+
await setRoots(included: [workspaceRootPath], excluded: []);
4644
}
4745

4846
Future<void> test_fromPlugins() async {
@@ -68,21 +66,23 @@ class AssistsTest extends AbstractAnalysisTest {
6866

6967
Future<void> test_invalidFilePathFormat_notAbsolute() async {
7068
var request = EditGetAssistsParams('test.dart', 0, 0).toRequest('0');
71-
var response = await waitResponse(request);
72-
expect(
69+
var response = await handleRequest(request);
70+
assertResponseFailure(
7371
response,
74-
isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
72+
requestId: '0',
73+
errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
7574
);
7675
}
7776

7877
Future<void> test_invalidFilePathFormat_notNormalized() async {
7978
var request =
8079
EditGetAssistsParams(convertPath('/foo/../bar/test.dart'), 0, 0)
8180
.toRequest('0');
82-
var response = await waitResponse(request);
83-
expect(
81+
var response = await handleRequest(request);
82+
assertResponseFailure(
8483
response,
85-
isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
84+
requestId: '0',
85+
errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
8686
);
8787
}
8888

@@ -142,7 +142,7 @@ main() {
142142
for (var change in changes) {
143143
if (change.message == message) {
144144
var resultCode =
145-
SourceEdit.applySequence(testCode, change.edits[0].edits);
145+
SourceEdit.applySequence(testFileContent, change.edits[0].edits);
146146
expect(resultCode, expectedCode);
147147
return;
148148
}

pkg/analysis_server/test/edit/bulk_fixes_test.dart

+30-31
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
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

77
import 'package:analysis_server/protocol/protocol_generated.dart';
8-
import 'package:analysis_server/src/edit/edit_domain.dart';
98
import 'package:analysis_server/src/services/linter/lint_names.dart';
9+
import 'package:analyzer/file_system/file_system.dart';
1010
import 'package:analyzer_plugin/protocol/protocol_common.dart';
1111
import 'package:linter/src/rules.dart';
1212
import 'package:test/test.dart';
1313
import 'package:test_reflective_loader/test_reflective_loader.dart';
1414

15-
import '../analysis_abstract.dart';
15+
import '../analysis_server_base.dart';
1616

1717
void 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, '''
6464
analyzer:
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', '''
7373
class 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, '''
8787
analyzer:
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, '''
9595
linter:
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, '''
119119
linter:
120120
rules:
@@ -125,8 +125,7 @@ linter:
125125
name: subproject
126126
''');
127127

128-
testFile = '$subprojectRoot/test.dart';
129-
addTestFile('''
128+
var file = newFile2('$subprojectRoot/test.dart', '''
130129
class 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, '''
139140
class 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, '''
151152
linter:
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', '''
159159
class 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, '''
185185
linter:
186186
rules:
187187
- unnecessary_new
@@ -191,21 +191,20 @@ class A {}
191191
A f() => new A();
192192
''');
193193

194-
await assertEditEquals('''
194+
await assertEditEquals(testFile, '''
195195
class A {}
196196
A 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, '''
209208
linter:
210209
rules:
211210
- prefer_collection_literals
@@ -219,7 +218,7 @@ class A {
219218
}
220219
''');
221220

222-
await assertEditEquals('''
221+
await assertEditEquals(testFile, '''
223222
class 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, '''
232231
analyzer:
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, '''
248247
linter:
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

Comments
 (0)