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

Function TestValidArgsFuncSingleCmdInvalidArg

completions_test.go:1357–1382  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1355}
1356
1357func TestValidArgsFuncSingleCmdInvalidArg(t *testing.T) {
1358 rootCmd := &Command{
1359 Use: "root",
1360 // If we don't specify a value for Args, this test fails.
1361 // This is only true for a root command without any subcommands, and is caused
1362 // by the fact that the __complete command becomes a subcommand when there should not be one.
1363 // The problem is in the implementation of legacyArgs().
1364 Args: MinimumNArgs(1),
1365 ValidArgsFunction: validArgsFunc,
1366 Run: emptyRun,
1367 }
1368
1369 // Check completing with wrong number of args
1370 output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "unexpectedArg", "t")
1371 if err != nil {
1372 t.Errorf("Unexpected error: %v", err)
1373 }
1374
1375 expected := strings.Join([]string{
1376 ":4",
1377 "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
1378
1379 if output != expected {
1380 t.Errorf("expected: %q, got: %q", expected, output)
1381 }
1382}
1383
1384func TestValidArgsFuncChildCmds(t *testing.T) {
1385 rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}

Callers

nothing calls this directly

Calls 2

MinimumNArgsFunction · 0.85
executeCommandFunction · 0.85

Tested by

no test coverage detected