args_test: style

This commit is contained in:
umarcor 2022-03-28 02:39:27 +02:00
parent 1684df23b3
commit 8d10b3fcb9
1 changed files with 92 additions and 150 deletions

View File

@ -20,7 +20,7 @@ import (
"testing" "testing"
) )
func getCommand(args PositionalArgs, withValid bool) *Command { func newCommand(args PositionalArgs, withValid bool) *Command {
c := &Command{ c := &Command{
Use: "c", Use: "c",
Args: args, Args: args,
@ -44,35 +44,26 @@ func expectSuccess(output string, err error, t *testing.T) {
type ExpectedErrors int64 type ExpectedErrors int64
const ( const (
OnlyValid_WithInvalidArgs ExpectedErrors = iota OnlyValidWithInvalidArgs ExpectedErrors = iota
NoArgs_WithArgs NoArgsWithArgs
MinimumNArgs_WithLessArgs MinimumNArgsWithLessArgs
MaximumNArgs_WithMoreArgs MaximumNArgsWithMoreArgs
ExactArgs_WithInvalidCount ExactArgsWithInvalidCount
RangeArgs_WithInvalidCount RangeArgsWithInvalidCount
) )
func expectErrorWithArg(err error, t *testing.T, ex ExpectedErrors, arg string) { func expectErrorWithArg(err error, t *testing.T, ex ExpectedErrors, arg string) {
if err == nil { if err == nil {
t.Fatal("Expected an error") t.Fatal("Expected an error")
} }
expected := map[ExpectedErrors]string{
var expected string OnlyValidWithInvalidArgs: `invalid argument "a" for "c"`,
switch ex { NoArgsWithArgs: `unknown command "` + arg + `" for "c"`,
case OnlyValid_WithInvalidArgs: MinimumNArgsWithLessArgs: "requires at least 2 arg(s), only received 1",
expected = `invalid argument "a" for "c"` MaximumNArgsWithMoreArgs: "accepts at most 2 arg(s), received 3",
case NoArgs_WithArgs: ExactArgsWithInvalidCount: "accepts 2 arg(s), received 3",
expected = `unknown command "` + arg + `" for "c"` RangeArgsWithInvalidCount: "accepts between 2 and 4 arg(s), received 1",
case MinimumNArgs_WithLessArgs: }[ex]
expected = "requires at least 2 arg(s), only received 1"
case MaximumNArgs_WithMoreArgs:
expected = "accepts at most 2 arg(s), received 3"
case ExactArgs_WithInvalidCount:
expected = "accepts 2 arg(s), received 3"
case RangeArgs_WithInvalidCount:
expected = "accepts between 2 and 4 arg(s), received 1"
}
if got := err.Error(); got != expected { if got := err.Error(); got != expected {
t.Errorf("Expected: %q, got: %q", expected, got) t.Errorf("Expected: %q, got: %q", expected, got)
} }
@ -85,273 +76,230 @@ func expectError(err error, t *testing.T, ex ExpectedErrors) {
// NoArgs // NoArgs
func TestNoArgs(t *testing.T) { func TestNoArgs(t *testing.T) {
c := getCommand(NoArgs, false) output, err := executeCommand(newCommand(NoArgs, false))
output, err := executeCommand(c)
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestNoArgs_WithArgs(t *testing.T) { func TestNoArgs_WithArgs(t *testing.T) {
c := getCommand(NoArgs, false) _, err := executeCommand(newCommand(NoArgs, false), "one")
_, err := executeCommand(c, "one") expectErrorWithArg(err, t, NoArgsWithArgs, "one")
expectErrorWithArg(err, t, NoArgs_WithArgs, "one")
} }
func TestNoArgs_WithValid_WithArgs(t *testing.T) { func TestNoArgs_WithValid_WithArgs(t *testing.T) {
c := getCommand(NoArgs, true) _, err := executeCommand(newCommand(NoArgs, true), "one")
_, err := executeCommand(c, "one") expectErrorWithArg(err, t, NoArgsWithArgs, "one")
expectErrorWithArg(err, t, NoArgs_WithArgs, "one")
} }
func TestNoArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestNoArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(NoArgs, true) _, err := executeCommand(newCommand(NoArgs, true), "a")
_, err := executeCommand(c, "a") expectErrorWithArg(err, t, NoArgsWithArgs, "a")
expectErrorWithArg(err, t, NoArgs_WithArgs, "a")
} }
func TestNoArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestNoArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, NoArgs), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, NoArgs), true), "a")
_, err := executeCommand(c, "a") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// OnlyValidArgs // OnlyValidArgs
func TestOnlyValidArgs(t *testing.T) { func TestOnlyValidArgs(t *testing.T) {
c := getCommand(OnlyValidArgs, true) output, err := executeCommand(newCommand(OnlyValidArgs, true), "one", "two")
output, err := executeCommand(c, "one", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestOnlyValidArgs_WithInvalidArgs(t *testing.T) { func TestOnlyValidArgs_WithInvalidArgs(t *testing.T) {
c := getCommand(OnlyValidArgs, true) _, err := executeCommand(newCommand(OnlyValidArgs, true), "a")
_, err := executeCommand(c, "a") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// ArbitraryArgs // ArbitraryArgs
func TestArbitraryArgs(t *testing.T) { func TestArbitraryArgs(t *testing.T) {
c := getCommand(ArbitraryArgs, false) output, err := executeCommand(newCommand(ArbitraryArgs, false), "a", "b")
output, err := executeCommand(c, "a", "b")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestArbitraryArgs_WithValid(t *testing.T) { func TestArbitraryArgs_WithValid(t *testing.T) {
c := getCommand(ArbitraryArgs, true) output, err := executeCommand(newCommand(ArbitraryArgs, true), "one", "two")
output, err := executeCommand(c, "one", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestArbitraryArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestArbitraryArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(ArbitraryArgs, true) output, err := executeCommand(newCommand(ArbitraryArgs, true), "a")
output, err := executeCommand(c, "a")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestArbitraryArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestArbitraryArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, ArbitraryArgs), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, ArbitraryArgs), true), "a")
_, err := executeCommand(c, "a") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// MinimumNArgs // MinimumNArgs
func TestMinimumNArgs(t *testing.T) { func TestMinimumNArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), false) output, err := executeCommand(newCommand(MinimumNArgs(2), false), "a", "b", "c")
output, err := executeCommand(c, "a", "b", "c")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestMinimumNArgs_WithValid(t *testing.T) { func TestMinimumNArgs_WithValid(t *testing.T) {
c := getCommand(MinimumNArgs(2), true) output, err := executeCommand(newCommand(MinimumNArgs(2), true), "one", "three")
output, err := executeCommand(c, "one", "three")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestMinimumNArgs_WithValid__WithInvalidArgs(t *testing.T) { func TestMinimumNArgs_WithValid__WithInvalidArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), true) output, err := executeCommand(newCommand(MinimumNArgs(2), true), "a", "b")
output, err := executeCommand(c, "a", "b")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestMinimumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestMinimumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true), "a", "b")
_, err := executeCommand(c, "a", "b") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
func TestMinimumNArgs_WithLessArgs(t *testing.T) { func TestMinimumNArgs_WithLessArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), false) _, err := executeCommand(newCommand(MinimumNArgs(2), false), "a")
_, err := executeCommand(c, "a") expectError(err, t, MinimumNArgsWithLessArgs)
expectError(err, t, MinimumNArgs_WithLessArgs)
} }
func TestMinimumNArgs_WithLessArgs_WithValid(t *testing.T) { func TestMinimumNArgs_WithLessArgs_WithValid(t *testing.T) {
c := getCommand(MinimumNArgs(2), true) _, err := executeCommand(newCommand(MinimumNArgs(2), true), "one")
_, err := executeCommand(c, "one") expectError(err, t, MinimumNArgsWithLessArgs)
expectError(err, t, MinimumNArgs_WithLessArgs)
} }
func TestMinimumNArgs_WithLessArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestMinimumNArgs_WithLessArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(MinimumNArgs(2), true) _, err := executeCommand(newCommand(MinimumNArgs(2), true), "a")
_, err := executeCommand(c, "a") expectError(err, t, MinimumNArgsWithLessArgs)
expectError(err, t, MinimumNArgs_WithLessArgs)
} }
func TestMinimumNArgs_WithLessArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestMinimumNArgs_WithLessArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true), "a")
_, err := executeCommand(c, "a") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// MaximumNArgs // MaximumNArgs
func TestMaximumNArgs(t *testing.T) { func TestMaximumNArgs(t *testing.T) {
c := getCommand(MaximumNArgs(3), false) output, err := executeCommand(newCommand(MaximumNArgs(3), false), "a", "b")
output, err := executeCommand(c, "a", "b")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestMaximumNArgs_WithValid(t *testing.T) { func TestMaximumNArgs_WithValid(t *testing.T) {
c := getCommand(MaximumNArgs(2), true) output, err := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three")
output, err := executeCommand(c, "one", "three")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestMaximumNArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestMaximumNArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(MaximumNArgs(2), true) output, err := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b")
output, err := executeCommand(c, "a", "b")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestMaximumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestMaximumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true), "a", "b")
_, err := executeCommand(c, "a", "b") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
func TestMaximumNArgs_WithMoreArgs(t *testing.T) { func TestMaximumNArgs_WithMoreArgs(t *testing.T) {
c := getCommand(MaximumNArgs(2), false) _, err := executeCommand(newCommand(MaximumNArgs(2), false), "a", "b", "c")
_, err := executeCommand(c, "a", "b", "c") expectError(err, t, MaximumNArgsWithMoreArgs)
expectError(err, t, MaximumNArgs_WithMoreArgs)
} }
func TestMaximumNArgs_WithMoreArgs_WithValid(t *testing.T) { func TestMaximumNArgs_WithMoreArgs_WithValid(t *testing.T) {
c := getCommand(MaximumNArgs(2), true) _, err := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three", "two")
_, err := executeCommand(c, "one", "three", "two") expectError(err, t, MaximumNArgsWithMoreArgs)
expectError(err, t, MaximumNArgs_WithMoreArgs)
} }
func TestMaximumNArgs_WithMoreArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestMaximumNArgs_WithMoreArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(MaximumNArgs(2), true) _, err := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b", "c")
_, err := executeCommand(c, "a", "b", "c") expectError(err, t, MaximumNArgsWithMoreArgs)
expectError(err, t, MaximumNArgs_WithMoreArgs)
} }
func TestMaximumNArgs_WithMoreArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestMaximumNArgs_WithMoreArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true), "a", "b", "c")
_, err := executeCommand(c, "a", "b", "c") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// ExactArgs // ExactArgs
func TestExactArgs(t *testing.T) { func TestExactArgs(t *testing.T) {
c := getCommand(ExactArgs(3), false) output, err := executeCommand(newCommand(ExactArgs(3), false), "a", "b", "c")
output, err := executeCommand(c, "a", "b", "c")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestExactArgs_WithValid(t *testing.T) { func TestExactArgs_WithValid(t *testing.T) {
c := getCommand(ExactArgs(3), true) output, err := executeCommand(newCommand(ExactArgs(3), true), "three", "one", "two")
output, err := executeCommand(c, "three", "one", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestExactArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestExactArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(ExactArgs(3), true) output, err := executeCommand(newCommand(ExactArgs(3), true), "three", "a", "two")
output, err := executeCommand(c, "three", "a", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestExactArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestExactArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, ExactArgs(3)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, ExactArgs(3)), true), "three", "a", "two")
_, err := executeCommand(c, "three", "a", "two") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
func TestExactArgs_WithInvalidCount(t *testing.T) { func TestExactArgs_WithInvalidCount(t *testing.T) {
c := getCommand(ExactArgs(2), false) _, err := executeCommand(newCommand(ExactArgs(2), false), "a", "b", "c")
_, err := executeCommand(c, "a", "b", "c") expectError(err, t, ExactArgsWithInvalidCount)
expectError(err, t, ExactArgs_WithInvalidCount)
} }
func TestExactArgs_WithInvalidCount_WithValid(t *testing.T) { func TestExactArgs_WithInvalidCount_WithValid(t *testing.T) {
c := getCommand(ExactArgs(2), true) _, err := executeCommand(newCommand(ExactArgs(2), true), "three", "one", "two")
_, err := executeCommand(c, "three", "one", "two") expectError(err, t, ExactArgsWithInvalidCount)
expectError(err, t, ExactArgs_WithInvalidCount)
} }
func TestExactArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) { func TestExactArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(ExactArgs(2), true) _, err := executeCommand(newCommand(ExactArgs(2), true), "three", "a", "two")
_, err := executeCommand(c, "three", "a", "two") expectError(err, t, ExactArgsWithInvalidCount)
expectError(err, t, ExactArgs_WithInvalidCount)
} }
func TestExactArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestExactArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, ExactArgs(2)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, ExactArgs(2)), true), "three", "a", "two")
_, err := executeCommand(c, "three", "a", "two") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// RangeArgs // RangeArgs
func TestRangeArgs(t *testing.T) { func TestRangeArgs(t *testing.T) {
c := getCommand(RangeArgs(2, 4), false) output, err := executeCommand(newCommand(RangeArgs(2, 4), false), "a", "b", "c")
output, err := executeCommand(c, "a", "b", "c")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestRangeArgs_WithValid(t *testing.T) { func TestRangeArgs_WithValid(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true) output, err := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "one", "two")
output, err := executeCommand(c, "three", "one", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestRangeArgs_WithValid_WithInvalidArgs(t *testing.T) { func TestRangeArgs_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true) output, err := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "a", "two")
output, err := executeCommand(c, "three", "a", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestRangeArgs_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestRangeArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true), "three", "a", "two")
_, err := executeCommand(c, "three", "a", "two") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
func TestRangeArgs_WithInvalidCount(t *testing.T) { func TestRangeArgs_WithInvalidCount(t *testing.T) {
c := getCommand(RangeArgs(2, 4), false) _, err := executeCommand(newCommand(RangeArgs(2, 4), false), "a")
_, err := executeCommand(c, "a") expectError(err, t, RangeArgsWithInvalidCount)
expectError(err, t, RangeArgs_WithInvalidCount)
} }
func TestRangeArgs_WithInvalidCount_WithValid(t *testing.T) { func TestRangeArgs_WithInvalidCount_WithValid(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true) _, err := executeCommand(newCommand(RangeArgs(2, 4), true), "two")
_, err := executeCommand(c, "two") expectError(err, t, RangeArgsWithInvalidCount)
expectError(err, t, RangeArgs_WithInvalidCount)
} }
func TestRangeArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) { func TestRangeArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) {
c := getCommand(RangeArgs(2, 4), true) _, err := executeCommand(newCommand(RangeArgs(2, 4), true), "a")
_, err := executeCommand(c, "a") expectError(err, t, RangeArgsWithInvalidCount)
expectError(err, t, RangeArgs_WithInvalidCount)
} }
func TestRangeArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) { func TestRangeArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) {
c := getCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true) _, err := executeCommand(newCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true), "a")
_, err := executeCommand(c, "a") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// Takes(No)Args // Takes(No)Args
@ -463,27 +411,23 @@ func TestMatchAll(t *testing.T) {
// DEPRECATED // DEPRECATED
func TestExactValidArgs(t *testing.T) { func TestExactValidArgs(t *testing.T) {
c := getCommand(ExactValidArgs(3), true) output, err := executeCommand(newCommand(ExactValidArgs(3), true), "three", "one", "two")
output, err := executeCommand(c, "three", "one", "two")
expectSuccess(output, err, t) expectSuccess(output, err, t)
} }
func TestExactValidArgs_WithInvalidCount(t *testing.T) { func TestExactValidArgs_WithInvalidCount(t *testing.T) {
c := getCommand(ExactValidArgs(2), false) _, err := executeCommand(newCommand(ExactValidArgs(2), false), "three", "one", "two")
_, err := executeCommand(c, "three", "one", "two") expectError(err, t, ExactArgsWithInvalidCount)
expectError(err, t, ExactArgs_WithInvalidCount)
} }
func TestExactValidArgs_WithInvalidCount_WithInvalidArgs(t *testing.T) { func TestExactValidArgs_WithInvalidCount_WithInvalidArgs(t *testing.T) {
c := getCommand(ExactValidArgs(2), true) _, err := executeCommand(newCommand(ExactValidArgs(2), true), "three", "a", "two")
_, err := executeCommand(c, "three", "a", "two") expectError(err, t, ExactArgsWithInvalidCount)
expectError(err, t, ExactArgs_WithInvalidCount)
} }
func TestExactValidArgs_WithInvalidArgs(t *testing.T) { func TestExactValidArgs_WithInvalidArgs(t *testing.T) {
c := getCommand(ExactValidArgs(2), true) _, err := executeCommand(newCommand(ExactValidArgs(2), true), "three", "a")
_, err := executeCommand(c, "three", "a") expectError(err, t, OnlyValidWithInvalidArgs)
expectError(err, t, OnlyValid_WithInvalidArgs)
} }
// This test make sure we keep backwards-compatibility with respect // This test make sure we keep backwards-compatibility with respect
@ -491,9 +435,7 @@ func TestExactValidArgs_WithInvalidArgs(t *testing.T) {
// It makes sure the root command accepts arguments if it does not have // It makes sure the root command accepts arguments if it does not have
// sub-commands. // sub-commands.
func TestLegacyArgsRootAcceptsArgs(t *testing.T) { func TestLegacyArgsRootAcceptsArgs(t *testing.T) {
rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun} _, err := executeCommand(&Command{Use: "root", Args: nil, Run: emptyRun}, "somearg")
_, err := executeCommand(rootCmd, "somearg")
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }