Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(977)

Unified Diff: pkg/args/test/utils.dart

Issue 797473002: Add a CommandRunner class for dispatching commands to args. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« pkg/args/lib/src/utils.dart ('K') | « pkg/args/test/command_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/args/test/utils.dart
diff --git a/pkg/args/test/utils.dart b/pkg/args/test/utils.dart
index 4586f573b0d12809f4f035eb4e65ea6daef9e933..a9b68efa15f936e857fac45b3b4fe3d9ad6441b0 100644
--- a/pkg/args/test/utils.dart
+++ b/pkg/args/test/utils.dart
@@ -4,9 +4,67 @@
library utils;
+import 'dart:async';
+
import 'package:unittest/unittest.dart';
import 'package:args/args.dart';
+class FooCommand extends Command {
+ var hasRun = false;
+
+ final name = "foo";
+ final description = "Set a value.";
+ final takesArguments = false;
+
+ FooCommand();
Bob Nystrom 2014/12/11 20:25:31 Are these constructors needed?
nweiz 2014/12/11 23:55:24 Nope, removed.
+
+ void run() {
+ hasRun = true;
+ }
+}
+
+class HiddenCommand extends Command {
+ var hasRun = false;
+
+ final name = "hidden";
+ final description = "Set a value.";
+ final hidden = true;
+ final takesArguments = false;
+
+ HiddenCommand();
+
+ void run() {
+ hasRun = true;
+ }
+}
+
+class AliasedCommand extends Command {
+ var hasRun = false;
+
+ final name = "aliased";
+ final description = "Set a value.";
+ final takesArguments = false;
+ final aliases = const ["alias", "als"];
+
+ AliasedCommand();
+
+ void run() {
+ hasRun = true;
+ }
+}
+
+class AsyncCommand extends Command {
+ var hasRun = false;
+
+ final name = "async";
+ final description = "Set a value asynchronously.";
+ final takesArguments = false;
+
+ AsyncCommand();
+
+ Future run() => new Future.value().then((_) => hasRun = true);
+}
+
void throwsIllegalArg(function, {String reason: null}) {
expect(function, throwsArgumentError, reason: reason);
}
@@ -14,3 +72,12 @@ void throwsIllegalArg(function, {String reason: null}) {
void throwsFormat(ArgParser parser, List<String> args) {
expect(() => parser.parse(args), throwsFormatException);
}
+
+Matcher throwsUsageError(message, usage) {
+ return throwsA(predicate((error) {
+ expect(error, new isInstanceOf<UsageError>());
+ expect(error.message, message);
+ expect(error.usage, usage);
+ return true;
+ }));
+}
« pkg/args/lib/src/utils.dart ('K') | « pkg/args/test/command_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698