OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io' as io; | 6 import 'dart:io' as io; |
7 | 7 |
8 import 'package:analysis_server/src/plugin/notification_manager.dart'; | 8 import 'package:analysis_server/src/plugin/notification_manager.dart'; |
9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; | 9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
10 import 'package:analyzer/context/context_root.dart'; | 10 import 'package:analyzer/context/context_root.dart'; |
11 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
12 import 'package:analyzer/file_system/physical_file_system.dart'; | 12 import 'package:analyzer/file_system/physical_file_system.dart'; |
13 import 'package:analyzer/instrumentation/instrumentation.dart'; | 13 import 'package:analyzer/instrumentation/instrumentation.dart'; |
14 import 'package:analyzer_plugin/channel/channel.dart'; | 14 import 'package:analyzer_plugin/channel/channel.dart'; |
15 import 'package:analyzer_plugin/protocol/protocol.dart'; | 15 import 'package:analyzer_plugin/protocol/protocol.dart'; |
16 import 'package:analyzer_plugin/protocol/protocol_generated.dart' | 16 import 'package:analyzer_plugin/protocol/protocol_generated.dart' |
17 hide ContextRoot; | 17 hide ContextRoot; |
18 import 'package:path/path.dart' as path; | 18 import 'package:path/path.dart' as path; |
19 import 'package:test/test.dart'; | 19 import 'package:test/test.dart'; |
20 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 20 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
21 import 'package:watcher/watcher.dart' as watcher; | 21 import 'package:watcher/watcher.dart' as watcher; |
22 | 22 |
23 main() { | 23 main() { |
24 defineReflectiveSuite(() { | 24 defineReflectiveSuite(() { |
25 defineReflectiveTests(PluginInfoTest); | 25 defineReflectiveTests(BuiltInPluginInfoTest); |
| 26 defineReflectiveTests(DiscoveredPluginInfoTest); |
26 defineReflectiveTests(PluginManagerTest); | 27 defineReflectiveTests(PluginManagerTest); |
27 defineReflectiveTests(PluginManagerFromDiskTest); | 28 defineReflectiveTests(PluginManagerFromDiskTest); |
28 defineReflectiveTests(PluginSessionTest); | 29 defineReflectiveTests(PluginSessionTest); |
29 defineReflectiveTests(PluginSessionFromDiskTest); | 30 defineReflectiveTests(PluginSessionFromDiskTest); |
30 }); | 31 }); |
31 } | 32 } |
32 | 33 |
33 @reflectiveTest | 34 @reflectiveTest |
34 class PluginInfoTest { | 35 class BuiltInPluginInfoTest { |
| 36 TestNotificationManager notificationManager; |
| 37 BuiltInPluginInfo plugin; |
| 38 |
| 39 void setUp() { |
| 40 notificationManager = new TestNotificationManager(); |
| 41 plugin = new BuiltInPluginInfo(null, 'test plugin', notificationManager, |
| 42 InstrumentationService.NULL_SERVICE); |
| 43 } |
| 44 |
| 45 test_addContextRoot() { |
| 46 ContextRoot contextRoot1 = new ContextRoot('/pkg1', []); |
| 47 plugin.addContextRoot(contextRoot1); |
| 48 expect(plugin.contextRoots, [contextRoot1]); |
| 49 plugin.addContextRoot(contextRoot1); |
| 50 expect(plugin.contextRoots, [contextRoot1]); |
| 51 } |
| 52 |
| 53 test_creation() { |
| 54 expect(plugin.pluginId, 'test plugin'); |
| 55 expect(plugin.notificationManager, notificationManager); |
| 56 expect(plugin.contextRoots, isEmpty); |
| 57 expect(plugin.currentSession, isNull); |
| 58 } |
| 59 |
| 60 test_removeContextRoot() { |
| 61 ContextRoot contextRoot1 = new ContextRoot('/pkg1', []); |
| 62 ContextRoot contextRoot2 = new ContextRoot('/pkg2', []); |
| 63 plugin.addContextRoot(contextRoot1); |
| 64 expect(plugin.contextRoots, unorderedEquals([contextRoot1])); |
| 65 plugin.addContextRoot(contextRoot2); |
| 66 expect(plugin.contextRoots, unorderedEquals([contextRoot1, contextRoot2])); |
| 67 plugin.removeContextRoot(contextRoot1); |
| 68 expect(plugin.contextRoots, unorderedEquals([contextRoot2])); |
| 69 plugin.removeContextRoot(contextRoot2); |
| 70 expect(plugin.contextRoots, isEmpty); |
| 71 } |
| 72 |
| 73 @failingTest |
| 74 test_start_notRunning() { |
| 75 fail('Not tested'); |
| 76 } |
| 77 |
| 78 test_start_running() async { |
| 79 plugin.currentSession = new PluginSession(plugin); |
| 80 try { |
| 81 await plugin.start(''); |
| 82 fail('Expected a StateError'); |
| 83 } on StateError { |
| 84 // Expected. |
| 85 } |
| 86 } |
| 87 |
| 88 test_stop_notRunning() { |
| 89 expect(() => plugin.stop(), throwsA(new isInstanceOf<StateError>())); |
| 90 } |
| 91 |
| 92 test_stop_running() { |
| 93 PluginSession session = new PluginSession(plugin); |
| 94 TestServerCommunicationChannel channel = |
| 95 new TestServerCommunicationChannel(session); |
| 96 plugin.currentSession = session; |
| 97 plugin.stop(); |
| 98 expect(plugin.currentSession, isNull); |
| 99 expect(channel.sentRequests, hasLength(1)); |
| 100 expect(channel.sentRequests[0].method, 'plugin.shutdown'); |
| 101 } |
| 102 } |
| 103 |
| 104 @reflectiveTest |
| 105 class DiscoveredPluginInfoTest { |
35 MemoryResourceProvider resourceProvider; | 106 MemoryResourceProvider resourceProvider; |
36 TestNotificationManager notificationManager; | 107 TestNotificationManager notificationManager; |
37 String pluginPath = '/pluginDir'; | 108 String pluginPath = '/pluginDir'; |
38 String executionPath = '/pluginDir/bin/plugin.dart'; | 109 String executionPath = '/pluginDir/bin/plugin.dart'; |
39 String packagesPath = '/pluginDir/.packages'; | 110 String packagesPath = '/pluginDir/.packages'; |
40 PluginInfo plugin; | 111 DiscoveredPluginInfo plugin; |
41 | 112 |
42 void setUp() { | 113 void setUp() { |
43 resourceProvider = new MemoryResourceProvider(); | 114 resourceProvider = new MemoryResourceProvider(); |
44 notificationManager = new TestNotificationManager(); | 115 notificationManager = new TestNotificationManager(); |
45 plugin = new PluginInfo(pluginPath, executionPath, packagesPath, | 116 plugin = new DiscoveredPluginInfo(pluginPath, executionPath, packagesPath, |
46 notificationManager, InstrumentationService.NULL_SERVICE); | 117 notificationManager, InstrumentationService.NULL_SERVICE); |
47 } | 118 } |
48 | 119 |
49 test_addContextRoot() { | 120 test_addContextRoot() { |
50 ContextRoot contextRoot1 = new ContextRoot('/pkg1', []); | 121 ContextRoot contextRoot1 = new ContextRoot('/pkg1', []); |
51 plugin.addContextRoot(contextRoot1); | 122 plugin.addContextRoot(contextRoot1); |
52 expect(plugin.contextRoots, [contextRoot1]); | 123 expect(plugin.contextRoots, [contextRoot1]); |
53 plugin.addContextRoot(contextRoot1); | 124 plugin.addContextRoot(contextRoot1); |
54 expect(plugin.contextRoots, [contextRoot1]); | 125 expect(plugin.contextRoots, [contextRoot1]); |
55 } | 126 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); | 253 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
183 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); | 254 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
184 await withPlugin( | 255 await withPlugin( |
185 pluginName: 'plugin1', | 256 pluginName: 'plugin1', |
186 test: (String plugin1Path) async { | 257 test: (String plugin1Path) async { |
187 ContextRoot contextRoot = new ContextRoot(pkgPath, []); | 258 ContextRoot contextRoot = new ContextRoot(pkgPath, []); |
188 await manager.addPluginToContextRoot(contextRoot, plugin1Path); | 259 await manager.addPluginToContextRoot(contextRoot, plugin1Path); |
189 List<PluginInfo> plugins = manager.pluginsForContextRoot(contextRoot); | 260 List<PluginInfo> plugins = manager.pluginsForContextRoot(contextRoot); |
190 expect(plugins, hasLength(1)); | 261 expect(plugins, hasLength(1)); |
191 watcher.WatchEvent watchEvent = new watcher.WatchEvent( | 262 watcher.WatchEvent watchEvent = new watcher.WatchEvent( |
192 watcher.ChangeType.MODIFY, | 263 watcher.ChangeType.MODIFY, path.join(pkgPath, 'lib', 'lib.dart')); |
193 path.join(plugin1Path, 'lib', 'lib.dart')); | |
194 List<Future<Response>> responses = | 264 List<Future<Response>> responses = |
195 await manager.broadcastWatchEvent(watchEvent); | 265 await manager.broadcastWatchEvent(watchEvent); |
196 expect(responses, hasLength(1)); | 266 expect(responses, hasLength(1)); |
197 Response response = await responses[0]; | 267 Response response = await responses[0]; |
198 expect(response, isNotNull); | 268 expect(response, isNotNull); |
199 expect(response.error, isNull); | 269 expect(response.error, isNull); |
200 await manager.stopAll(); | 270 await manager.stopAll(); |
201 }); | 271 }); |
202 pkg1Dir.deleteSync(recursive: true); | 272 pkg1Dir.deleteSync(recursive: true); |
203 } | 273 } |
204 | 274 |
205 test_pluginsForContextRoot_multiple() async { | 275 test_pluginsForContextRoot_multiple() async { |
206 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); | 276 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
207 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); | 277 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
208 await withPlugin( | 278 await withPlugin( |
209 pluginName: 'plugin1', | 279 pluginName: 'plugin1', |
210 test: (String plugin1Path) async { | 280 test: (String plugin1Path) async { |
211 await withPlugin( | 281 await withPlugin( |
212 pluginName: 'plugin2', | 282 pluginName: 'plugin2', |
213 test: (String plugin2Path) async { | 283 test: (String plugin2Path) async { |
214 ContextRoot contextRoot = new ContextRoot(pkgPath, []); | 284 ContextRoot contextRoot = new ContextRoot(pkgPath, []); |
215 await manager.addPluginToContextRoot(contextRoot, plugin1Path); | 285 await manager.addPluginToContextRoot(contextRoot, plugin1Path); |
216 await manager.addPluginToContextRoot(contextRoot, plugin2Path); | 286 await manager.addPluginToContextRoot(contextRoot, plugin2Path); |
217 | 287 |
218 List<PluginInfo> plugins = | 288 List<PluginInfo> plugins = |
219 manager.pluginsForContextRoot(contextRoot); | 289 manager.pluginsForContextRoot(contextRoot); |
220 expect(plugins, hasLength(2)); | 290 expect(plugins, hasLength(2)); |
221 List<String> paths = | 291 List<String> paths = plugins |
222 plugins.map((PluginInfo plugin) => plugin.path).toList(); | 292 .map((PluginInfo plugin) => plugin.pluginId) |
| 293 .toList(); |
223 expect(paths, unorderedEquals([plugin1Path, plugin2Path])); | 294 expect(paths, unorderedEquals([plugin1Path, plugin2Path])); |
224 | 295 |
225 await manager.stopAll(); | 296 await manager.stopAll(); |
226 }); | 297 }); |
227 }); | 298 }); |
228 pkg1Dir.deleteSync(recursive: true); | 299 pkg1Dir.deleteSync(recursive: true); |
229 } | 300 } |
230 | 301 |
231 test_pluginsForContextRoot_one() async { | 302 test_pluginsForContextRoot_one() async { |
232 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); | 303 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
233 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); | 304 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
234 await withPlugin(test: (String pluginPath) async { | 305 await withPlugin(test: (String pluginPath) async { |
235 ContextRoot contextRoot = new ContextRoot(pkgPath, []); | 306 ContextRoot contextRoot = new ContextRoot(pkgPath, []); |
236 await manager.addPluginToContextRoot(contextRoot, pluginPath); | 307 await manager.addPluginToContextRoot(contextRoot, pluginPath); |
237 | 308 |
238 List<PluginInfo> plugins = manager.pluginsForContextRoot(contextRoot); | 309 List<PluginInfo> plugins = manager.pluginsForContextRoot(contextRoot); |
239 expect(plugins, hasLength(1)); | 310 expect(plugins, hasLength(1)); |
240 expect(plugins[0].path, pluginPath); | 311 expect(plugins[0].pluginId, pluginPath); |
241 | 312 |
242 await manager.stopAll(); | 313 await manager.stopAll(); |
243 }); | 314 }); |
244 pkg1Dir.deleteSync(recursive: true); | 315 pkg1Dir.deleteSync(recursive: true); |
245 } | 316 } |
246 | 317 |
247 test_removedContextRoot() async { | 318 test_removedContextRoot() async { |
248 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); | 319 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); |
249 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); | 320 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); |
250 await withPlugin(test: (String pluginPath) async { | 321 await withPlugin(test: (String pluginPath) async { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 370 } |
300 | 371 |
301 @reflectiveTest | 372 @reflectiveTest |
302 class PluginSessionFromDiskTest extends PluginTestSupport { | 373 class PluginSessionFromDiskTest extends PluginTestSupport { |
303 test_start_notRunning() async { | 374 test_start_notRunning() async { |
304 await withPlugin(test: (String pluginPath) async { | 375 await withPlugin(test: (String pluginPath) async { |
305 String packagesPath = path.join(pluginPath, '.packages'); | 376 String packagesPath = path.join(pluginPath, '.packages'); |
306 String mainPath = path.join(pluginPath, 'bin', 'plugin.dart'); | 377 String mainPath = path.join(pluginPath, 'bin', 'plugin.dart'); |
307 String byteStorePath = path.join(pluginPath, 'byteStore'); | 378 String byteStorePath = path.join(pluginPath, 'byteStore'); |
308 new io.Directory(byteStorePath).createSync(); | 379 new io.Directory(byteStorePath).createSync(); |
309 PluginInfo plugin = new PluginInfo(pluginPath, mainPath, packagesPath, | 380 PluginInfo plugin = new DiscoveredPluginInfo( |
310 notificationManager, InstrumentationService.NULL_SERVICE); | 381 pluginPath, |
| 382 mainPath, |
| 383 packagesPath, |
| 384 notificationManager, |
| 385 InstrumentationService.NULL_SERVICE); |
311 PluginSession session = new PluginSession(plugin); | 386 PluginSession session = new PluginSession(plugin); |
312 plugin.currentSession = session; | 387 plugin.currentSession = session; |
313 expect(await session.start(byteStorePath), isTrue); | 388 expect(await session.start(byteStorePath), isTrue); |
314 await session.stop(); | 389 await session.stop(); |
315 }); | 390 }); |
316 } | 391 } |
317 } | 392 } |
318 | 393 |
319 @reflectiveTest | 394 @reflectiveTest |
320 class PluginSessionTest { | 395 class PluginSessionTest { |
321 MemoryResourceProvider resourceProvider; | 396 MemoryResourceProvider resourceProvider; |
322 TestNotificationManager notificationManager; | 397 TestNotificationManager notificationManager; |
323 String pluginPath = '/pluginDir'; | 398 String pluginPath = '/pluginDir'; |
324 String executionPath = '/pluginDir/bin/plugin.dart'; | 399 String executionPath = '/pluginDir/bin/plugin.dart'; |
325 String packagesPath = '/pluginDir/.packages'; | 400 String packagesPath = '/pluginDir/.packages'; |
326 PluginInfo plugin; | 401 PluginInfo plugin; |
327 PluginSession session; | 402 PluginSession session; |
328 | 403 |
329 void setUp() { | 404 void setUp() { |
330 resourceProvider = new MemoryResourceProvider(); | 405 resourceProvider = new MemoryResourceProvider(); |
331 notificationManager = new TestNotificationManager(); | 406 notificationManager = new TestNotificationManager(); |
332 plugin = new PluginInfo(pluginPath, executionPath, packagesPath, | 407 plugin = new DiscoveredPluginInfo(pluginPath, executionPath, packagesPath, |
333 notificationManager, InstrumentationService.NULL_SERVICE); | 408 notificationManager, InstrumentationService.NULL_SERVICE); |
334 session = new PluginSession(plugin); | 409 session = new PluginSession(plugin); |
335 } | 410 } |
336 | 411 |
337 void test_handleNotification() { | 412 void test_handleNotification() { |
338 Notification notification = | 413 Notification notification = |
339 new AnalysisErrorsParams('/test.dart', <AnalysisError>[]) | 414 new AnalysisErrorsParams('/test.dart', <AnalysisError>[]) |
340 .toNotification(); | 415 .toNotification(); |
341 expect(notificationManager.notifications, hasLength(0)); | 416 expect(notificationManager.notifications, hasLength(0)); |
342 session.handleNotification(notification); | 417 session.handleNotification(notification); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 void onNotification(Notification notification), | 678 void onNotification(Notification notification), |
604 {Function onError, void onDone()}) { | 679 {Function onError, void onDone()}) { |
605 fail('Unexpected invocation of listen'); | 680 fail('Unexpected invocation of listen'); |
606 } | 681 } |
607 | 682 |
608 @override | 683 @override |
609 void sendRequest(Request request) { | 684 void sendRequest(Request request) { |
610 sentRequests.add(request); | 685 sentRequests.add(request); |
611 } | 686 } |
612 } | 687 } |
OLD | NEW |