Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: pkg/analyzer_plugin/test/plugin/plugin_test.dart

Issue 2857233002: Implement more of the behavior of a plugin; refactor some API (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer_plugin/plugin/plugin.dart';
11 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
12 import 'package:path/src/context.dart';
13 import 'package:test/test.dart';
14 import 'package:test_reflective_loader/test_reflective_loader.dart';
15
16 void main() {
17 defineReflectiveTests(ServerPluginTest);
18 }
19
20 class MockAnalysisDriver extends AnalysisDriverGeneric {
21 @override
22 bool get hasFilesToAnalyze => false;
23
24 @override
25 set priorityFiles(List<String> priorityPaths) {}
26
27 @override
28 AnalysisDriverPriority get workPriority => AnalysisDriverPriority.nothing;
29
30 @override
31 void dispose() {}
32
33 @override
34 Future<Null> performWork() => new Future.value(null);
35 }
36
37 @reflectiveTest
38 class ServerPluginTest {
39 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
40
41 TestServerPlugin plugin;
42
43 String packagePath1;
44 String filePath1;
45 ContextRoot contextRoot1;
46
47 String packagePath2;
48 String filePath2;
49 ContextRoot contextRoot2;
50
51 void setUp() {
52 Context pathContext = resourceProvider.pathContext;
53
54 packagePath1 = resourceProvider.convertPath('/package1');
55 String lib1Path = pathContext.join(packagePath1, 'lib');
56 filePath1 = pathContext.join(lib1Path, 'test.dart');
57 resourceProvider.newFolder(packagePath1);
58 resourceProvider.newFolder(lib1Path);
59 resourceProvider.newFile(filePath1, '');
scheglov 2017/05/03 19:37:02 newFile() creates all its parent folders.
Brian Wilkerson 2017/05/03 19:48:12 Done
60 contextRoot1 = new ContextRoot(packagePath1, <String>[]);
61
62 packagePath2 = resourceProvider.convertPath('/package2');
63 String lib2Path = pathContext.join(packagePath2, 'lib');
64 filePath2 = pathContext.join(lib2Path, 'test.dart');
65 resourceProvider.newFolder(packagePath1);
66 resourceProvider.newFolder(lib2Path);
67 resourceProvider.newFile(filePath2, '');
68 contextRoot2 = new ContextRoot(packagePath2, <String>[]);
69
70 plugin = new TestServerPlugin(resourceProvider);
71 }
72
73 void test_contextRootContaining_insideRoot() {
74 plugin.handleAnalysisSetContextRoots(
75 new AnalysisSetContextRootsParams([contextRoot1]));
76
77 expect(plugin.contextRootContaining(filePath1), isNotNull);
78 }
79
80 void test_contextRootContaining_noRoots() {
81 expect(plugin.contextRootContaining(filePath1), isNull);
82 }
83
84 void test_contextRootContaining_outsideRoot() {
85 plugin.handleAnalysisSetContextRoots(
86 new AnalysisSetContextRootsParams([contextRoot1]));
87
88 expect(plugin.contextRootContaining(filePath2), isNull);
89 }
90
91 @failingTest
92 void test_handleAnalysisHandleWatchEvents() {
93 var result = plugin.handleAnalysisHandleWatchEvents(
94 new AnalysisHandleWatchEventsParams([]));
95 expect(result, isNotNull);
96 }
97
98 @failingTest
99 void test_handleAnalysisReanalyze_all() {
100 plugin.handleAnalysisSetContextRoots(
101 new AnalysisSetContextRootsParams([contextRoot1]));
102 var result = plugin.handleAnalysisReanalyze(new AnalysisReanalyzeParams());
103 expect(result, isNotNull);
104 }
105
106 @failingTest
107 void test_handleAnalysisReanalyze_subset() {
108 plugin.handleAnalysisSetContextRoots(
109 new AnalysisSetContextRootsParams([contextRoot1]));
110 plugin.handleAnalysisSetContextRoots(
111 new AnalysisSetContextRootsParams([contextRoot2]));
112 var result = plugin.handleAnalysisReanalyze(
113 new AnalysisReanalyzeParams(roots: [packagePath2]));
114 expect(result, isNotNull);
115 }
116
117 @failingTest
118 void test_handleAnalysisSetContextBuilderOptions() {
119 var result = plugin.handleAnalysisSetContextBuilderOptions(
120 new AnalysisSetContextBuilderOptionsParams(
121 new ContextBuilderOptions()));
122 expect(result, isNotNull);
123 }
124
125 void test_handleAnalysisSetContextRoots() {
126 var result = plugin.handleAnalysisSetContextRoots(
127 new AnalysisSetContextRootsParams([contextRoot1]));
128 expect(result, isNotNull);
129 expect(plugin.driverMap[contextRoot1], isNotNull);
130 }
131
132 void test_handleAnalysisSetPriorityFiles() {
133 plugin.handleAnalysisSetContextRoots(
134 new AnalysisSetContextRootsParams([contextRoot1]));
135
136 var result = plugin.handleAnalysisSetPriorityFiles(
137 new AnalysisSetPriorityFilesParams([filePath1]));
138 expect(result, isNotNull);
139 }
140
141 void test_handleAnalysisSetSubscriptions() {
142 plugin.handleAnalysisSetContextRoots(
143 new AnalysisSetContextRootsParams([contextRoot1]));
144 expect(plugin.subscriptionManager.servicesForFile(filePath1), isEmpty);
145
146 AnalysisSetSubscriptionsResult result = plugin
147 .handleAnalysisSetSubscriptions(new AnalysisSetSubscriptionsParams({
148 AnalysisService.OUTLINE: [filePath1]
149 }));
150 expect(result, isNotNull);
151 expect(plugin.subscriptionManager.servicesForFile(filePath1),
152 [AnalysisService.OUTLINE]);
153 }
154
155 void test_handleAnalysisUpdateContent() {
156 plugin.handleAnalysisSetContextRoots(
157 new AnalysisSetContextRootsParams([contextRoot1]));
158 var addResult = plugin.handleAnalysisUpdateContent(
159 new AnalysisUpdateContentParams(
160 {filePath1: new AddContentOverlay('class C {}')}));
161 expect(addResult, isNotNull);
162 var changeResult =
163 plugin.handleAnalysisUpdateContent(new AnalysisUpdateContentParams({
164 filePath1:
165 new ChangeContentOverlay([new SourceEdit(7, 0, ' extends Object')])
166 }));
167 expect(changeResult, isNotNull);
168 var removeResult = plugin.handleAnalysisUpdateContent(
169 new AnalysisUpdateContentParams(
170 {filePath1: new RemoveContentOverlay()}));
171 expect(removeResult, isNotNull);
172 }
173
174 void test_handleCompletionGetSuggestions() {
175 plugin.handleAnalysisSetContextRoots(
176 new AnalysisSetContextRootsParams([contextRoot1]));
177
178 CompletionGetSuggestionsResult result =
179 plugin.handleCompletionGetSuggestions(
180 new CompletionGetSuggestionsParams(filePath1, 12));
181 expect(result, isNotNull);
182 }
183
184 void test_handleEditGetAssists() {
185 plugin.handleAnalysisSetContextRoots(
186 new AnalysisSetContextRootsParams([contextRoot1]));
187
188 EditGetAssistsResult result =
189 plugin.handleEditGetAssists(new EditGetAssistsParams(filePath1, 10, 0));
190 expect(result, isNotNull);
191 }
192
193 void test_handleEditGetAvailableRefactorings() {
194 plugin.handleAnalysisSetContextRoots(
195 new AnalysisSetContextRootsParams([contextRoot1]));
196
197 EditGetAvailableRefactoringsResult result =
198 plugin.handleEditGetAvailableRefactorings(
199 new EditGetAvailableRefactoringsParams(filePath1, 10, 0));
200 expect(result, isNotNull);
201 }
202
203 void test_handleEditGetFixes() {
204 plugin.handleAnalysisSetContextRoots(
205 new AnalysisSetContextRootsParams([contextRoot1]));
206
207 EditGetFixesResult result =
208 plugin.handleEditGetFixes(new EditGetFixesParams(filePath1, 13));
209 expect(result, isNotNull);
210 }
211
212 @failingTest
213 void test_handleEditGetRefactoring() {
214 plugin.handleAnalysisSetContextRoots(
215 new AnalysisSetContextRootsParams([contextRoot1]));
216
217 EditGetRefactoringResult result = plugin.handleEditGetRefactoring(
218 new EditGetRefactoringParams(
219 RefactoringKind.RENAME, filePath1, 7, 0, false));
220 expect(result, isNotNull);
221 }
222
223 void test_handlePluginShutdown() {
224 var result = plugin.handlePluginShutdown(new PluginShutdownParams());
225 expect(result, isNotNull);
226 }
227
228 void test_handlePluginVersionCheck() {
229 PluginVersionCheckResult result = plugin.handlePluginVersionCheck(
230 new PluginVersionCheckParams('path', '0.1.0'));
231 expect(result, isNotNull);
232 expect(result.interestingFiles, ['*.dart']);
233 expect(result.isCompatible, isTrue);
234 expect(result.name, 'Test Plugin');
235 expect(result.version, '0.1.0');
236 }
237
238 @failingTest
239 void test_isCompatibleWith() {
240 fail('Not yet implemented.');
241 }
242
243 @failingTest
244 void test_onDone() {
245 fail('Not yet implemented.');
246 }
247
248 @failingTest
249 void test_onError() {
250 fail('Not yet implemented.');
251 }
252
253 @failingTest
254 void test_start() {
255 fail('Not yet implemented.');
256 }
257 }
258
259 /**
260 * A concrete implementation of a server plugin that is suitable for testing.
261 */
262 class TestServerPlugin extends ServerPlugin {
263 TestServerPlugin(ResourceProvider resourceProvider) : super(resourceProvider);
264
265 @override
266 List<String> get fileGlobsToAnalyze => <String>['*.dart'];
267
268 @override
269 String get name => 'Test Plugin';
270
271 @override
272 String get version => '0.1.0';
273
274 @override
275 AnalysisDriverGeneric createAnalysisDriver(ContextRoot contextRoot) {
276 return new MockAnalysisDriver();
277 }
278 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/plugin/plugin.dart ('k') | pkg/analyzer_plugin/test/plugin/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698