OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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 @TestOn("vm") | |
6 library analyzer_cli.test.plugin_manager_test; | |
7 | |
8 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | |
9 import 'package:analyzer_cli/src/plugin/plugin_manager.dart'; | |
10 import 'package:test/test.dart'; | |
11 | |
12 main() { | |
13 group('plugin manager tests', () { | |
14 test('combine plugin info', () { | |
15 PluginInfo localInfo = new PluginInfo(name: 'my_plugin'); | |
16 PluginInfo manifestInfo = new PluginInfo( | |
17 className: 'MyPlugin', libraryUri: 'my_plugin/my_plugin.dart'); | |
18 | |
19 PluginInfo merged = combine(localInfo, manifestInfo); | |
20 expect(merged.name, equals('my_plugin')); | |
21 expect(merged.className, equals('MyPlugin')); | |
22 expect(merged.libraryUri, equals('my_plugin/my_plugin.dart')); | |
23 }); | |
24 | |
25 test('find manifest', () { | |
26 const manifestSrc = ''' | |
27 library_uri: 'my_plugin/my_plugin.dart' | |
28 '''; | |
29 var packageMap = {'my_plugin': new Uri.file('my_plugin')}; | |
30 | |
31 PluginManager pm = | |
32 new PluginManager(packageMap, 'analyzer', (Uri uri) => manifestSrc); | |
33 | |
34 PluginManifest manifest = pm.findManifest('my_plugin'); | |
35 expect(manifest, isNotNull); | |
36 expect(manifest.plugin.libraryUri, equals('my_plugin/my_plugin.dart')); | |
37 }); | |
38 | |
39 final plugin1Uri = new Uri.file('my_plugin1'); | |
40 final plugin2Uri = new Uri.file('my_plugin2'); | |
41 final plugin3Uri = new Uri.file('my_plugin3'); | |
42 | |
43 const serverPluginManifest = ''' | |
44 library_uri: 'my_plugin2/my_plugin2.dart' | |
45 contributes_to: analysis_server | |
46 '''; | |
47 const analyzerPluginManifest = ''' | |
48 library_uri: 'my_plugin3/my_plugin3.dart' | |
49 contributes_to: analyzer | |
50 '''; | |
51 | |
52 var packageMap = { | |
53 'my_plugin': plugin1Uri, | |
54 'my_plugin2': plugin2Uri, | |
55 'my_plugin3': plugin3Uri | |
56 }; | |
57 | |
58 var manifestReader = (Uri uri) { | |
59 if (uri == plugin2Uri) return serverPluginManifest; | |
60 if (uri == plugin3Uri) return analyzerPluginManifest; | |
61 return null; | |
62 }; | |
63 | |
64 test('get plugin details', () { | |
65 PluginManager pm = | |
66 new PluginManager(packageMap, 'analysis_server', manifestReader); | |
67 | |
68 PluginInfo notFound = new PluginInfo(name: 'my_plugin1'); | |
69 PluginInfo applicable = new PluginInfo(name: 'my_plugin2'); | |
70 PluginInfo notApplicable = new PluginInfo(name: 'my_plugin3'); | |
71 | |
72 PluginConfig localConfig = | |
73 new PluginConfig([notFound, applicable, notApplicable]); | |
74 | |
75 Iterable<PluginDetails> details = pm.getPluginDetails(localConfig); | |
76 expect(details, hasLength(3)); | |
77 | |
78 List<PluginDetails> plugins = sortByName(details); | |
79 | |
80 expect(plugins[0].plugin.name, equals('my_plugin1')); | |
81 expect(plugins[0].status, equals(PluginStatus.NotFound)); | |
82 expect(plugins[1].plugin.name, equals('my_plugin2')); | |
83 expect( | |
84 plugins[1].plugin.libraryUri, equals('my_plugin2/my_plugin2.dart')); | |
85 expect(plugins[1].status, equals(PluginStatus.Applicable)); | |
86 expect(plugins[2].plugin.name, equals('my_plugin3')); | |
87 expect(plugins[2].status, equals(PluginStatus.NotApplicable)); | |
88 }); | |
89 }); | |
90 } | |
91 | |
92 List<PluginDetails> sortByName(Iterable<PluginDetails> details) => | |
93 details.toList() | |
94 ..sort((p1, p2) => p1.plugin.name.compareTo(p2.plugin.name)); | |
OLD | NEW |