MCPcopy
hub / github.com/spf13/cobra / TestFlagInvalidInput

Function TestFlagInvalidInput

command_test.go:604–614  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

602}
603
604func TestFlagInvalidInput(t *testing.T) {
605 rootCmd := &Command{Use: "root", Run: emptyRun}
606 rootCmd.Flags().IntP("intf", "i", -1, "")
607
608 _, err := executeCommand(rootCmd, "-iabc")
609 if err == nil {
610 t.Errorf("Invalid flag value should generate error")
611 }
612
613 checkStringContains(t, err.Error(), "invalid syntax")
614}
615
616func TestFlagBeforeCommand(t *testing.T) {
617 rootCmd := &Command{Use: "root", Run: emptyRun}

Callers

nothing calls this directly

Calls 4

FlagsMethod · 0.95
executeCommandFunction · 0.85
ErrorMethod · 0.80
checkStringContainsFunction · 0.70

Tested by

no test coverage detected