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

These tests make sure we don't break backwards-compatibility with
respect to the current behaviour of legacyArgs().

See #1500 for the back-story.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This commit is contained in:
Marc Khouzam 2022-03-17 21:36:47 -04:00 committed by GitHub
parent 8cc7be2119
commit 94e552d8d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
}
}