OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'package:args/command_runner.dart'; | 5 import 'package:args/command_runner.dart'; |
6 import 'package:test/test.dart'; | 6 import 'package:test/test.dart'; |
7 | 7 |
8 import 'utils.dart'; | 8 import 'utils.dart'; |
9 | 9 |
10 const _DEFAULT_USAGE = """ | 10 const _DEFAULT_USAGE = """ |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 Available commands: | 132 Available commands: |
133 aliased Set a value. | 133 aliased Set a value. |
134 help Display help information for test. | 134 help Display help information for test. |
135 | 135 |
136 Run "test help <command>" for more information about a command.""")); | 136 Run "test help <command>" for more information about a command.""")); |
137 }); | 137 }); |
138 }); | 138 }); |
139 | 139 |
140 test("usageException splits up the message and usage", () { | 140 test("usageException splits up the message and usage", () { |
141 expect(() => runner.usageException("message"), | 141 expect(() => runner.usageException("message"), |
142 throwsUsageError("message", _DEFAULT_USAGE)); | 142 throwsUsageException("message", _DEFAULT_USAGE)); |
143 }); | 143 }); |
144 | 144 |
145 group("run()", () { | 145 group("run()", () { |
146 test("runs a command", () { | 146 test("runs a command", () { |
147 var command = new FooCommand(); | 147 var command = new FooCommand(); |
148 runner.addCommand(command); | 148 runner.addCommand(command); |
149 | 149 |
150 expect(runner.run(["foo"]).then((_) { | 150 expect(runner.run(["foo"]).then((_) { |
151 expect(command.hasRun, isTrue); | 151 expect(command.hasRun, isTrue); |
152 }), completes); | 152 }), completes); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 test("includes the footer in the usage string", () { | 256 test("includes the footer in the usage string", () { |
257 expect(runner.usage, equals(""" | 257 expect(runner.usage, equals(""" |
258 A test command runner. | 258 A test command runner. |
259 | 259 |
260 $_DEFAULT_USAGE | 260 $_DEFAULT_USAGE |
261 Also, footer!""")); | 261 Also, footer!""")); |
262 }); | 262 }); |
263 | 263 |
264 test("includes the footer in usage errors", () { | 264 test("includes the footer in usage errors", () { |
265 expect(runner.run(["--bad"]), throwsUsageError( | 265 expect(runner.run(["--bad"]), throwsUsageException( |
266 'Could not find an option named "bad".', | 266 'Could not find an option named "bad".', |
267 "$_DEFAULT_USAGE\nAlso, footer!")); | 267 "$_DEFAULT_USAGE\nAlso, footer!")); |
268 }); | 268 }); |
269 }); | 269 }); |
270 | 270 |
271 group("throws a useful error when", () { | 271 group("throws a useful error when", () { |
272 test("arg parsing fails", () { | 272 test("arg parsing fails", () { |
273 expect(runner.run(["--bad"]), throwsUsageError( | 273 expect(runner.run(["--bad"]), throwsUsageException( |
274 'Could not find an option named "bad".', _DEFAULT_USAGE)); | 274 'Could not find an option named "bad".', _DEFAULT_USAGE)); |
275 }); | 275 }); |
276 | 276 |
277 test("a top-level command doesn't exist", () { | 277 test("a top-level command doesn't exist", () { |
278 expect(runner.run(["bad"]), throwsUsageError( | 278 expect(runner.run(["bad"]), throwsUsageException( |
279 'Could not find a command named "bad".', _DEFAULT_USAGE)); | 279 'Could not find a command named "bad".', _DEFAULT_USAGE)); |
280 }); | 280 }); |
281 | 281 |
282 test("a subcommand doesn't exist", () { | 282 test("a subcommand doesn't exist", () { |
283 runner.addCommand(new FooCommand()..addSubcommand(new AsyncCommand())); | 283 runner.addCommand(new FooCommand()..addSubcommand(new AsyncCommand())); |
284 | 284 |
285 expect(runner.run(["foo bad"]), throwsUsageError( | 285 expect(runner.run(["foo bad"]), throwsUsageException( |
286 'Could not find a command named "foo bad".', """ | 286 'Could not find a command named "foo bad".', """ |
287 Usage: test <command> [arguments] | 287 Usage: test <command> [arguments] |
288 | 288 |
289 Global options: | 289 Global options: |
290 -h, --help Print this usage information. | 290 -h, --help Print this usage information. |
291 | 291 |
292 Available commands: | 292 Available commands: |
293 foo Set a value. | 293 foo Set a value. |
294 help Display help information for test. | 294 help Display help information for test. |
295 | 295 |
296 Run "test help <command>" for more information about a command.""")); | 296 Run "test help <command>" for more information about a command.""")); |
297 }); | 297 }); |
298 | 298 |
299 test("a subcommand wasn't passed", () { | 299 test("a subcommand wasn't passed", () { |
300 runner.addCommand(new FooCommand()..addSubcommand(new AsyncCommand())); | 300 runner.addCommand(new FooCommand()..addSubcommand(new AsyncCommand())); |
301 | 301 |
302 expect(runner.run(["foo"]), throwsUsageError( | 302 expect(runner.run(["foo"]), throwsUsageException( |
303 'Missing subcommand for "test foo".', """ | 303 'Missing subcommand for "test foo".', """ |
304 Usage: test foo <subcommand> [arguments] | 304 Usage: test foo <subcommand> [arguments] |
305 -h, --help Print this usage information. | 305 -h, --help Print this usage information. |
306 | 306 |
307 Available subcommands: | 307 Available subcommands: |
308 async Set a value asynchronously. | 308 async Set a value asynchronously. |
309 | 309 |
310 Run "test help" to see global options.""")); | 310 Run "test help" to see global options.""")); |
311 }); | 311 }); |
312 | 312 |
313 test("a command that doesn't take arguments was given them", () { | 313 test("a command that doesn't take arguments was given them", () { |
314 runner.addCommand(new FooCommand()); | 314 runner.addCommand(new FooCommand()); |
315 | 315 |
316 expect(runner.run(["foo", "bar"]), throwsUsageError( | 316 expect(runner.run(["foo", "bar"]), throwsUsageException( |
317 'Command "foo" does not take any arguments.', """ | 317 'Command "foo" does not take any arguments.', """ |
318 Usage: test foo [arguments] | 318 Usage: test foo [arguments] |
319 -h, --help Print this usage information. | 319 -h, --help Print this usage information. |
320 | 320 |
321 Run "test help" to see global options.""")); | 321 Run "test help" to see global options.""")); |
322 }); | 322 }); |
323 }); | 323 }); |
324 } | 324 } |
OLD | NEW |