@@ -30,6 +30,7 @@ func validWithInvalidArgs(err error, t *testing.T) {
30
30
if err == nil {
31
31
t .Fatal ("Expected an error" )
32
32
}
33
+
33
34
got := err .Error ()
34
35
expected := `invalid argument "a" for "c"`
35
36
if got != expected {
@@ -42,7 +43,7 @@ func noArgsWithArgs(err error, t *testing.T) {
42
43
t .Fatal ("Expected an error" )
43
44
}
44
45
got := err .Error ()
45
- expected := `unknown command "illegal " for "c"`
46
+ expected := `unknown command "one " for "c"`
46
47
if got != expected {
47
48
t .Errorf ("Expected: %q, got: %q" , expected , got )
48
49
}
@@ -63,6 +64,7 @@ func maximumNArgsWithMoreArgs(err error, t *testing.T) {
63
64
if err == nil {
64
65
t .Fatal ("Expected an error" )
65
66
}
67
+
66
68
got := err .Error ()
67
69
expected := "accepts at most 2 arg(s), received 3"
68
70
if got != expected {
@@ -92,6 +94,8 @@ func rangeArgsWithInvalidCount(err error, t *testing.T) {
92
94
}
93
95
}
94
96
97
+ // NoArgs
98
+
95
99
func TestNoArgs (t * testing.T ) {
96
100
c := getCommand (NoArgs , false )
97
101
output , err := executeCommand (c )
@@ -100,94 +104,190 @@ func TestNoArgs(t *testing.T) {
100
104
101
105
func TestNoArgsWithArgs (t * testing.T ) {
102
106
c := getCommand (NoArgs , false )
103
- _ , err := executeCommand (c , "illegal " )
107
+ _ , err := executeCommand (c , "one " )
104
108
noArgsWithArgs (err , t )
105
109
}
106
110
107
- func TestOnlyValidArgs (t * testing.T ) {
108
- c := getCommand (OnlyValidArgs , true )
109
- output , err := executeCommand (c , "one" , "two " )
110
- expectSuccess ( output , err , t )
111
+ func TestNoArgsWithArgsWithValid (t * testing.T ) {
112
+ c := getCommand (NoArgs , true )
113
+ _ , err := executeCommand (c , "one" )
114
+ noArgsWithArgs ( err , t )
111
115
}
112
116
113
- func TestOnlyValidArgsWithInvalidArgs (t * testing.T ) {
114
- c := getCommand (OnlyValidArgs , true )
115
- _ , err := executeCommand (c , "a" )
116
- validWithInvalidArgs (err , t )
117
- }
117
+ // ArbitraryArgs
118
118
119
119
func TestArbitraryArgs (t * testing.T ) {
120
120
c := getCommand (ArbitraryArgs , false )
121
121
output , err := executeCommand (c , "a" , "b" )
122
122
expectSuccess (output , err , t )
123
123
}
124
124
125
+ func TestArbitraryArgsWithValid (t * testing.T ) {
126
+ c := getCommand (ArbitraryArgs , true )
127
+ output , err := executeCommand (c , "one" , "two" )
128
+ expectSuccess (output , err , t )
129
+ }
130
+
131
+ func TestArbitraryArgsWithValidWithInvalidArgs (t * testing.T ) {
132
+ c := getCommand (ArbitraryArgs , true )
133
+ _ , err := executeCommand (c , "a" )
134
+ validWithInvalidArgs (err , t )
135
+ }
136
+
137
+ // MinimumNArgs
138
+
125
139
func TestMinimumNArgs (t * testing.T ) {
126
140
c := getCommand (MinimumNArgs (2 ), false )
127
141
output , err := executeCommand (c , "a" , "b" , "c" )
128
142
expectSuccess (output , err , t )
129
143
}
130
144
145
+ func TestMinimumNArgsWithValid (t * testing.T ) {
146
+ c := getCommand (MinimumNArgs (2 ), true )
147
+ output , err := executeCommand (c , "one" , "three" )
148
+ expectSuccess (output , err , t )
149
+ }
150
+
151
+ func TestMinimumNArgsWithValidWithInvalidArgs (t * testing.T ) {
152
+ c := getCommand (MinimumNArgs (2 ), true )
153
+ _ , err := executeCommand (c , "a" , "b" )
154
+ validWithInvalidArgs (err , t )
155
+ }
156
+
131
157
func TestMinimumNArgsWithLessArgs (t * testing.T ) {
132
158
c := getCommand (MinimumNArgs (2 ), false )
133
159
_ , err := executeCommand (c , "a" )
134
160
minimumNArgsWithLessArgs (err , t )
135
161
}
136
162
163
+ func TestMinimumNArgsWithLessArgsWithValid (t * testing.T ) {
164
+ c := getCommand (MinimumNArgs (2 ), true )
165
+ _ , err := executeCommand (c , "one" )
166
+ minimumNArgsWithLessArgs (err , t )
167
+ }
168
+
169
+ func TestMinimumNArgsWithLessArgsWithValidWithInvalidArgs (t * testing.T ) {
170
+ c := getCommand (MinimumNArgs (2 ), true )
171
+ _ , err := executeCommand (c , "a" )
172
+ validWithInvalidArgs (err , t )
173
+ }
174
+
175
+ // MaximumNArgs
176
+
137
177
func TestMaximumNArgs (t * testing.T ) {
138
178
c := getCommand (MaximumNArgs (3 ), false )
139
179
output , err := executeCommand (c , "a" , "b" )
140
180
expectSuccess (output , err , t )
141
181
}
142
182
183
+ func TestMaximumNArgsWithValid (t * testing.T ) {
184
+ c := getCommand (MaximumNArgs (2 ), true )
185
+ output , err := executeCommand (c , "one" , "three" )
186
+ expectSuccess (output , err , t )
187
+ }
188
+
189
+ func TestMaximumNArgsWithValidWithInvalidArgs (t * testing.T ) {
190
+ c := getCommand (MaximumNArgs (2 ), true )
191
+ _ , err := executeCommand (c , "a" , "b" )
192
+ validWithInvalidArgs (err , t )
193
+ }
194
+
143
195
func TestMaximumNArgsWithMoreArgs (t * testing.T ) {
144
196
c := getCommand (MaximumNArgs (2 ), false )
145
197
_ , err := executeCommand (c , "a" , "b" , "c" )
146
198
maximumNArgsWithMoreArgs (err , t )
147
199
}
148
200
201
+ func TestMaximumNArgsWithMoreArgsWithValid (t * testing.T ) {
202
+ c := getCommand (MaximumNArgs (2 ), true )
203
+ _ , err := executeCommand (c , "one" , "three" , "two" )
204
+ maximumNArgsWithMoreArgs (err , t )
205
+ }
206
+
207
+ func TestMaximumNArgsWithMoreArgsWithValidWithInvalidArgs (t * testing.T ) {
208
+ c := getCommand (MaximumNArgs (2 ), true )
209
+ _ , err := executeCommand (c , "a" , "b" , "c" )
210
+ validWithInvalidArgs (err , t )
211
+ }
212
+
213
+ // ExactArgs
214
+
149
215
func TestExactArgs (t * testing.T ) {
150
216
c := getCommand (ExactArgs (3 ), false )
151
217
output , err := executeCommand (c , "a" , "b" , "c" )
152
218
expectSuccess (output , err , t )
153
219
}
154
220
221
+ func TestExactArgsWithValid (t * testing.T ) {
222
+ c := getCommand (ExactArgs (3 ), true )
223
+ output , err := executeCommand (c , "three" , "one" , "two" )
224
+ expectSuccess (output , err , t )
225
+ }
226
+
227
+ func TestExactArgsWithValidWithInvalidArgs (t * testing.T ) {
228
+ c := getCommand (ExactArgs (3 ), true )
229
+ _ , err := executeCommand (c , "three" , "a" , "two" )
230
+ validWithInvalidArgs (err , t )
231
+ }
232
+
155
233
func TestExactArgsWithInvalidCount (t * testing.T ) {
156
234
c := getCommand (ExactArgs (2 ), false )
157
235
_ , err := executeCommand (c , "a" , "b" , "c" )
158
236
exactArgsWithInvalidCount (err , t )
159
237
}
160
238
161
- func TestExactValidArgs (t * testing.T ) {
162
- c := getCommand (ExactValidArgs (3 ), true )
163
- output , err := executeCommand (c , "three" , "one" , "two" )
164
- expectSuccess (output , err , t )
165
- }
166
-
167
- func TestExactValidArgsWithInvalidCount (t * testing.T ) {
168
- c := getCommand (ExactValidArgs (2 ), false )
239
+ func TestExactArgsWithInvalidCountWithValid (t * testing.T ) {
240
+ c := getCommand (ExactArgs (2 ), true )
169
241
_ , err := executeCommand (c , "three" , "one" , "two" )
170
242
exactArgsWithInvalidCount (err , t )
171
243
}
172
244
173
- func TestExactValidArgsWithInvalidArgs (t * testing.T ) {
174
- c := getCommand (ExactValidArgs ( 3 ), true )
245
+ func TestExactArgsWithInvalidCountWithValidWithInvalidArgs (t * testing.T ) {
246
+ c := getCommand (ExactArgs ( 2 ), true )
175
247
_ , err := executeCommand (c , "three" , "a" , "two" )
176
248
validWithInvalidArgs (err , t )
177
249
}
178
250
251
+ // RangeArgs
252
+
179
253
func TestRangeArgs (t * testing.T ) {
180
254
c := getCommand (RangeArgs (2 , 4 ), false )
181
255
output , err := executeCommand (c , "a" , "b" , "c" )
182
256
expectSuccess (output , err , t )
183
257
}
184
258
259
+ func TestRangeArgsWithValid (t * testing.T ) {
260
+ c := getCommand (RangeArgs (2 , 4 ), true )
261
+ output , err := executeCommand (c , "three" , "one" , "two" )
262
+ expectSuccess (output , err , t )
263
+ }
264
+
265
+ func TestRangeArgsWithValidWithInvalidArgs (t * testing.T ) {
266
+ c := getCommand (RangeArgs (2 , 4 ), true )
267
+ _ , err := executeCommand (c , "three" , "a" , "two" )
268
+ validWithInvalidArgs (err , t )
269
+ }
270
+
185
271
func TestRangeArgsWithInvalidCount (t * testing.T ) {
186
272
c := getCommand (RangeArgs (2 , 4 ), false )
187
273
_ , err := executeCommand (c , "a" )
188
274
rangeArgsWithInvalidCount (err , t )
189
275
}
190
276
277
+ func TestRangeArgsWithInvalidCountWithValid (t * testing.T ) {
278
+ c := getCommand (RangeArgs (2 , 4 ), true )
279
+ _ , err := executeCommand (c , "two" )
280
+ rangeArgsWithInvalidCount (err , t )
281
+ }
282
+
283
+ func TestRangeArgsWithInvalidCountWithValidWithInvalidArgs (t * testing.T ) {
284
+ c := getCommand (RangeArgs (2 , 4 ), true )
285
+ _ , err := executeCommand (c , "a" )
286
+ validWithInvalidArgs (err , t )
287
+ }
288
+
289
+ // Takes(No)Args
290
+
191
291
func TestRootTakesNoArgs (t * testing.T ) {
192
292
rootCmd := & Command {Use : "root" , Run : emptyRun }
193
293
childCmd := & Command {Use : "child" , Run : emptyRun }
0 commit comments