@@ -14,6 +14,25 @@ class MockAnalytics extends Mock implements Analytics {}
14
14
15
15
class MockLogger extends Mock implements Logger {}
16
16
17
+ const expectedUsage = [
18
+ '🦄 A Very Good Command Line Interface\n '
19
+ '\n '
20
+ 'Usage: very_good <command> [arguments]\n '
21
+ '\n '
22
+ 'Global options:\n '
23
+ '-h, --help Print this usage information.\n '
24
+ ' --version Print the current version.\n '
25
+ ' --analytics Toggle anonymous usage statistics.\n '
26
+ '\n '
27
+ ' [false] Disable anonymous usage statistics\n '
28
+ ' [true] Enable anonymous usage statistics\n '
29
+ '\n '
30
+ 'Available commands:\n '
31
+ ' create Creates a new very good flutter application in seconds.\n '
32
+ '\n '
33
+ 'Run "very_good help <command>" for more information about a command.'
34
+ ];
35
+
17
36
void main () {
18
37
group ('VeryGoodCommandRunner' , () {
19
38
List <String > printLogs;
@@ -98,51 +117,21 @@ void main() {
98
117
});
99
118
100
119
test ('handles no command' , overridePrint (() async {
101
- const expectedPrintLogs = [
102
- '🦄 A Very Good Command Line Interface\n '
103
- '\n '
104
- 'Usage: very_good <command> [arguments]\n '
105
- '\n '
106
- 'Global options:\n '
107
- '-h, --help Print this usage information.\n '
108
- ' --version Print the current version.\n '
109
- ''' --analytics Opt into or out of anonymous usage statistics.\n '''
110
- '\n '
111
- 'Available commands:\n '
112
- ''' create Creates a new very good flutter application in seconds.\n '''
113
- '\n '
114
- '''Run "very_good help <command>" for more information about a command.'''
115
- ];
116
120
final result = await commandRunner.run ([]);
117
- expect (printLogs, equals (expectedPrintLogs ));
121
+ expect (printLogs, equals (expectedUsage ));
118
122
expect (result, equals (ExitCode .success.code));
119
123
}));
120
124
121
125
group ('--help' , () {
122
126
test ('outputs usage' , overridePrint (() async {
123
- const expectedPrintLogs = [
124
- '🦄 A Very Good Command Line Interface\n '
125
- '\n '
126
- 'Usage: very_good <command> [arguments]\n '
127
- '\n '
128
- 'Global options:\n '
129
- '-h, --help Print this usage information.\n '
130
- ' --version Print the current version.\n '
131
- ''' --analytics Opt into or out of anonymous usage statistics.\n '''
132
- '\n '
133
- 'Available commands:\n '
134
- ''' create Creates a new very good flutter application in seconds.\n '''
135
- '\n '
136
- '''Run "very_good help <command>" for more information about a command.'''
137
- ];
138
127
final result = await commandRunner.run (['--help' ]);
139
- expect (printLogs, equals (expectedPrintLogs ));
128
+ expect (printLogs, equals (expectedUsage ));
140
129
expect (result, equals (ExitCode .success.code));
141
130
142
131
printLogs.clear ();
143
132
144
133
final resultAbbr = await commandRunner.run (['-h' ]);
145
- expect (printLogs, equals (expectedPrintLogs ));
134
+ expect (printLogs, equals (expectedUsage ));
146
135
expect (resultAbbr, equals (ExitCode .success.code));
147
136
}));
148
137
});
@@ -160,10 +149,13 @@ void main() {
160
149
verify (analytics.enabled = false );
161
150
});
162
151
163
- test ('sets analytics.enabled to false (garbage value) ' , () async {
152
+ test ('does not accept erroneous input ' , () async {
164
153
final result = await commandRunner.run (['--analytics' , 'garbage' ]);
165
- expect (result, equals (ExitCode .success.code));
166
- verify (analytics.enabled = false );
154
+ expect (result, equals (ExitCode .usage.code));
155
+ verifyNever (analytics.enabled);
156
+ verify (logger.err (
157
+ '"garbage" is not an allowed value for option "analytics".' ,
158
+ )).called (1 );
167
159
});
168
160
169
161
test ('exits with bad usage when missing value' , () async {
0 commit comments