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; | |
6 | |
7 import 'dart:async'; | 5 import 'dart:async'; |
8 | 6 |
9 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
10 import 'package:args/command_runner.dart'; | 8 import 'package:args/command_runner.dart'; |
11 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
12 | 10 |
13 class CommandRunnerWithFooter extends CommandRunner { | 11 class CommandRunnerWithFooter extends CommandRunner { |
14 final usageFooter = "Also, footer!"; | 12 String get usageFooter => "Also, footer!"; |
15 | 13 |
16 CommandRunnerWithFooter(String executableName, String description) | 14 CommandRunnerWithFooter(String executableName, String description) |
17 : super(executableName, description); | 15 : super(executableName, description); |
18 } | 16 } |
19 | 17 |
20 class FooCommand extends Command { | 18 class FooCommand extends Command { |
21 var hasRun = false; | 19 var hasRun = false; |
22 | 20 |
23 final name = "foo"; | 21 final name = "foo"; |
24 final description = "Set a value."; | 22 final description = "Set a value."; |
25 final takesArguments = false; | 23 final takesArguments = false; |
26 | 24 |
27 void run() { | 25 void run() { |
28 hasRun = true; | 26 hasRun = true; |
29 } | 27 } |
30 } | 28 } |
31 | 29 |
| 30 class ValueCommand extends Command<int> { |
| 31 final name = "foo"; |
| 32 final description = "Return a value."; |
| 33 final takesArguments = false; |
| 34 |
| 35 int run() => 12; |
| 36 } |
| 37 |
| 38 class AsyncValueCommand extends Command<String> { |
| 39 final name = "foo"; |
| 40 final description = "Return a future."; |
| 41 final takesArguments = false; |
| 42 |
| 43 Future<String> run() async => "hi"; |
| 44 } |
| 45 |
| 46 class MultilineCommand extends Command { |
| 47 var hasRun = false; |
| 48 |
| 49 final name = "multiline"; |
| 50 final description = "Multi\nline."; |
| 51 final takesArguments = false; |
| 52 |
| 53 void run() { |
| 54 hasRun = true; |
| 55 } |
| 56 } |
| 57 |
| 58 class MultilineSummaryCommand extends MultilineCommand { |
| 59 String get summary => description; |
| 60 } |
| 61 |
32 class HiddenCommand extends Command { | 62 class HiddenCommand extends Command { |
33 var hasRun = false; | 63 var hasRun = false; |
34 | 64 |
35 final name = "hidden"; | 65 final name = "hidden"; |
36 final description = "Set a value."; | 66 final description = "Set a value."; |
37 final hidden = true; | 67 final hidden = true; |
38 final takesArguments = false; | 68 final takesArguments = false; |
39 | 69 |
40 void run() { | 70 void run() { |
41 hasRun = true; | 71 hasRun = true; |
(...skipping 24 matching lines...) Expand all Loading... |
66 } | 96 } |
67 | 97 |
68 void throwsIllegalArg(function, {String reason: null}) { | 98 void throwsIllegalArg(function, {String reason: null}) { |
69 expect(function, throwsArgumentError, reason: reason); | 99 expect(function, throwsArgumentError, reason: reason); |
70 } | 100 } |
71 | 101 |
72 void throwsFormat(ArgParser parser, List<String> args) { | 102 void throwsFormat(ArgParser parser, List<String> args) { |
73 expect(() => parser.parse(args), throwsFormatException); | 103 expect(() => parser.parse(args), throwsFormatException); |
74 } | 104 } |
75 | 105 |
76 Matcher throwsUsageError(message, usage) { | 106 Matcher throwsUsageException(message, usage) { |
77 return throwsA(predicate((error) { | 107 return throwsA(predicate((error) { |
78 expect(error, new isInstanceOf<UsageException>()); | 108 expect(error, new isInstanceOf<UsageException>()); |
79 expect(error.message, message); | 109 expect(error.message, message); |
80 expect(error.usage, usage); | 110 expect(error.usage, usage); |
81 return true; | 111 return true; |
82 })); | 112 })); |
83 } | 113 } |
OLD | NEW |