| 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 library command_test; | 5 library command_test; |
| 6 | 6 |
| 7 import 'package:args/args.dart'; | |
| 8 import 'package:args/command_runner.dart'; | 7 import 'package:args/command_runner.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 10 import 'utils.dart'; | 9 import 'utils.dart'; |
| 11 | 10 |
| 12 void main() { | 11 void main() { |
| 13 var foo; | 12 var foo; |
| 14 setUp(() { | 13 setUp(() { |
| 15 foo = new FooCommand(); | 14 foo = new FooCommand(); |
| 16 | 15 |
| 17 // Make sure [Command.runner] is set up. | 16 // Make sure [Command.runner] is set up. |
| 18 new CommandRunner("test", "A test command runner.").addCommand(foo); | 17 new CommandRunner("test", "A test command runner.").addCommand(foo); |
| 19 }); | 18 }); |
| 20 | 19 |
| 21 group(".invocation has a sane default", () { | 20 group(".invocation has a sane default", () { |
| 22 test("without subcommands", () { | 21 test("without subcommands", () { |
| 23 expect(foo.invocation, | 22 expect(foo.invocation, equals("test foo [arguments]")); |
| 24 equals("test foo [arguments]")); | |
| 25 }); | 23 }); |
| 26 | 24 |
| 27 test("with subcommands", () { | 25 test("with subcommands", () { |
| 28 foo.addSubcommand(new AsyncCommand()); | 26 foo.addSubcommand(new AsyncCommand()); |
| 29 expect(foo.invocation, | 27 expect(foo.invocation, equals("test foo <subcommand> [arguments]")); |
| 30 equals("test foo <subcommand> [arguments]")); | |
| 31 }); | 28 }); |
| 32 | 29 |
| 33 test("for a subcommand", () { | 30 test("for a subcommand", () { |
| 34 var async = new AsyncCommand(); | 31 var async = new AsyncCommand(); |
| 35 foo.addSubcommand(async); | 32 foo.addSubcommand(async); |
| 36 | 33 |
| 37 expect(async.invocation, | 34 expect(async.invocation, equals("test foo async [arguments]")); |
| 38 equals("test foo async [arguments]")); | |
| 39 }); | 35 }); |
| 40 }); | 36 }); |
| 41 | 37 |
| 42 group(".usage", () { | 38 group(".usage", () { |
| 43 test("returns the usage string", () { | 39 test("returns the usage string", () { |
| 44 expect(foo.usage, equals(""" | 40 expect(foo.usage, equals(""" |
| 45 Set a value. | 41 Set a value. |
| 46 | 42 |
| 47 Usage: test foo [arguments] | 43 Usage: test foo [arguments] |
| 48 -h, --help Print this usage information. | 44 -h, --help Print this usage information. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 -h, --help Print this usage information. | 97 -h, --help Print this usage information. |
| 102 | 98 |
| 103 Run "test help" to see global options.""")); | 99 Run "test help" to see global options.""")); |
| 104 }); | 100 }); |
| 105 | 101 |
| 106 test("considers a command hidden if all its subcommands are hidden", () { | 102 test("considers a command hidden if all its subcommands are hidden", () { |
| 107 foo.addSubcommand(new HiddenCommand()); | 103 foo.addSubcommand(new HiddenCommand()); |
| 108 expect(foo.hidden, isTrue); | 104 expect(foo.hidden, isTrue); |
| 109 }); | 105 }); |
| 110 } | 106 } |
| OLD | NEW |