Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: pkg/analyzer/test/src/plugin/plugin_config_test.dart

Issue 1366023002: Plugin manifest parsing. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 test('plugin map (empty)', () { 40 test('plugin map (empty)', () {
41 const optionsSrc = ''' 41 const optionsSrc = '''
42 analyzer: 42 analyzer:
43 plugins: 43 plugins:
44 # my_plugin1: ^0.1.0 #shorthand 44 # my_plugin1: ^0.1.0 #shorthand
45 '''; 45 ''';
46 var config = parseConfig(optionsSrc); 46 var config = parseConfig(optionsSrc);
47 // Commented out plugins shouldn't cause a parse failure. 47 // Commented out plugins shouldn't cause a parse failure.
48 expect(config.plugins, hasLength(0)); 48 expect(config.plugins, hasLength(0));
49 }); 49 });
50 test('plugin manifest', () {
51 const manifestSrc = '''
52 analyzer-plugin:
53 class_name: AnalyzerPlugin
54 library_uri: myplugin/analyzer_plugin.dart
55 server-plugin:
56 class_name: ServerPlugin
57 library_uri: myplugin/server_plugin.dart
58 ''';
59 var manifest = parsePluginManifestString(manifestSrc);
60 var analyzerPlugin = manifest.analyzerPlugin;
61 expect(
62 analyzerPlugin.libraryUri, equals('myplugin/analyzer_plugin.dart'));
63 expect(analyzerPlugin.className, equals('AnalyzerPlugin'));
64 var serverPlugin = manifest.serverPlugin;
65 expect(serverPlugin.libraryUri, equals('myplugin/server_plugin.dart'));
66 expect(serverPlugin.className, equals('ServerPlugin'));
67 });
50 group('errors', () { 68 group('errors', () {
51 test('bad format', () { 69 test('bad config format', () {
52 const optionsSrc = ''' 70 const optionsSrc = '''
53 analyzer: 71 analyzer:
54 plugins: 72 plugins:
55 - my_plugin1 73 - my_plugin1
56 - my_plugin2 74 - my_plugin2
57 '''; 75 ''';
58 try { 76 try {
59 parseConfig(optionsSrc); 77 parseConfig(optionsSrc);
60 fail('expected PluginConfigFormatException'); 78 fail('expected PluginConfigFormatException');
61 } on PluginConfigFormatException catch (e) { 79 } on PluginConfigFormatException catch (e) {
62 expect( 80 expect(
63 e.message, 81 e.message,
64 equals( 82 equals(
65 'Unrecognized plugin config format (expected `YamlMap`, got `YamlList`)')); 83 'Unrecognized plugin config format, expected `YamlMap`, got `YamlList`'));
66 expect(e.yamlNode, new isInstanceOf<YamlList>()); 84 expect(e.yamlNode, new isInstanceOf<YamlList>());
67 } 85 }
68 }); 86 });
87 test('bad manifest format', () {
88 const manifestSource = '''
89 analyzer-plugin:
90 - Foo
91 ''';
92 try {
93 parsePluginManifestString(manifestSource);
94 fail('expected PluginConfigFormatException');
95 } on PluginConfigFormatException catch (e) {
96 expect(
97 e.message,
98 equals(
99 'Unable to parse plugin manifest, expected `YamlMap`, got `Y amlList`'));
100 expect(e.yamlNode, new isInstanceOf<YamlList>());
101 }
102 });
69 }); 103 });
70 }); 104 });
71 }); 105 });
72 } 106 }
73 107
74 PluginConfig parseConfig(String optionsSrc) { 108 PluginConfig parseConfig(String optionsSrc) {
75 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); 109 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc);
76 return new PluginConfig.fromOptions(options); 110 return new PluginConfig.fromOptions(options);
77 } 111 }
78 112
79 List<PluginInfo> pluginsSortedByName(PluginConfig config) => 113 List<PluginInfo> pluginsSortedByName(Iterable<PluginInfo> plugins) =>
80 config.plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); 114 plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name));
OLDNEW
« pkg/analyzer/lib/src/plugin/plugin_configuration.dart ('K') | « pkg/analyzer/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698