MCPcopy
hub / github.com/urfave/cli / TestInt32Flag

Function TestInt32Flag

flag_int_test.go:179–239  ·  flag_int_test.go::TestInt32Flag
(t *testing.T)

Source from the content-addressed store, hash-verified

177}
178
179func TestInt32Flag(t *testing.T) {
180 tests := []struct {
181 name string
182 flag Flag
183 arguments []string
184 expectedValue int32
185 expectErr bool
186 }{
187 {
188 name: "valid",
189 flag: &Int32Flag{
190 Name: "number",
191 Aliases: []string{"n"},
192 },
193 arguments: []string{"--number", "2147483647"},
194 expectedValue: 2147483647,
195 },
196 {
197 name: "invalid",
198 flag: &Int32Flag{
199 Name: "number",
200 },
201
202 arguments: []string{"--number", "gopher"},
203 expectErr: true,
204 },
205 {
206 name: "out of range",
207 flag: &Int32Flag{
208 Name: "number",
209 },
210 arguments: []string{"--number", "2147483648"},
211 expectErr: true,
212 },
213 }
214
215 for _, tt := range tests {
216 t.Run(tt.name, func(t *testing.T) {
217 cmd := &Command{
218 Name: "mock",
219 Flags: []Flag{tt.flag},
220 Writer: io.Discard,
221 ErrWriter: io.Discard,
222 }
223
224 err := cmd.Run(buildTestContext(t), append([]string{"mock"}, tt.arguments...))
225
226 if tt.expectErr {
227 require.Error(t, err)
228
229 return
230 }
231
232 require.NoError(t, err)
233
234 for _, name := range tt.flag.Names() {
235 assert.Equal(t, tt.expectedValue, cmd.Int32(name))
236 }

Callers

nothing calls this directly

Calls 5

RunMethod · 0.95
Int32Method · 0.95
buildTestContextFunction · 0.85
NamesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected