Skip to content
Myr

Add backwards-compatibility tests for legacyArgs() (#1547)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

These tests make sure we don't break backwards-compatibility with respect to the current behaviour of legacyArgs(). See #1500 for the back-story.

authored by Marc Khouzam · committed by GitHub · parent 8cc7be2 · Browse files · 1 file+29 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Diff stats

1 file+29 added−0 removed

  • other:+29 added−0 removed

1 file+29 added−0 removed

modified:args_test.go+29 added
290 unmodified lines
291 }292 })293 }294}295296// This test make sure we keep backwards-compatibility with respect297// to the legacyArgs() function.298// It makes sure the root command accepts arguments if it does not have299// sub-commands.300func TestLegacyArgsRootAcceptsArgs(t *testing.T) {301 rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun}302303 _, err := executeCommand(rootCmd, "somearg")304 if err != nil {305 t.Fatalf("Unexpected error: %v", err)306 }307}308309// This test make sure we keep backwards-compatibility with respect310// to the legacyArgs() function.311// It makes sure a sub-command accepts arguments and further sub-commands312func TestLegacyArgsSubcmdAcceptsArgs(t *testing.T) {313 rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun}314 childCmd := &Command{Use: "child", Args: nil, Run: emptyRun}315 grandchildCmd := &Command{Use: "grandchild", Args: nil, Run: emptyRun}316 rootCmd.AddCommand(childCmd)317 childCmd.AddCommand(grandchildCmd)318319 _, err := executeCommand(rootCmd, "child", "somearg")320 if err != nil {321 t.Fatalf("Unexpected error: %v", err)322 }323}