OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 library analyzer.test.src.plugin.plugin_config_test; | 5 library analyzer.test.src.plugin.plugin_config_test; |
6 | 6 |
7 import 'package:analyzer/source/analysis_options_provider.dart'; | 7 import 'package:analyzer/source/analysis_options_provider.dart'; |
8 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | 8 import 'package:analyzer/src/plugin/plugin_configuration.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:test/test.dart'; |
10 import 'package:yaml/yaml.dart'; | 10 import 'package:yaml/yaml.dart'; |
11 | 11 |
12 main() { | 12 main() { |
13 group('plugin config tests', () { | 13 group('plugin config tests', () { |
14 group('parsing', () { | 14 group('parsing', () { |
15 test('plugin map', () { | 15 test('plugin map', () { |
16 const optionsSrc = ''' | 16 const optionsSrc = ''' |
17 analyzer: | 17 analyzer: |
18 plugins: | 18 plugins: |
19 my_plugin1: ^0.1.0 #shorthand | 19 my_plugin1: ^0.1.0 #shorthand |
20 my_plugin2: | 20 my_plugin2: |
21 version: ^0.2.0 | 21 version: ^0.2.0 |
22 my_plugin3: | 22 my_plugin3: |
23 class_name: MyPlugin | 23 class_name: MyPlugin |
24 library_uri: myplugin/myplugin.dart | 24 library_uri: myplugin/myplugin.dart |
25 path: '/u/disk/src/' | 25 path: '/u/disk/src/' |
26 '''; | 26 '''; |
27 var config = parseConfig(optionsSrc); | 27 var config = parseConfig(optionsSrc); |
28 var plugins = pluginsSortedByName(config.plugins); | 28 var plugins = pluginsSortedByName(config.plugins); |
29 expect(plugins, hasLength(3)); | 29 expect(plugins, hasLength(3)); |
30 expect(plugins[0].name, equals('my_plugin1')); | 30 expect(plugins[0].name, equals('my_plugin1')); |
31 expect(plugins[0].version, equals('^0.1.0')); | 31 expect(plugins[0].version, equals('^0.1.0')); |
32 expect(plugins[1].name, equals('my_plugin2')); | 32 expect(plugins[1].name, equals('my_plugin2')); |
33 expect(plugins[1].version, equals('^0.2.0')); | 33 expect(plugins[1].version, equals('^0.2.0')); |
34 expect(plugins[2].name, equals('my_plugin3')); | 34 expect(plugins[2].name, equals('my_plugin3')); |
35 expect(plugins[2].version, isNull); | 35 expect(plugins[2].version, isNull); |
36 expect(plugins[2].path, equals('/u/disk/src/')); | 36 expect(plugins[2].path, equals('/u/disk/src/')); |
37 expect(plugins[2].libraryUri, equals('myplugin/myplugin.dart')); | 37 expect(plugins[2].libraryUri, equals('myplugin/myplugin.dart')); |
38 expect(plugins[2].className, equals('MyPlugin')); | 38 expect(plugins[2].className, equals('MyPlugin')); |
39 }); | 39 }); |
40 | 40 |
41 test('plugin map (empty)', () { | 41 test('plugin map (empty)', () { |
42 const optionsSrc = ''' | 42 const optionsSrc = ''' |
43 analyzer: | 43 analyzer: |
44 plugins: | 44 plugins: |
45 # my_plugin1: ^0.1.0 #shorthand | 45 # my_plugin1: ^0.1.0 #shorthand |
46 '''; | 46 '''; |
47 var config = parseConfig(optionsSrc); | 47 var config = parseConfig(optionsSrc); |
48 // Commented out plugins shouldn't cause a parse failure. | 48 // Commented out plugins shouldn't cause a parse failure. |
49 expect(config.plugins, hasLength(0)); | 49 expect(config.plugins, hasLength(0)); |
50 }); | 50 }); |
51 | 51 |
52 test('plugin manifest', () { | 52 test('plugin manifest', () { |
53 const manifestSrc = ''' | 53 const manifestSrc = ''' |
54 class_name: AnalyzerPlugin | 54 class_name: AnalyzerPlugin |
55 library_uri: myplugin/analyzer_plugin.dart | 55 library_uri: myplugin/analyzer_plugin.dart |
56 contributes_to: analyzer | 56 contributes_to: analyzer |
57 '''; | 57 '''; |
58 var manifest = parsePluginManifestString(manifestSrc); | 58 var manifest = parsePluginManifestString(manifestSrc); |
59 var plugin = manifest.plugin; | 59 var plugin = manifest.plugin; |
60 expect(plugin.libraryUri, equals('myplugin/analyzer_plugin.dart')); | 60 expect(plugin.libraryUri, equals('myplugin/analyzer_plugin.dart')); |
61 expect(plugin.className, equals('AnalyzerPlugin')); | 61 expect(plugin.className, equals('AnalyzerPlugin')); |
62 expect(manifest.contributesTo, unorderedEquals(['analyzer'])); | 62 expect(manifest.contributesTo, unorderedEquals(['analyzer'])); |
63 }); | 63 }); |
64 | 64 |
65 test('plugin manifest (contributes_to list)', () { | 65 test('plugin manifest (contributes_to list)', () { |
66 const manifestSrc = ''' | 66 const manifestSrc = ''' |
67 class_name: AnalyzerPlugin | 67 class_name: AnalyzerPlugin |
68 library_uri: myplugin/analyzer_plugin.dart | 68 library_uri: myplugin/analyzer_plugin.dart |
69 contributes_to: | 69 contributes_to: |
70 - analyzer | 70 - analyzer |
71 - analysis_server | 71 - analysis_server |
72 '''; | 72 '''; |
73 var manifest = parsePluginManifestString(manifestSrc); | 73 var manifest = parsePluginManifestString(manifestSrc); |
74 var plugin = manifest.plugin; | 74 var plugin = manifest.plugin; |
75 expect(plugin.libraryUri, equals('myplugin/analyzer_plugin.dart')); | 75 expect(plugin.libraryUri, equals('myplugin/analyzer_plugin.dart')); |
76 expect(plugin.className, equals('AnalyzerPlugin')); | 76 expect(plugin.className, equals('AnalyzerPlugin')); |
77 expect(manifest.contributesTo, | 77 expect(manifest.contributesTo, |
78 unorderedEquals(['analyzer', 'analysis_server'])); | 78 unorderedEquals(['analyzer', 'analysis_server'])); |
79 }); | 79 }); |
80 | 80 |
81 group('errors', () { | 81 group('errors', () { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 }); | 118 }); |
119 } | 119 } |
120 | 120 |
121 PluginConfig parseConfig(String optionsSrc) { | 121 PluginConfig parseConfig(String optionsSrc) { |
122 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); | 122 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); |
123 return new PluginConfig.fromOptions(options); | 123 return new PluginConfig.fromOptions(options); |
124 } | 124 } |
125 | 125 |
126 List<PluginInfo> pluginsSortedByName(Iterable<PluginInfo> plugins) => | 126 List<PluginInfo> pluginsSortedByName(Iterable<PluginInfo> plugins) => |
127 plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); | 127 plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); |
OLD | NEW |