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

Function TestSingleOptionalArg

args_test.go:510–553  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

508}
509
510func TestSingleOptionalArg(t *testing.T) {
511 tests := []struct {
512 name string
513 args []string
514 argValue string
515 exp string
516 }{
517 {
518 name: "no args",
519 args: []string{"foo"},
520 exp: "",
521 },
522 {
523 name: "no arg with def value",
524 args: []string{"foo"},
525 argValue: "bar",
526 exp: "bar",
527 },
528 {
529 name: "one arg",
530 args: []string{"foo", "zbar"},
531 exp: "zbar",
532 },
533 }
534
535 for _, test := range tests {
536 t.Run(test.name, func(t *testing.T) {
537 cmd := buildMinimalTestCommand()
538 var s1 string
539 arg := &StringArg{
540 Value: test.argValue,
541 Destination: &s1,
542 }
543 cmd.Arguments = []Argument{
544 arg,
545 }
546
547 err := cmd.Run(buildTestContext(t), test.args) //
548 r := require.New(t)
549 r.NoError(err)
550 r.Equal(test.exp, s1)
551 })
552 }
553}
554
555func TestUnboundedArgs(t *testing.T) {
556 arg := &StringArgs{

Callers

nothing calls this directly

Calls 3

buildMinimalTestCommandFunction · 0.85
buildTestContextFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected