@@ -14,6 +14,25 @@ class MockAnalytics extends Mock implements Analytics {}
1414
1515class MockLogger extends Mock implements Logger {}
1616
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+
1736void main () {
1837 group ('VeryGoodCommandRunner' , () {
1938 List <String > printLogs;
@@ -98,51 +117,21 @@ void main() {
98117 });
99118
100119 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- ];
116120 final result = await commandRunner.run ([]);
117- expect (printLogs, equals (expectedPrintLogs ));
121+ expect (printLogs, equals (expectedUsage ));
118122 expect (result, equals (ExitCode .success.code));
119123 }));
120124
121125 group ('--help' , () {
122126 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- ];
138127 final result = await commandRunner.run (['--help' ]);
139- expect (printLogs, equals (expectedPrintLogs ));
128+ expect (printLogs, equals (expectedUsage ));
140129 expect (result, equals (ExitCode .success.code));
141130
142131 printLogs.clear ();
143132
144133 final resultAbbr = await commandRunner.run (['-h' ]);
145- expect (printLogs, equals (expectedPrintLogs ));
134+ expect (printLogs, equals (expectedUsage ));
146135 expect (resultAbbr, equals (ExitCode .success.code));
147136 }));
148137 });
@@ -160,10 +149,13 @@ void main() {
160149 verify (analytics.enabled = false );
161150 });
162151
163- test ('sets analytics.enabled to false (garbage value) ' , () async {
152+ test ('does not accept erroneous input ' , () async {
164153 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 );
167159 });
168160
169161 test ('exits with bad usage when missing value' , () async {
0 commit comments