Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backwards-compatibility tests for legacyArgs() #1547

Merged
merged 1 commit into from Mar 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions args_test.go
Expand Up @@ -292,3 +292,32 @@ func TestMatchAll(t *testing.T) {
})
}
}

// This test make sure we keep backwards-compatibility with respect
// to the legacyArgs() function.
// It makes sure the root command accepts arguments if it does not have
// sub-commands.
func TestLegacyArgsRootAcceptsArgs(t *testing.T) {
rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun}

_, err := executeCommand(rootCmd, "somearg")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
}

// This test make sure we keep backwards-compatibility with respect
// to the legacyArgs() function.
// It makes sure a sub-command accepts arguments and further sub-commands
func TestLegacyArgsSubcmdAcceptsArgs(t *testing.T) {
rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun}
childCmd := &Command{Use: "child", Args: nil, Run: emptyRun}
grandchildCmd := &Command{Use: "grandchild", Args: nil, Run: emptyRun}
rootCmd.AddCommand(childCmd)
childCmd.AddCommand(grandchildCmd)

_, err := executeCommand(rootCmd, "child", "somearg")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
}