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

Function TestInt64Flag

flag_int_test.go:241–292  ·  flag_int_test.go::TestInt64Flag
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func TestInt64Flag(t *testing.T) {
242 tests := []struct {
243 name string
244 flag Flag
245 arguments []string
246 expectedValue int64
247 expectErr bool
248 }{
249 {
250 name: "valid",
251 flag: &Int64Flag{
252 Name: "number",
253 Aliases: []string{"n"},
254 },
255 arguments: []string{"--number", "-2147483648"},
256 expectedValue: -2147483648,
257 },
258 {
259 name: "invalid",
260 flag: &Int64Flag{
261 Name: "number",
262 },
263 arguments: []string{"--number", "gopher"},
264 expectErr: true,
265 },
266 }
267
268 for _, tt := range tests {
269 t.Run(tt.name, func(t *testing.T) {
270 cmd := &Command{
271 Name: "mock",
272 Flags: []Flag{tt.flag},
273 Writer: io.Discard,
274 ErrWriter: io.Discard,
275 }
276
277 err := cmd.Run(buildTestContext(t), append([]string{"mock"}, tt.arguments...))
278
279 if tt.expectErr {
280 require.Error(t, err)
281
282 return
283 }
284
285 require.NoError(t, err)
286
287 for _, name := range tt.flag.Names() {
288 assert.Equal(t, tt.expectedValue, cmd.Int64(name))
289 }
290 })
291 }
292}
293
294func TestIntFlagExt(t *testing.T) {
295 tests := []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected