|
5 | 5 | "testing"
|
6 | 6 | )
|
7 | 7 |
|
8 |
| -func getCommand(args PositionalArgs, withValid bool) *Command { |
| 8 | +func newCommand(args PositionalArgs, withValid bool) *Command { |
9 | 9 | c := &Command{
|
10 | 10 | Use: "c",
|
11 | 11 | Args: args,
|
@@ -54,193 +54,163 @@ func expectError(err error, t *testing.T, ex string) {
|
54 | 54 | // NoArgs
|
55 | 55 |
|
56 | 56 | func TestNoArgs(t *testing.T) {
|
57 |
| - c := getCommand(NoArgs, false) |
58 |
| - output, err := executeCommand(c) |
59 |
| - expectSuccess(output, err, t) |
| 57 | + o, e := executeCommand(newCommand(NoArgs, false)) |
| 58 | + expectSuccess(o, e, t) |
60 | 59 | }
|
61 | 60 |
|
62 | 61 | func TestNoArgsWithArgs(t *testing.T) {
|
63 |
| - c := getCommand(NoArgs, false) |
64 |
| - _, err := executeCommand(c, "one") |
65 |
| - expectError(err, t, "no") |
| 62 | + _, e := executeCommand(newCommand(NoArgs, false), "one") |
| 63 | + expectError(e, t, "no") |
66 | 64 | }
|
67 | 65 |
|
68 | 66 | func TestNoArgsWithArgsWithValid(t *testing.T) {
|
69 |
| - c := getCommand(NoArgs, true) |
70 |
| - _, err := executeCommand(c, "one") |
71 |
| - expectError(err, t, "no") |
| 67 | + _, e := executeCommand(newCommand(NoArgs, true), "one") |
| 68 | + expectError(e, t, "no") |
72 | 69 | }
|
73 | 70 |
|
74 | 71 | // ArbitraryArgs
|
75 | 72 |
|
76 | 73 | func TestArbitraryArgs(t *testing.T) {
|
77 |
| - c := getCommand(ArbitraryArgs, false) |
78 |
| - output, err := executeCommand(c, "a", "b") |
79 |
| - expectSuccess(output, err, t) |
| 74 | + o, e := executeCommand(newCommand(ArbitraryArgs, false), "a", "b") |
| 75 | + expectSuccess(o, e, t) |
80 | 76 | }
|
81 | 77 |
|
82 | 78 | func TestArbitraryArgsWithValid(t *testing.T) {
|
83 |
| - c := getCommand(ArbitraryArgs, true) |
84 |
| - output, err := executeCommand(c, "one", "two") |
85 |
| - expectSuccess(output, err, t) |
| 79 | + o, e := executeCommand(newCommand(ArbitraryArgs, true), "one", "two") |
| 80 | + expectSuccess(o, e, t) |
86 | 81 | }
|
87 | 82 |
|
88 | 83 | func TestArbitraryArgsWithValidWithInvalidArgs(t *testing.T) {
|
89 |
| - c := getCommand(ArbitraryArgs, true) |
90 |
| - _, err := executeCommand(c, "a") |
91 |
| - expectError(err, t, "valid") |
| 84 | + _, e := executeCommand(newCommand(ArbitraryArgs, true), "a") |
| 85 | + expectError(e, t, "valid") |
92 | 86 | }
|
93 | 87 |
|
94 | 88 | // MinimumNArgs
|
95 | 89 |
|
96 | 90 | func TestMinimumNArgs(t *testing.T) {
|
97 |
| - c := getCommand(MinimumNArgs(2), false) |
98 |
| - output, err := executeCommand(c, "a", "b", "c") |
99 |
| - expectSuccess(output, err, t) |
| 91 | + o, e := executeCommand(newCommand(MinimumNArgs(2), false), "a", "b", "c") |
| 92 | + expectSuccess(o, e, t) |
100 | 93 | }
|
101 | 94 |
|
102 | 95 | func TestMinimumNArgsWithValid(t *testing.T) {
|
103 |
| - c := getCommand(MinimumNArgs(2), true) |
104 |
| - output, err := executeCommand(c, "one", "three") |
105 |
| - expectSuccess(output, err, t) |
| 96 | + o, e := executeCommand(newCommand(MinimumNArgs(2), true), "one", "three") |
| 97 | + expectSuccess(o, e, t) |
106 | 98 | }
|
107 | 99 |
|
108 | 100 | func TestMinimumNArgsWithValidWithInvalidArgs(t *testing.T) {
|
109 |
| - c := getCommand(MinimumNArgs(2), true) |
110 |
| - _, err := executeCommand(c, "a", "b") |
111 |
| - expectError(err, t, "valid") |
| 101 | + _, e := executeCommand(newCommand(MinimumNArgs(2), true), "a", "b") |
| 102 | + expectError(e, t, "valid") |
112 | 103 | }
|
113 | 104 |
|
114 | 105 | func TestMinimumNArgsWithLessArgs(t *testing.T) {
|
115 |
| - c := getCommand(MinimumNArgs(2), false) |
116 |
| - _, err := executeCommand(c, "a") |
117 |
| - expectError(err, t, "min") |
| 106 | + _, e := executeCommand(newCommand(MinimumNArgs(2), false), "a") |
| 107 | + expectError(e, t, "min") |
118 | 108 | }
|
119 | 109 |
|
120 | 110 | func TestMinimumNArgsWithLessArgsWithValid(t *testing.T) {
|
121 |
| - c := getCommand(MinimumNArgs(2), true) |
122 |
| - _, err := executeCommand(c, "one") |
123 |
| - expectError(err, t, "min") |
| 111 | + _, e := executeCommand(newCommand(MinimumNArgs(2), true), "one") |
| 112 | + expectError(e, t, "min") |
124 | 113 | }
|
125 | 114 |
|
126 | 115 | func TestMinimumNArgsWithLessArgsWithValidWithInvalidArgs(t *testing.T) {
|
127 |
| - c := getCommand(MinimumNArgs(2), true) |
128 |
| - _, err := executeCommand(c, "a") |
129 |
| - expectError(err, t, "valid") |
| 116 | + _, e := executeCommand(newCommand(MinimumNArgs(2), true), "a") |
| 117 | + expectError(e, t, "valid") |
130 | 118 | }
|
131 | 119 |
|
132 | 120 | // MaximumNArgs
|
133 | 121 |
|
134 | 122 | func TestMaximumNArgs(t *testing.T) {
|
135 |
| - c := getCommand(MaximumNArgs(3), false) |
136 |
| - output, err := executeCommand(c, "a", "b") |
137 |
| - expectSuccess(output, err, t) |
| 123 | + o, e := executeCommand(newCommand(MaximumNArgs(3), false), "a", "b") |
| 124 | + expectSuccess(o, e, t) |
138 | 125 | }
|
139 | 126 |
|
140 | 127 | func TestMaximumNArgsWithValid(t *testing.T) {
|
141 |
| - c := getCommand(MaximumNArgs(2), true) |
142 |
| - output, err := executeCommand(c, "one", "three") |
143 |
| - expectSuccess(output, err, t) |
| 128 | + o, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three") |
| 129 | + expectSuccess(o, e, t) |
144 | 130 | }
|
145 | 131 |
|
146 | 132 | func TestMaximumNArgsWithValidWithInvalidArgs(t *testing.T) {
|
147 |
| - c := getCommand(MaximumNArgs(2), true) |
148 |
| - _, err := executeCommand(c, "a", "b") |
149 |
| - expectError(err, t, "valid") |
| 133 | + _, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b") |
| 134 | + expectError(e, t, "valid") |
150 | 135 | }
|
151 | 136 |
|
152 | 137 | func TestMaximumNArgsWithMoreArgs(t *testing.T) {
|
153 |
| - c := getCommand(MaximumNArgs(2), false) |
154 |
| - _, err := executeCommand(c, "a", "b", "c") |
155 |
| - expectError(err, t, "max") |
| 138 | + _, e := executeCommand(newCommand(MaximumNArgs(2), false), "a", "b", "c") |
| 139 | + expectError(e, t, "max") |
156 | 140 | }
|
157 | 141 |
|
158 | 142 | func TestMaximumNArgsWithMoreArgsWithValid(t *testing.T) {
|
159 |
| - c := getCommand(MaximumNArgs(2), true) |
160 |
| - _, err := executeCommand(c, "one", "three", "two") |
161 |
| - expectError(err, t, "max") |
| 143 | + _, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three", "two") |
| 144 | + expectError(e, t, "max") |
162 | 145 | }
|
163 | 146 |
|
164 | 147 | func TestMaximumNArgsWithMoreArgsWithValidWithInvalidArgs(t *testing.T) {
|
165 |
| - c := getCommand(MaximumNArgs(2), true) |
166 |
| - _, err := executeCommand(c, "a", "b", "c") |
167 |
| - expectError(err, t, "valid") |
| 148 | + _, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b", "c") |
| 149 | + expectError(e, t, "valid") |
168 | 150 | }
|
169 | 151 |
|
170 | 152 | // ExactArgs
|
171 | 153 |
|
172 | 154 | func TestExactArgs(t *testing.T) {
|
173 |
| - c := getCommand(ExactArgs(3), false) |
174 |
| - output, err := executeCommand(c, "a", "b", "c") |
175 |
| - expectSuccess(output, err, t) |
| 155 | + o, e := executeCommand(newCommand(ExactArgs(3), false), "a", "b", "c") |
| 156 | + expectSuccess(o, e, t) |
176 | 157 | }
|
177 | 158 |
|
178 | 159 | func TestExactArgsWithValid(t *testing.T) {
|
179 |
| - c := getCommand(ExactArgs(3), true) |
180 |
| - output, err := executeCommand(c, "three", "one", "two") |
181 |
| - expectSuccess(output, err, t) |
| 160 | + o, e := executeCommand(newCommand(ExactArgs(3), true), "three", "one", "two") |
| 161 | + expectSuccess(o, e, t) |
182 | 162 | }
|
183 | 163 |
|
184 | 164 | func TestExactArgsWithValidWithInvalidArgs(t *testing.T) {
|
185 |
| - c := getCommand(ExactArgs(3), true) |
186 |
| - _, err := executeCommand(c, "three", "a", "two") |
187 |
| - expectError(err, t, "valid") |
| 165 | + _, e := executeCommand(newCommand(ExactArgs(3), true), "three", "a", "two") |
| 166 | + expectError(e, t, "valid") |
188 | 167 | }
|
189 | 168 |
|
190 | 169 | func TestExactArgsWithInvalidCount(t *testing.T) {
|
191 |
| - c := getCommand(ExactArgs(2), false) |
192 |
| - _, err := executeCommand(c, "a", "b", "c") |
193 |
| - expectError(err, t, "exact") |
| 170 | + _, e := executeCommand(newCommand(ExactArgs(2), false), "a", "b", "c") |
| 171 | + expectError(e, t, "exact") |
194 | 172 | }
|
195 | 173 |
|
196 | 174 | func TestExactArgsWithInvalidCountWithValid(t *testing.T) {
|
197 |
| - c := getCommand(ExactArgs(2), true) |
198 |
| - _, err := executeCommand(c, "three", "one", "two") |
199 |
| - expectError(err, t, "exact") |
| 175 | + _, e := executeCommand(newCommand(ExactArgs(2), true), "three", "one", "two") |
| 176 | + expectError(e, t, "exact") |
200 | 177 | }
|
201 | 178 |
|
202 | 179 | func TestExactArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) {
|
203 |
| - c := getCommand(ExactArgs(2), true) |
204 |
| - _, err := executeCommand(c, "three", "a", "two") |
205 |
| - expectError(err, t, "valid") |
| 180 | + _, e := executeCommand(newCommand(ExactArgs(2), true), "three", "a", "two") |
| 181 | + expectError(e, t, "valid") |
206 | 182 | }
|
207 | 183 |
|
208 | 184 | // RangeArgs
|
209 | 185 |
|
210 | 186 | func TestRangeArgs(t *testing.T) {
|
211 |
| - c := getCommand(RangeArgs(2, 4), false) |
212 |
| - output, err := executeCommand(c, "a", "b", "c") |
213 |
| - expectSuccess(output, err, t) |
| 187 | + o, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a", "b", "c") |
| 188 | + expectSuccess(o, e, t) |
214 | 189 | }
|
215 | 190 |
|
216 | 191 | func TestRangeArgsWithValid(t *testing.T) {
|
217 |
| - c := getCommand(RangeArgs(2, 4), true) |
218 |
| - output, err := executeCommand(c, "three", "one", "two") |
219 |
| - expectSuccess(output, err, t) |
| 192 | + o, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "one", "two") |
| 193 | + expectSuccess(o, e, t) |
220 | 194 | }
|
221 | 195 |
|
222 | 196 | func TestRangeArgsWithValidWithInvalidArgs(t *testing.T) {
|
223 |
| - c := getCommand(RangeArgs(2, 4), true) |
224 |
| - _, err := executeCommand(c, "three", "a", "two") |
225 |
| - expectError(err, t, "valid") |
| 197 | + _, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "a", "two") |
| 198 | + expectError(e, t, "valid") |
226 | 199 | }
|
227 | 200 |
|
228 | 201 | func TestRangeArgsWithInvalidCount(t *testing.T) {
|
229 |
| - c := getCommand(RangeArgs(2, 4), false) |
230 |
| - _, err := executeCommand(c, "a") |
231 |
| - expectError(err, t, "range") |
| 202 | + _, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a") |
| 203 | + expectError(e, t, "range") |
232 | 204 | }
|
233 | 205 |
|
234 | 206 | func TestRangeArgsWithInvalidCountWithValid(t *testing.T) {
|
235 |
| - c := getCommand(RangeArgs(2, 4), true) |
236 |
| - _, err := executeCommand(c, "two") |
237 |
| - expectError(err, t, "range") |
| 207 | + _, e := executeCommand(newCommand(RangeArgs(2, 4), true), "two") |
| 208 | + expectError(e, t, "range") |
238 | 209 | }
|
239 | 210 |
|
240 | 211 | func TestRangeArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) {
|
241 |
| - c := getCommand(RangeArgs(2, 4), true) |
242 |
| - _, err := executeCommand(c, "a") |
243 |
| - expectError(err, t, "valid") |
| 212 | + _, e := executeCommand(newCommand(RangeArgs(2, 4), true), "a") |
| 213 | + expectError(e, t, "valid") |
244 | 214 | }
|
245 | 215 |
|
246 | 216 | // Takes(No)Args
|
|
0 commit comments