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

Side by Side 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: Code review changes 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 }
OLDNEW
« pkg/args/lib/command_runner.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