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_cli.test.driver; | 5 library analyzer_cli.test.driver; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:analyzer/plugin/options.dart'; | 9 import 'package:analyzer/plugin/options.dart'; |
10 import 'package:analyzer/source/analysis_options_provider.dart'; | 10 import 'package:analyzer/source/analysis_options_provider.dart'; |
11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
12 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
14 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | 14 import 'package:analyzer/src/plugin/plugin_configuration.dart'; |
15 import 'package:analyzer/src/services/lint.dart'; | 15 import 'package:analyzer/src/services/lint.dart'; |
16 import 'package:analyzer_cli/src/bootloader.dart'; | 16 import 'package:analyzer_cli/src/bootloader.dart'; |
17 import 'package:analyzer_cli/src/driver.dart'; | 17 import 'package:analyzer_cli/src/driver.dart'; |
18 import 'package:analyzer_cli/src/options.dart'; | 18 import 'package:analyzer_cli/src/options.dart'; |
19 import 'package:path/path.dart' as path; | 19 import 'package:path/path.dart' as path; |
20 import 'package:plugin/plugin.dart'; | 20 import 'package:plugin/plugin.dart'; |
21 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
22 import 'package:yaml/src/yaml_node.dart'; | 22 import 'package:yaml/src/yaml_node.dart'; |
23 | 23 |
24 // TODO(pq): fix tests to run safely on the bots | 24 import 'utils.dart'; |
25 // https://github.com/dart-lang/sdk/issues/25001 | |
26 main() {} | |
27 const emptyOptionsFile = 'test/data/empty_options.yaml'; | |
28 | 25 |
29 /// Start a driver for the given [source], optionally providing additional | 26 main() { |
30 /// [args] and an [options] file path. The value of [options] defaults to | 27 StringSink savedOutSink, savedErrorSink; |
31 /// an empty options file to avoid unwanted configuration from an otherwise | 28 int savedExitCode; |
32 /// discovered options file. | 29 ExitHandler savedExitHandler; |
33 void drive(String source, | |
34 {String options: emptyOptionsFile, | |
35 List<String> args: const <String>[]}) => | |
36 new Driver().start(['--options', options, source]..addAll(args)); | |
37 | 30 |
38 not_main() { | 31 /// Base setup. |
| 32 _setUp() { |
| 33 savedOutSink = outSink; |
| 34 savedErrorSink = errorSink; |
| 35 savedExitHandler = exitHandler; |
| 36 savedExitCode = exitCode; |
| 37 exitHandler = (code) => exitCode = code; |
| 38 outSink = new StringBuffer(); |
| 39 errorSink = new StringBuffer(); |
| 40 } |
| 41 |
| 42 /// Base teardown. |
| 43 _tearDown() { |
| 44 outSink = savedOutSink; |
| 45 errorSink = savedErrorSink; |
| 46 exitCode = savedExitCode; |
| 47 exitHandler = savedExitHandler; |
| 48 } |
| 49 |
| 50 setUp(() => _setUp()); |
| 51 |
| 52 tearDown(() => _tearDown()); |
| 53 |
39 group('Driver', () { | 54 group('Driver', () { |
40 StringSink savedOutSink, savedErrorSink; | |
41 int savedExitCode; | |
42 setUp(() { | |
43 savedOutSink = outSink; | |
44 savedErrorSink = errorSink; | |
45 savedExitCode = exitCode; | |
46 outSink = new StringBuffer(); | |
47 errorSink = new StringBuffer(); | |
48 }); | |
49 tearDown(() { | |
50 outSink = savedOutSink; | |
51 errorSink = savedErrorSink; | |
52 exitCode = savedExitCode; | |
53 }); | |
54 | |
55 group('options', () { | 55 group('options', () { |
56 test('custom processor', () { | 56 test('custom processor', () { |
57 Driver driver = new Driver(); | 57 Driver driver = new Driver(); |
58 TestProcessor processor = new TestProcessor(); | 58 TestProcessor processor = new TestProcessor(); |
59 driver.userDefinedPlugins = [new TestPlugin(processor)]; | 59 driver.userDefinedPlugins = [new TestPlugin(processor)]; |
60 driver.start([ | 60 driver.start([ |
61 '--options', | 61 '--options', |
62 'test/data/test_options.yaml', | 62 path.join(testDirectory, 'data/test_options.yaml'), |
63 'test/data/test_file.dart' | 63 path.join(testDirectory, 'data/test_file.dart') |
64 ]); | 64 ]); |
65 expect(processor.options['test_plugin'], isNotNull); | 65 expect(processor.options['test_plugin'], isNotNull); |
66 expect(processor.exception, isNull); | 66 expect(processor.exception, isNull); |
67 }); | 67 }); |
68 }); | 68 }); |
69 | 69 |
| 70 //TODO(pq): refactor to NOT set actual error codes to play nice with bots |
70 group('exit codes', () { | 71 group('exit codes', () { |
71 StringSink savedOutSink, savedErrorSink; | |
72 int savedExitCode; | |
73 ExitHandler savedExitHandler; | |
74 setUp(() { | |
75 savedOutSink = outSink; | |
76 savedErrorSink = errorSink; | |
77 savedExitCode = exitCode; | |
78 savedExitHandler = exitHandler; | |
79 exitHandler = (code) => exitCode = code; | |
80 outSink = new StringBuffer(); | |
81 errorSink = new StringBuffer(); | |
82 }); | |
83 tearDown(() { | |
84 outSink = savedOutSink; | |
85 errorSink = savedErrorSink; | |
86 exitCode = savedExitCode; | |
87 exitHandler = savedExitHandler; | |
88 }); | |
89 | |
90 test('fatal hints', () { | 72 test('fatal hints', () { |
91 drive('test/data/file_with_hint.dart', args: ['--fatal-hints']); | 73 drive('data/file_with_hint.dart', args: ['--fatal-hints']); |
92 expect(exitCode, 3); | 74 expect(exitCode, 3); |
93 }); | 75 }); |
94 | 76 |
95 test('not fatal hints', () { | 77 test('not fatal hints', () { |
96 drive('test/data/file_with_hint.dart'); | 78 drive('data/file_with_hint.dart'); |
97 expect(exitCode, 0); | 79 expect(exitCode, 0); |
98 }); | 80 }); |
99 | 81 |
100 test('fatal errors', () { | 82 test('fatal errors', () { |
101 drive('test/data/file_with_error.dart'); | 83 drive('data/file_with_error.dart'); |
102 expect(exitCode, 3); | 84 expect(exitCode, 3); |
103 }); | 85 }); |
104 | 86 |
105 test('not fatal warnings', () { | 87 test('not fatal warnings', () { |
106 drive('test/data/file_with_warning.dart'); | 88 drive('data/file_with_warning.dart'); |
107 expect(exitCode, 0); | 89 expect(exitCode, 0); |
108 }); | 90 }); |
109 | 91 |
110 test('fatal warnings', () { | 92 test('fatal warnings', () { |
111 drive('test/data/file_with_warning.dart', args: ['--fatal-warnings']); | 93 drive('data/file_with_warning.dart', args: ['--fatal-warnings']); |
112 expect(exitCode, 3); | 94 expect(exitCode, 3); |
113 }); | 95 }); |
114 | 96 |
115 test('missing options file', () { | 97 test('missing options file', () { |
116 drive('test/data/test_file.dart', options: 'test/data/NO_OPTIONS_HERE'); | 98 drive('data/test_file.dart', options: 'data/NO_OPTIONS_HERE'); |
117 expect(exitCode, 3); | 99 expect(exitCode, 3); |
118 }); | 100 }); |
119 | 101 |
120 test('missing dart file', () { | 102 test('missing dart file', () { |
121 drive('test/data/NO_DART_FILE_HERE.dart'); | 103 drive('data/NO_DART_FILE_HERE.dart'); |
122 expect(exitCode, 3); | 104 expect(exitCode, 3); |
123 }); | 105 }); |
124 | 106 |
125 test('part file', () { | 107 test('part file', () { |
126 drive('test/data/library_and_parts/part2.dart'); | 108 drive('data/library_and_parts/part2.dart'); |
127 expect(exitCode, 3); | 109 expect(exitCode, 3); |
128 }); | 110 }); |
129 | 111 |
130 test('non-dangling part file', () { | 112 test('non-dangling part file', () { |
131 Driver driver = new Driver(); | 113 Driver driver = new Driver(); |
132 driver.start([ | 114 driver.start([ |
133 'test/data/library_and_parts/lib.dart', | 115 path.join(testDirectory, 'data/library_and_parts/lib.dart'), |
134 'test/data/library_and_parts/part1.dart', | 116 path.join(testDirectory, 'data/library_and_parts/part1.dart') |
135 ]); | 117 ]); |
136 expect(exitCode, 0); | 118 expect(exitCode, 0); |
137 }); | 119 }); |
138 | 120 |
139 test('extra part file', () { | 121 test('extra part file', () { |
140 Driver driver = new Driver(); | 122 Driver driver = new Driver(); |
141 driver.start([ | 123 driver.start([ |
142 'test/data/library_and_parts/lib.dart', | 124 path.join(testDirectory, 'data/library_and_parts/lib.dart'), |
143 'test/data/library_and_parts/part1.dart', | 125 path.join(testDirectory, 'data/library_and_parts/part1.dart'), |
144 'test/data/library_and_parts/part2.dart', | 126 path.join(testDirectory, 'data/library_and_parts/part2.dart') |
145 ]); | 127 ]); |
146 expect(exitCode, 3); | 128 expect(exitCode, 3); |
147 }); | 129 }); |
148 }); | 130 }); |
149 | 131 |
150 group('linter', () { | 132 group('linter', () { |
151 group('lints in options', () { | 133 group('lints in options', () { |
152 StringSink savedOutSink; | 134 // Shared lint command. |
153 Driver driver; | 135 var runLinter = () => drive('data/linter_project/test_file.dart', |
154 | 136 options: 'data/linter_project/.analysis_options', |
155 setUp(() { | 137 args: ['--lints']); |
156 savedOutSink = outSink; | |
157 outSink = new StringBuffer(); | |
158 | |
159 driver = new Driver(); | |
160 driver.start([ | |
161 '--options', | |
162 'test/data/linter_project/.analysis_options', | |
163 '--lints', | |
164 'test/data/linter_project/test_file.dart' | |
165 ]); | |
166 }); | |
167 tearDown(() { | |
168 outSink = savedOutSink; | |
169 }); | |
170 | 138 |
171 test('gets analysis options', () { | 139 test('gets analysis options', () { |
| 140 runLinter(); |
| 141 |
172 /// Lints should be enabled. | 142 /// Lints should be enabled. |
173 expect(driver.context.analysisOptions.lint, isTrue); | 143 expect(driver.context.analysisOptions.lint, isTrue); |
174 | 144 |
175 /// The .analysis_options file only specifies 'camel_case_types'. | 145 /// The .analysis_options file only specifies 'camel_case_types'. |
176 var lintNames = getLints(driver.context).map((r) => r.name); | 146 var lintNames = getLints(driver.context).map((r) => r.name); |
177 expect(lintNames, orderedEquals(['camel_case_types'])); | 147 expect(lintNames, orderedEquals(['camel_case_types'])); |
178 }); | 148 }); |
179 | 149 |
180 test('generates lints', () { | 150 test('generates lints', () { |
| 151 runLinter(); |
181 expect(outSink.toString(), | 152 expect(outSink.toString(), |
182 contains('[lint] Name types using UpperCamelCase.')); | 153 contains('[lint] Name types using UpperCamelCase.')); |
183 }); | 154 }); |
184 }); | 155 }); |
185 | 156 |
186 group('default lints', () { | 157 group('default lints', () { |
187 StringSink savedOutSink; | 158 // Shared lint command. |
188 Driver driver; | 159 var runLinter = () => drive('data/linter_project/test_file.dart', |
189 | 160 options: 'data/linter_project/.analysis_options', |
190 setUp(() { | 161 args: ['--lints']); |
191 savedOutSink = outSink; | |
192 outSink = new StringBuffer(); | |
193 | |
194 driver = new Driver(); | |
195 driver.start([ | |
196 '--lints', | |
197 'test/data/linter_project/test_file.dart', | |
198 '--options', | |
199 'test/data/linter_project/.analysis_options' | |
200 ]); | |
201 }); | |
202 tearDown(() { | |
203 outSink = savedOutSink; | |
204 }); | |
205 | 162 |
206 test('gets default lints', () { | 163 test('gets default lints', () { |
| 164 runLinter(); |
| 165 |
207 /// Lints should be enabled. | 166 /// Lints should be enabled. |
208 expect(driver.context.analysisOptions.lint, isTrue); | 167 expect(driver.context.analysisOptions.lint, isTrue); |
209 | 168 |
210 /// Default list should include camel_case_types. | 169 /// Default list should include camel_case_types. |
211 var lintNames = getLints(driver.context).map((r) => r.name); | 170 var lintNames = getLints(driver.context).map((r) => r.name); |
212 expect(lintNames, contains('camel_case_types')); | 171 expect(lintNames, contains('camel_case_types')); |
213 }); | 172 }); |
214 | 173 |
215 test('generates lints', () { | 174 test('generates lints', () { |
| 175 runLinter(); |
216 expect(outSink.toString(), | 176 expect(outSink.toString(), |
217 contains('[lint] Name types using UpperCamelCase.')); | 177 contains('[lint] Name types using UpperCamelCase.')); |
218 }); | 178 }); |
219 }); | 179 }); |
220 | 180 |
221 group('no `--lints` flag (none in options)', () { | 181 group('no `--lints` flag (none in options)', () { |
222 StringSink savedOutSink; | 182 // Shared lint command. |
223 Driver driver; | 183 var runLinter = () => drive('data/no_lints_project/test_file.dart', |
224 | 184 options: 'data/no_lints_project/.analysis_options'); |
225 setUp(() { | |
226 savedOutSink = outSink; | |
227 outSink = new StringBuffer(); | |
228 | |
229 driver = new Driver(); | |
230 driver.start([ | |
231 'test/data/no_lints_project/test_file.dart', | |
232 '--options', | |
233 'test/data/no_lints_project/.analysis_options' | |
234 ]); | |
235 }); | |
236 tearDown(() { | |
237 outSink = savedOutSink; | |
238 }); | |
239 | 185 |
240 test('lints disabled', () { | 186 test('lints disabled', () { |
| 187 runLinter(); |
241 expect(driver.context.analysisOptions.lint, isFalse); | 188 expect(driver.context.analysisOptions.lint, isFalse); |
242 }); | 189 }); |
243 | 190 |
244 test('no registered lints', () { | 191 test('no registered lints', () { |
| 192 runLinter(); |
245 expect(getLints(driver.context), isEmpty); | 193 expect(getLints(driver.context), isEmpty); |
246 }); | 194 }); |
247 | 195 |
248 test('no generated warnings', () { | 196 test('no generated warnings', () { |
| 197 runLinter(); |
249 expect(outSink.toString(), contains('No issues found')); | 198 expect(outSink.toString(), contains('No issues found')); |
250 }); | 199 }); |
251 }); | 200 }); |
252 }); | 201 }); |
253 | 202 |
254 test('containsLintRuleEntry', () { | 203 test('containsLintRuleEntry', () { |
255 Map<String, YamlNode> options; | 204 Map<String, YamlNode> options; |
256 options = parseOptions(''' | 205 options = parseOptions(''' |
257 linter: | 206 linter: |
258 rules: | 207 rules: |
(...skipping 11 matching lines...) Expand all Loading... |
270 expect(containsLintRuleEntry(options), true); | 219 expect(containsLintRuleEntry(options), true); |
271 options = parseOptions(''' | 220 options = parseOptions(''' |
272 linter: | 221 linter: |
273 # rules: | 222 # rules: |
274 # - foo | 223 # - foo |
275 '''); | 224 '''); |
276 expect(containsLintRuleEntry(options), false); | 225 expect(containsLintRuleEntry(options), false); |
277 }); | 226 }); |
278 | 227 |
279 group('options processing', () { | 228 group('options processing', () { |
| 229 // Shared driver command. |
| 230 var doDrive = () => drive('data/options_tests_project/test_file.dart', |
| 231 options: 'data/options_tests_project/.analysis_options'); |
| 232 |
280 group('error filters', () { | 233 group('error filters', () { |
281 StringSink savedOutSink; | |
282 Driver driver; | |
283 | |
284 setUp(() { | |
285 savedOutSink = outSink; | |
286 outSink = new StringBuffer(); | |
287 | |
288 driver = new Driver(); | |
289 driver.start([ | |
290 'test/data/options_tests_project/test_file.dart', | |
291 '--options', | |
292 'test/data/options_tests_project/.analysis_options' | |
293 ]); | |
294 }); | |
295 tearDown(() { | |
296 outSink = savedOutSink; | |
297 }); | |
298 | |
299 test('filters', () { | 234 test('filters', () { |
| 235 doDrive(); |
300 var processors = | 236 var processors = |
301 driver.context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); | 237 driver.context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); |
302 expect(processors, hasLength(1)); | 238 expect(processors, hasLength(1)); |
303 | 239 |
304 var unused_local_variable = new AnalysisError( | 240 var unused_local_variable = new AnalysisError( |
305 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ | 241 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
306 ['x'] | 242 ['x'] |
307 ]); | 243 ]); |
308 | 244 |
309 var unusedLocalVariable = | 245 var unusedLocalVariable = |
310 processors.firstWhere((p) => p.appliesTo(unused_local_variable)); | 246 processors.firstWhere((p) => p.appliesTo(unused_local_variable)); |
311 expect(unusedLocalVariable.severity, isNull); | 247 expect(unusedLocalVariable.severity, isNull); |
312 }); | 248 }); |
313 | 249 |
314 test('language config', () { | 250 test('language config', () { |
| 251 doDrive(); |
315 expect(driver.context.analysisOptions.enableSuperMixins, isTrue); | 252 expect(driver.context.analysisOptions.enableSuperMixins, isTrue); |
316 }); | 253 }); |
317 }); | 254 }); |
318 }); | 255 }); |
319 | 256 |
320 group('in temp directory', () { | 257 group('in temp directory', () { |
321 StringSink savedOutSink, savedErrorSink; | |
322 int savedExitCode; | |
323 Directory savedCurrentDirectory; | 258 Directory savedCurrentDirectory; |
324 Directory tempDir; | 259 Directory tempDir; |
325 setUp(() { | 260 setUp(() { |
326 savedOutSink = outSink; | 261 // Call base setUp. |
327 savedErrorSink = errorSink; | 262 _setUp(); |
328 savedExitCode = exitCode; | |
329 outSink = new StringBuffer(); | |
330 errorSink = new StringBuffer(); | |
331 savedCurrentDirectory = Directory.current; | 263 savedCurrentDirectory = Directory.current; |
332 tempDir = Directory.systemTemp.createTempSync('analyzer_'); | 264 tempDir = Directory.systemTemp.createTempSync('analyzer_'); |
333 }); | 265 }); |
334 tearDown(() { | 266 tearDown(() { |
335 outSink = savedOutSink; | |
336 errorSink = savedErrorSink; | |
337 exitCode = savedExitCode; | |
338 Directory.current = savedCurrentDirectory; | 267 Directory.current = savedCurrentDirectory; |
339 tempDir.deleteSync(recursive: true); | 268 tempDir.deleteSync(recursive: true); |
| 269 // Call base tearDown. |
| 270 _tearDown(); |
340 }); | 271 }); |
341 | 272 |
342 test('packages folder', () { | 273 test('packages folder', () { |
343 Directory.current = tempDir; | 274 Directory.current = tempDir; |
344 new File(path.join(tempDir.path, 'test.dart')).writeAsStringSync(''' | 275 new File(path.join(tempDir.path, 'test.dart')).writeAsStringSync(''' |
345 import 'package:foo/bar.dart'; | 276 import 'package:foo/bar.dart'; |
346 main() { | 277 main() { |
347 baz(); | 278 baz(); |
348 } | 279 } |
349 '''); | 280 '''); |
(...skipping 29 matching lines...) Expand all Loading... |
379 expect(exitCode, 3); | 310 expect(exitCode, 3); |
380 expect( | 311 expect( |
381 stdout, | 312 stdout, |
382 contains( | 313 contains( |
383 'Package root directory (does/not/exist) does not exist.')); | 314 'Package root directory (does/not/exist) does not exist.')); |
384 }); | 315 }); |
385 }); | 316 }); |
386 }); | 317 }); |
387 group('Bootloader', () { | 318 group('Bootloader', () { |
388 group('plugin processing', () { | 319 group('plugin processing', () { |
389 StringSink savedErrorSink; | |
390 setUp(() { | |
391 savedErrorSink = errorSink; | |
392 errorSink = new StringBuffer(); | |
393 }); | |
394 tearDown(() { | |
395 errorSink = savedErrorSink; | |
396 }); | |
397 test('bad format', () { | 320 test('bad format', () { |
398 BootLoader loader = new BootLoader(); | 321 BootLoader loader = new BootLoader(); |
399 loader.createImage([ | 322 loader.createImage([ |
400 '--options', | 323 '--options', |
401 'test/data/bad_plugin_options.yaml', | 324 path.join(testDirectory, 'data/bad_plugin_options.yaml'), |
402 'test/data/test_file.dart' | 325 path.join(testDirectory, 'data/test_file.dart') |
403 ]); | 326 ]); |
404 expect( | 327 expect( |
405 errorSink.toString(), | 328 errorSink.toString(), |
406 equals('Plugin configuration skipped: Unrecognized plugin config ' | 329 equals('Plugin configuration skipped: Unrecognized plugin config ' |
407 'format, expected `YamlMap`, got `YamlList` ' | 330 'format, expected `YamlMap`, got `YamlList` ' |
408 '(line 2, column 4)\n')); | 331 '(line 2, column 4)\n')); |
409 }); | 332 }); |
410 test('plugin config', () { | 333 test('plugin config', () { |
411 BootLoader loader = new BootLoader(); | 334 BootLoader loader = new BootLoader(); |
412 Image image = loader.createImage([ | 335 Image image = loader.createImage([ |
413 '--options', | 336 '--options', |
414 'test/data/plugin_options.yaml', | 337 path.join(testDirectory, 'data/plugin_options.yaml'), |
415 'test/data/test_file.dart' | 338 path.join(testDirectory, 'data/test_file.dart') |
416 ]); | 339 ]); |
417 var plugins = image.config.plugins; | 340 var plugins = image.config.plugins; |
418 expect(plugins, hasLength(1)); | 341 expect(plugins, hasLength(1)); |
419 expect(plugins.first.name, equals('my_plugin1')); | 342 expect(plugins.first.name, equals('my_plugin1')); |
420 }); | 343 }); |
421 group('plugin validation', () { | 344 group('plugin validation', () { |
422 test('requires class name', () { | 345 test('requires class name', () { |
423 expect( | 346 expect( |
424 validate(new PluginInfo( | 347 validate(new PluginInfo( |
425 name: 'test_plugin', libraryUri: 'my_package/foo.dart')), | 348 name: 'test_plugin', libraryUri: 'my_package/foo.dart')), |
(...skipping 11 matching lines...) Expand all Loading... |
437 name: 'test_plugin', | 360 name: 'test_plugin', |
438 className: 'MyPlugin', | 361 className: 'MyPlugin', |
439 libraryUri: 'my_package/foo.dart')), | 362 libraryUri: 'my_package/foo.dart')), |
440 isNull); | 363 isNull); |
441 }); | 364 }); |
442 }); | 365 }); |
443 }); | 366 }); |
444 }); | 367 }); |
445 } | 368 } |
446 | 369 |
| 370 const emptyOptionsFile = 'data/empty_options.yaml'; |
| 371 |
| 372 /// Shared driver. |
| 373 Driver driver; |
| 374 |
| 375 /// Start a driver for the given [source], optionally providing additional |
| 376 /// [args] and an [options] file path. The value of [options] defaults to |
| 377 /// an empty options file to avoid unwanted configuration from an otherwise |
| 378 /// discovered options file. |
| 379 void drive(String source, |
| 380 {String options: emptyOptionsFile, List<String> args: const <String>[]}) { |
| 381 driver = new Driver(); |
| 382 var cmd = [ |
| 383 '--options', |
| 384 path.join(testDirectory, options), |
| 385 path.join(testDirectory, source) |
| 386 ]..addAll(args); |
| 387 driver.start(cmd); |
| 388 } |
| 389 |
447 Map<String, YamlNode> parseOptions(String src) => | 390 Map<String, YamlNode> parseOptions(String src) => |
448 new AnalysisOptionsProvider().getOptionsFromString(src); | 391 new AnalysisOptionsProvider().getOptionsFromString(src); |
449 | 392 |
450 class TestPlugin extends Plugin { | 393 class TestPlugin extends Plugin { |
451 TestProcessor processor; | 394 TestProcessor processor; |
452 TestPlugin(this.processor); | 395 TestPlugin(this.processor); |
453 | 396 |
454 @override | 397 @override |
455 String get uniqueIdentifier => 'test_plugin.core'; | 398 String get uniqueIdentifier => 'test_plugin.core'; |
456 | 399 |
(...skipping 23 matching lines...) Expand all Loading... |
480 this.options = options; | 423 this.options = options; |
481 } | 424 } |
482 } | 425 } |
483 | 426 |
484 class TestSource implements Source { | 427 class TestSource implements Source { |
485 TestSource(); | 428 TestSource(); |
486 | 429 |
487 @override | 430 @override |
488 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 431 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
489 } | 432 } |
OLD | NEW |