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 library analyzer.test.src.plugin.plugin_config_test; | |
6 | |
7 import 'package:analyzer/source/analysis_options_provider.dart'; | |
8 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | |
9 import 'package:test/test.dart'; | |
10 import 'package:yaml/yaml.dart'; | |
11 | |
12 main() { | |
13 group('plugin config tests', () { | |
14 group('parsing', () { | |
15 test('plugin map', () { | |
16 const optionsSrc = ''' | |
17 analyzer: | |
18 plugins: | |
19 my_plugin1: ^0.1.0 #shorthand | |
20 my_plugin2: | |
21 version: ^0.2.0 | |
22 my_plugin3: | |
23 class_name: MyPlugin | |
24 library_uri: myplugin/myplugin.dart | |
25 path: '/u/disk/src/' | |
26 '''; | |
27 var config = parseConfig(optionsSrc); | |
28 var plugins = pluginsSortedByName(config.plugins); | |
29 expect(plugins, hasLength(3)); | |
30 expect(plugins[0].name, equals('my_plugin1')); | |
31 expect(plugins[0].version, equals('^0.1.0')); | |
32 expect(plugins[1].name, equals('my_plugin2')); | |
33 expect(plugins[1].version, equals('^0.2.0')); | |
34 expect(plugins[2].name, equals('my_plugin3')); | |
35 expect(plugins[2].version, isNull); | |
36 expect(plugins[2].path, equals('/u/disk/src/')); | |
37 expect(plugins[2].libraryUri, equals('myplugin/myplugin.dart')); | |
38 expect(plugins[2].className, equals('MyPlugin')); | |
39 }); | |
40 | |
41 test('plugin map (empty)', () { | |
42 const optionsSrc = ''' | |
43 analyzer: | |
44 plugins: | |
45 # my_plugin1: ^0.1.0 #shorthand | |
46 '''; | |
47 var config = parseConfig(optionsSrc); | |
48 // Commented out plugins shouldn't cause a parse failure. | |
49 expect(config.plugins, hasLength(0)); | |
50 }); | |
51 | |
52 test('plugin manifest', () { | |
53 const manifestSrc = ''' | |
54 class_name: AnalyzerPlugin | |
55 library_uri: myplugin/analyzer_plugin.dart | |
56 contributes_to: analyzer | |
57 '''; | |
58 var manifest = parsePluginManifestString(manifestSrc); | |
59 var plugin = manifest.plugin; | |
60 expect(plugin.libraryUri, equals('myplugin/analyzer_plugin.dart')); | |
61 expect(plugin.className, equals('AnalyzerPlugin')); | |
62 expect(manifest.contributesTo, unorderedEquals(['analyzer'])); | |
63 }); | |
64 | |
65 test('plugin manifest (contributes_to list)', () { | |
66 const manifestSrc = ''' | |
67 class_name: AnalyzerPlugin | |
68 library_uri: myplugin/analyzer_plugin.dart | |
69 contributes_to: | |
70 - analyzer | |
71 - analysis_server | |
72 '''; | |
73 var manifest = parsePluginManifestString(manifestSrc); | |
74 var plugin = manifest.plugin; | |
75 expect(plugin.libraryUri, equals('myplugin/analyzer_plugin.dart')); | |
76 expect(plugin.className, equals('AnalyzerPlugin')); | |
77 expect(manifest.contributesTo, | |
78 unorderedEquals(['analyzer', 'analysis_server'])); | |
79 }); | |
80 | |
81 group('errors', () { | |
82 test('bad config format', () { | |
83 const optionsSrc = ''' | |
84 analyzer: | |
85 plugins: | |
86 - my_plugin1 | |
87 - my_plugin2 | |
88 '''; | |
89 try { | |
90 parseConfig(optionsSrc); | |
91 fail('expected PluginConfigFormatException'); | |
92 } on PluginConfigFormatException catch (e) { | |
93 expect( | |
94 e.message, | |
95 equals( | |
96 'Unrecognized plugin config format, expected `YamlMap`, got
`YamlList`')); | |
97 expect(e.yamlNode, new isInstanceOf<YamlList>()); | |
98 } | |
99 }); | |
100 test('bad manifest format', () { | |
101 const manifestSource = ''' | |
102 library_uri: | |
103 - should be a scalar uri | |
104 '''; | |
105 try { | |
106 parsePluginManifestString(manifestSource); | |
107 fail('expected PluginConfigFormatException'); | |
108 } on PluginConfigFormatException catch (e) { | |
109 expect( | |
110 e.message, | |
111 equals( | |
112 'Unable to parse pugin manifest, expected `String`, got `Yam
lList`')); | |
113 expect(e.yamlNode, new isInstanceOf<YamlList>()); | |
114 } | |
115 }); | |
116 }); | |
117 }); | |
118 }); | |
119 } | |
120 | |
121 PluginConfig parseConfig(String optionsSrc) { | |
122 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); | |
123 return new PluginConfig.fromOptions(options); | |
124 } | |
125 | |
126 List<PluginInfo> pluginsSortedByName(Iterable<PluginInfo> plugins) => | |
127 plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); | |
OLD | NEW |