Chromium Code Reviews| 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 test.src.plugin.plugin_config_test; | 5 library 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:unittest/unittest.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); | 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 test('plugin map (empty)', () { | 41 test('plugin map (empty)', () { |
| 41 const optionsSrc = ''' | 42 const optionsSrc = ''' |
| 42 analyzer: | 43 analyzer: |
| 43 plugins: | 44 plugins: |
| 44 # my_plugin1: ^0.1.0 #shorthand | 45 # my_plugin1: ^0.1.0 #shorthand |
| 45 '''; | 46 '''; |
| 46 var config = parseConfig(optionsSrc); | 47 var config = parseConfig(optionsSrc); |
| 47 // Commented out plugins shouldn't cause a parse failure. | 48 // Commented out plugins shouldn't cause a parse failure. |
| 48 expect(config.plugins, hasLength(0)); | 49 expect(config.plugins, hasLength(0)); |
| 49 }); | 50 }); |
| 51 | |
| 52 test('plugin manifest', () { | |
| 53 const manifestSrc = ''' | |
| 54 class_name: AnalyzerPlugin | |
| 55 library_uri: myplugin/analyzer_plugin.dart | |
|
Brian Wilkerson
2015/09/24 21:40:00
I suspect that in most cases the URI will be a "pa
pquitslund
2015/09/24 21:52:44
Will do. I want to add more validation for sure a
| |
| 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 | |
| 50 group('errors', () { | 81 group('errors', () { |
| 51 test('bad format', () { | 82 test('bad config format', () { |
| 52 const optionsSrc = ''' | 83 const optionsSrc = ''' |
| 53 analyzer: | 84 analyzer: |
| 54 plugins: | 85 plugins: |
| 55 - my_plugin1 | 86 - my_plugin1 |
| 56 - my_plugin2 | 87 - my_plugin2 |
| 57 '''; | 88 '''; |
| 58 try { | 89 try { |
| 59 parseConfig(optionsSrc); | 90 parseConfig(optionsSrc); |
| 60 fail('expected PluginConfigFormatException'); | 91 fail('expected PluginConfigFormatException'); |
| 61 } on PluginConfigFormatException catch (e) { | 92 } on PluginConfigFormatException catch (e) { |
| 62 expect( | 93 expect( |
| 63 e.message, | 94 e.message, |
| 64 equals( | 95 equals( |
| 65 'Unrecognized plugin config format (expected `YamlMap`, got `YamlList`)')); | 96 'Unrecognized plugin config format, expected `YamlMap`, got `YamlList`')); |
| 66 expect(e.yamlNode, new isInstanceOf<YamlList>()); | 97 expect(e.yamlNode, new isInstanceOf<YamlList>()); |
| 67 } | 98 } |
| 68 }); | 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 }); | |
| 69 }); | 116 }); |
| 70 }); | 117 }); |
| 71 }); | 118 }); |
| 72 } | 119 } |
| 73 | 120 |
| 74 PluginConfig parseConfig(String optionsSrc) { | 121 PluginConfig parseConfig(String optionsSrc) { |
| 75 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); | 122 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); |
| 76 return new PluginConfig.fromOptions(options); | 123 return new PluginConfig.fromOptions(options); |
| 77 } | 124 } |
| 78 | 125 |
| 79 List<PluginInfo> pluginsSortedByName(PluginConfig config) => | 126 List<PluginInfo> pluginsSortedByName(Iterable<PluginInfo> plugins) => |
| 80 config.plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); | 127 plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); |
| OLD | NEW |