| 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 @TestOn("vm") | 5 @TestOn("vm") |
| 6 library analyzer_cli.test.driver; | 6 library analyzer_cli.test.driver; |
| 7 | 7 |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analyzer/plugin/options.dart'; | 10 import 'package:analyzer/plugin/options.dart'; |
| 11 import 'package:analyzer_cli/src/bootloader.dart'; |
| 11 import 'package:analyzer_cli/src/driver.dart'; | 12 import 'package:analyzer_cli/src/driver.dart'; |
| 12 import 'package:linter/src/plugin/linter_plugin.dart'; | 13 import 'package:linter/src/plugin/linter_plugin.dart'; |
| 13 import 'package:path/path.dart' as path; | 14 import 'package:path/path.dart' as path; |
| 14 import 'package:plugin/plugin.dart'; | 15 import 'package:plugin/plugin.dart'; |
| 15 import 'package:test/test.dart'; | 16 import 'package:test/test.dart'; |
| 16 import 'package:yaml/src/yaml_node.dart'; | 17 import 'package:yaml/src/yaml_node.dart'; |
| 17 | 18 |
| 18 main() { | 19 main() { |
| 19 group('Driver', () { | 20 group('Driver', () { |
| 20 group('options', () { | 21 group('options', () { |
| 21 test('custom processor', () { | 22 test('custom processor', () { |
| 22 Driver driver = new Driver(); | 23 Driver driver = new Driver(); |
| 23 TestProcessor processor = new TestProcessor(); | 24 TestProcessor processor = new TestProcessor(); |
| 24 driver.userDefinedPlugins = [new TestPlugin(processor)]; | 25 driver.userDefinedPlugins = [new TestPlugin(processor)]; |
| 25 driver.start([ | 26 driver.start([ |
| 26 '--options', | 27 '--options', |
| 27 'test/data/test_options.yaml', | 28 'test/data/test_options.yaml', |
| 28 'test/data/test_file.dart' | 29 'test/data/test_file.dart' |
| 29 ]); | 30 ]); |
| 30 expect(processor.options['test_plugin'], isNotNull); | 31 expect(processor.options['test_plugin'], isNotNull); |
| 31 expect(processor.exception, isNull); | 32 expect(processor.exception, isNull); |
| 32 }); | 33 }); |
| 33 group('plugin processing', () { | |
| 34 StringSink savedErrorSink; | |
| 35 setUp(() { | |
| 36 savedErrorSink = errorSink; | |
| 37 errorSink = new StringBuffer(); | |
| 38 }); | |
| 39 tearDown(() { | |
| 40 errorSink = savedErrorSink; | |
| 41 }); | |
| 42 test('bad format', () { | |
| 43 Driver driver = new Driver(); | |
| 44 driver.start([ | |
| 45 '--options', | |
| 46 'test/data/bad_plugin_options.yaml', | |
| 47 'test/data/test_file.dart' | |
| 48 ]); | |
| 49 expect( | |
| 50 errorSink.toString(), | |
| 51 equals( | |
| 52 'Plugin configuration skipped: Unrecognized plugin config form
at, expected `YamlMap`, got `YamlList` (line 2, column 4)\n')); | |
| 53 }); | |
| 54 test('plugin config', () { | |
| 55 Driver driver = new Driver(); | |
| 56 driver.start([ | |
| 57 '--options', | |
| 58 'test/data/plugin_options.yaml', | |
| 59 'test/data/test_file.dart' | |
| 60 ]); | |
| 61 var plugins = driver.pluginConfig.plugins; | |
| 62 expect(plugins, hasLength(1)); | |
| 63 expect(plugins.first.name, equals('my_plugin1')); | |
| 64 }); | |
| 65 }); | |
| 66 }); | 34 }); |
| 67 | 35 |
| 68 group('linter', () { | 36 group('linter', () { |
| 69 test('gets analysis options', () { | 37 test('gets analysis options', () { |
| 70 Driver driver = new Driver(); | 38 Driver driver = new Driver(); |
| 71 driver.start([ | 39 driver.start([ |
| 72 '--options', | 40 '--options', |
| 73 'test/data/linter_project/.analysis_options', | 41 'test/data/linter_project/.analysis_options', |
| 74 '--lints', | 42 '--lints', |
| 75 'test/data/linter_project/test_file.dart' | 43 'test/data/linter_project/test_file.dart' |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 new Driver().start(['--package-root', 'does/not/exist', 'test.dart']); | 112 new Driver().start(['--package-root', 'does/not/exist', 'test.dart']); |
| 145 String stdout = outSink.toString(); | 113 String stdout = outSink.toString(); |
| 146 expect(exitCode, 3); | 114 expect(exitCode, 3); |
| 147 expect( | 115 expect( |
| 148 stdout, | 116 stdout, |
| 149 contains( | 117 contains( |
| 150 'Package root directory (does/not/exist) does not exist.')); | 118 'Package root directory (does/not/exist) does not exist.')); |
| 151 }); | 119 }); |
| 152 }); | 120 }); |
| 153 }); | 121 }); |
| 122 group('Bootloader', () { |
| 123 group('plugin processing', () { |
| 124 StringSink savedErrorSink; |
| 125 setUp(() { |
| 126 savedErrorSink = errorSink; |
| 127 errorSink = new StringBuffer(); |
| 128 }); |
| 129 tearDown(() { |
| 130 errorSink = savedErrorSink; |
| 131 }); |
| 132 test('bad format', () { |
| 133 BootLoader loader = new BootLoader(); |
| 134 loader.createImage([ |
| 135 '--options', |
| 136 'test/data/bad_plugin_options.yaml', |
| 137 'test/data/test_file.dart' |
| 138 ]); |
| 139 expect( |
| 140 errorSink.toString(), |
| 141 equals( |
| 142 'Plugin configuration skipped: Unrecognized plugin config format
, expected `YamlMap`, got `YamlList` (line 2, column 4)\n')); |
| 143 }); |
| 144 test('plugin config', () { |
| 145 BootLoader loader = new BootLoader(); |
| 146 Image image = loader.createImage([ |
| 147 '--options', |
| 148 'test/data/plugin_options.yaml', |
| 149 'test/data/test_file.dart' |
| 150 ]); |
| 151 var plugins = image.config.plugins; |
| 152 expect(plugins, hasLength(1)); |
| 153 expect(plugins.first.name, equals('my_plugin1')); |
| 154 }); |
| 155 }); |
| 156 }); |
| 154 } | 157 } |
| 155 | 158 |
| 156 class TestPlugin extends Plugin { | 159 class TestPlugin extends Plugin { |
| 157 TestProcessor processor; | 160 TestProcessor processor; |
| 158 TestPlugin(this.processor); | 161 TestPlugin(this.processor); |
| 159 | 162 |
| 160 @override | 163 @override |
| 161 String get uniqueIdentifier => 'test_plugin.core'; | 164 String get uniqueIdentifier => 'test_plugin.core'; |
| 162 | 165 |
| 163 @override | 166 @override |
| (...skipping 14 matching lines...) Expand all Loading... |
| 178 @override | 181 @override |
| 179 void onError(Exception exception) { | 182 void onError(Exception exception) { |
| 180 this.exception = exception; | 183 this.exception = exception; |
| 181 } | 184 } |
| 182 | 185 |
| 183 @override | 186 @override |
| 184 void optionsProcessed(Map<String, YamlNode> options) { | 187 void optionsProcessed(Map<String, YamlNode> options) { |
| 185 this.options = options; | 188 this.options = options; |
| 186 } | 189 } |
| 187 } | 190 } |
| OLD | NEW |