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