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

Function TestChildTakesNoArgs

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

Source from the content-addressed store, hash-verified

410}
411
412func TestChildTakesNoArgs(t *testing.T) {
413 rootCmd := &Command{Use: "root", Run: emptyRun}
414 childCmd := &Command{Use: "child", Args: NoArgs, Run: emptyRun}
415 rootCmd.AddCommand(childCmd)
416
417 _, err := executeCommand(rootCmd, "child", "illegal", "args")
418 if err == nil {
419 t.Fatal("Expected an error")
420 }
421
422 got := err.Error()
423 expected := `unknown command "illegal" for "root child"`
424 if !strings.Contains(got, expected) {
425 t.Errorf("expected %q, got %q", expected, got)
426 }
427}
428
429func TestChildTakesArgs(t *testing.T) {
430 rootCmd := &Command{Use: "root", Run: emptyRun}

Callers

nothing calls this directly

Calls 3

AddCommandMethod · 0.95
executeCommandFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected