OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library command_test; |
| 6 |
| 7 import 'package:args/command_runner.dart'; |
| 8 import 'package:test/test.dart'; |
| 9 import 'utils.dart'; |
| 10 |
| 11 void main() { |
| 12 var foo; |
| 13 setUp(() { |
| 14 foo = new FooCommand(); |
| 15 |
| 16 // Make sure [Command.runner] is set up. |
| 17 new CommandRunner("test", "A test command runner.").addCommand(foo); |
| 18 }); |
| 19 |
| 20 group(".invocation has a sane default", () { |
| 21 test("without subcommands", () { |
| 22 expect(foo.invocation, equals("test foo [arguments]")); |
| 23 }); |
| 24 |
| 25 test("with subcommands", () { |
| 26 foo.addSubcommand(new AsyncCommand()); |
| 27 expect(foo.invocation, equals("test foo <subcommand> [arguments]")); |
| 28 }); |
| 29 |
| 30 test("for a subcommand", () { |
| 31 var async = new AsyncCommand(); |
| 32 foo.addSubcommand(async); |
| 33 |
| 34 expect(async.invocation, equals("test foo async [arguments]")); |
| 35 }); |
| 36 }); |
| 37 |
| 38 group(".usage", () { |
| 39 test("returns the usage string", () { |
| 40 expect(foo.usage, equals(""" |
| 41 Set a value. |
| 42 |
| 43 Usage: test foo [arguments] |
| 44 -h, --help Print this usage information. |
| 45 |
| 46 Run "test help" to see global options.""")); |
| 47 }); |
| 48 |
| 49 test("contains custom options", () { |
| 50 foo.argParser.addFlag("flag", help: "Do something."); |
| 51 |
| 52 expect(foo.usage, equals(""" |
| 53 Set a value. |
| 54 |
| 55 Usage: test foo [arguments] |
| 56 -h, --help Print this usage information. |
| 57 --[no-]flag Do something. |
| 58 |
| 59 Run "test help" to see global options.""")); |
| 60 }); |
| 61 |
| 62 test("doesn't print hidden subcommands", () { |
| 63 foo.addSubcommand(new AsyncCommand()); |
| 64 foo.addSubcommand(new HiddenCommand()); |
| 65 |
| 66 expect(foo.usage, equals(""" |
| 67 Set a value. |
| 68 |
| 69 Usage: test foo <subcommand> [arguments] |
| 70 -h, --help Print this usage information. |
| 71 |
| 72 Available subcommands: |
| 73 async Set a value asynchronously. |
| 74 |
| 75 Run "test help" to see global options.""")); |
| 76 }); |
| 77 |
| 78 test("doesn't print subcommand aliases", () { |
| 79 foo.addSubcommand(new AliasedCommand()); |
| 80 |
| 81 expect(foo.usage, equals(""" |
| 82 Set a value. |
| 83 |
| 84 Usage: test foo <subcommand> [arguments] |
| 85 -h, --help Print this usage information. |
| 86 |
| 87 Available subcommands: |
| 88 aliased Set a value. |
| 89 |
| 90 Run "test help" to see global options.""")); |
| 91 }); |
| 92 }); |
| 93 |
| 94 test("usageException splits up the message and usage", () { |
| 95 expect(() => foo.usageException("message"), throwsUsageError("message", """ |
| 96 Usage: test foo [arguments] |
| 97 -h, --help Print this usage information. |
| 98 |
| 99 Run "test help" to see global options.""")); |
| 100 }); |
| 101 |
| 102 test("considers a command hidden if all its subcommands are hidden", () { |
| 103 foo.addSubcommand(new HiddenCommand()); |
| 104 expect(foo.hidden, isTrue); |
| 105 }); |
| 106 } |
OLD | NEW |