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