OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 utils; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:args/args.dart'; |
| 10 import 'package:args/command_runner.dart'; |
| 11 import 'package:test/test.dart'; |
| 12 |
| 13 class CommandRunnerWithFooter extends CommandRunner { |
| 14 final usageFooter = "Also, footer!"; |
| 15 |
| 16 CommandRunnerWithFooter(String executableName, String description) |
| 17 : super(executableName, description); |
| 18 } |
| 19 |
| 20 class FooCommand extends Command { |
| 21 var hasRun = false; |
| 22 |
| 23 final name = "foo"; |
| 24 final description = "Set a value."; |
| 25 final takesArguments = false; |
| 26 |
| 27 void run() { |
| 28 hasRun = true; |
| 29 } |
| 30 } |
| 31 |
| 32 class HiddenCommand extends Command { |
| 33 var hasRun = false; |
| 34 |
| 35 final name = "hidden"; |
| 36 final description = "Set a value."; |
| 37 final hidden = true; |
| 38 final takesArguments = false; |
| 39 |
| 40 void run() { |
| 41 hasRun = true; |
| 42 } |
| 43 } |
| 44 |
| 45 class AliasedCommand extends Command { |
| 46 var hasRun = false; |
| 47 |
| 48 final name = "aliased"; |
| 49 final description = "Set a value."; |
| 50 final takesArguments = false; |
| 51 final aliases = const ["alias", "als"]; |
| 52 |
| 53 void run() { |
| 54 hasRun = true; |
| 55 } |
| 56 } |
| 57 |
| 58 class AsyncCommand extends Command { |
| 59 var hasRun = false; |
| 60 |
| 61 final name = "async"; |
| 62 final description = "Set a value asynchronously."; |
| 63 final takesArguments = false; |
| 64 |
| 65 Future run() => new Future.value().then((_) => hasRun = true); |
| 66 } |
| 67 |
| 68 void throwsIllegalArg(function, {String reason: null}) { |
| 69 expect(function, throwsArgumentError, reason: reason); |
| 70 } |
| 71 |
| 72 void throwsFormat(ArgParser parser, List<String> args) { |
| 73 expect(() => parser.parse(args), throwsFormatException); |
| 74 } |
| 75 |
| 76 Matcher throwsUsageError(message, usage) { |
| 77 return throwsA(predicate((error) { |
| 78 expect(error, new isInstanceOf<UsageException>()); |
| 79 expect(error.message, message); |
| 80 expect(error.usage, usage); |
| 81 return true; |
| 82 })); |
| 83 } |
OLD | NEW |