From d7c0e17d25f9c3f1b7dab55dc564ca21cdfcde58 Mon Sep 17 00:00:00 2001 From: umarcor Date: Tue, 19 Mar 2019 20:30:05 +0100 Subject: [PATCH] style(args_test) --- args_test.go | 152 +++++++++++++++++++++------------------------------ 1 file changed, 61 insertions(+), 91 deletions(-) diff --git a/args_test.go b/args_test.go index c8b17a1309..249da57a75 100644 --- a/args_test.go +++ b/args_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func getCommand(args PositionalArgs, withValid bool) *Command { +func newCommand(args PositionalArgs, withValid bool) *Command { c := &Command{ Use: "c", Args: args, @@ -54,193 +54,163 @@ func expectError(err error, t *testing.T, ex string) { // NoArgs func TestNoArgs(t *testing.T) { - c := getCommand(NoArgs, false) - output, err := executeCommand(c) - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(NoArgs, false)) + expectSuccess(o, e, t) } func TestNoArgsWithArgs(t *testing.T) { - c := getCommand(NoArgs, false) - _, err := executeCommand(c, "one") - expectError(err, t, "no") + _, e := executeCommand(newCommand(NoArgs, false), "one") + expectError(e, t, "no") } func TestNoArgsWithArgsWithValid(t *testing.T) { - c := getCommand(NoArgs, true) - _, err := executeCommand(c, "one") - expectError(err, t, "no") + _, e := executeCommand(newCommand(NoArgs, true), "one") + expectError(e, t, "no") } // ArbitraryArgs func TestArbitraryArgs(t *testing.T) { - c := getCommand(ArbitraryArgs, false) - output, err := executeCommand(c, "a", "b") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(ArbitraryArgs, false), "a", "b") + expectSuccess(o, e, t) } func TestArbitraryArgsWithValid(t *testing.T) { - c := getCommand(ArbitraryArgs, true) - output, err := executeCommand(c, "one", "two") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(ArbitraryArgs, true), "one", "two") + expectSuccess(o, e, t) } func TestArbitraryArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(ArbitraryArgs, true) - _, err := executeCommand(c, "a") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(ArbitraryArgs, true), "a") + expectError(e, t, "valid") } // MinimumNArgs func TestMinimumNArgs(t *testing.T) { - c := getCommand(MinimumNArgs(2), false) - output, err := executeCommand(c, "a", "b", "c") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(MinimumNArgs(2), false), "a", "b", "c") + expectSuccess(o, e, t) } func TestMinimumNArgsWithValid(t *testing.T) { - c := getCommand(MinimumNArgs(2), true) - output, err := executeCommand(c, "one", "three") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(MinimumNArgs(2), true), "one", "three") + expectSuccess(o, e, t) } func TestMinimumNArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(MinimumNArgs(2), true) - _, err := executeCommand(c, "a", "b") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(MinimumNArgs(2), true), "a", "b") + expectError(e, t, "valid") } func TestMinimumNArgsWithLessArgs(t *testing.T) { - c := getCommand(MinimumNArgs(2), false) - _, err := executeCommand(c, "a") - expectError(err, t, "min") + _, e := executeCommand(newCommand(MinimumNArgs(2), false), "a") + expectError(e, t, "min") } func TestMinimumNArgsWithLessArgsWithValid(t *testing.T) { - c := getCommand(MinimumNArgs(2), true) - _, err := executeCommand(c, "one") - expectError(err, t, "min") + _, e := executeCommand(newCommand(MinimumNArgs(2), true), "one") + expectError(e, t, "min") } func TestMinimumNArgsWithLessArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(MinimumNArgs(2), true) - _, err := executeCommand(c, "a") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(MinimumNArgs(2), true), "a") + expectError(e, t, "valid") } // MaximumNArgs func TestMaximumNArgs(t *testing.T) { - c := getCommand(MaximumNArgs(3), false) - output, err := executeCommand(c, "a", "b") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(MaximumNArgs(3), false), "a", "b") + expectSuccess(o, e, t) } func TestMaximumNArgsWithValid(t *testing.T) { - c := getCommand(MaximumNArgs(2), true) - output, err := executeCommand(c, "one", "three") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three") + expectSuccess(o, e, t) } func TestMaximumNArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(MaximumNArgs(2), true) - _, err := executeCommand(c, "a", "b") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b") + expectError(e, t, "valid") } func TestMaximumNArgsWithMoreArgs(t *testing.T) { - c := getCommand(MaximumNArgs(2), false) - _, err := executeCommand(c, "a", "b", "c") - expectError(err, t, "max") + _, e := executeCommand(newCommand(MaximumNArgs(2), false), "a", "b", "c") + expectError(e, t, "max") } func TestMaximumNArgsWithMoreArgsWithValid(t *testing.T) { - c := getCommand(MaximumNArgs(2), true) - _, err := executeCommand(c, "one", "three", "two") - expectError(err, t, "max") + _, e := executeCommand(newCommand(MaximumNArgs(2), true), "one", "three", "two") + expectError(e, t, "max") } func TestMaximumNArgsWithMoreArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(MaximumNArgs(2), true) - _, err := executeCommand(c, "a", "b", "c") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(MaximumNArgs(2), true), "a", "b", "c") + expectError(e, t, "valid") } // ExactArgs func TestExactArgs(t *testing.T) { - c := getCommand(ExactArgs(3), false) - output, err := executeCommand(c, "a", "b", "c") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(ExactArgs(3), false), "a", "b", "c") + expectSuccess(o, e, t) } func TestExactArgsWithValid(t *testing.T) { - c := getCommand(ExactArgs(3), true) - output, err := executeCommand(c, "three", "one", "two") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(ExactArgs(3), true), "three", "one", "two") + expectSuccess(o, e, t) } func TestExactArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(ExactArgs(3), true) - _, err := executeCommand(c, "three", "a", "two") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(ExactArgs(3), true), "three", "a", "two") + expectError(e, t, "valid") } func TestExactArgsWithInvalidCount(t *testing.T) { - c := getCommand(ExactArgs(2), false) - _, err := executeCommand(c, "a", "b", "c") - expectError(err, t, "exact") + _, e := executeCommand(newCommand(ExactArgs(2), false), "a", "b", "c") + expectError(e, t, "exact") } func TestExactArgsWithInvalidCountWithValid(t *testing.T) { - c := getCommand(ExactArgs(2), true) - _, err := executeCommand(c, "three", "one", "two") - expectError(err, t, "exact") + _, e := executeCommand(newCommand(ExactArgs(2), true), "three", "one", "two") + expectError(e, t, "exact") } func TestExactArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(ExactArgs(2), true) - _, err := executeCommand(c, "three", "a", "two") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(ExactArgs(2), true), "three", "a", "two") + expectError(e, t, "valid") } // RangeArgs func TestRangeArgs(t *testing.T) { - c := getCommand(RangeArgs(2, 4), false) - output, err := executeCommand(c, "a", "b", "c") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a", "b", "c") + expectSuccess(o, e, t) } func TestRangeArgsWithValid(t *testing.T) { - c := getCommand(RangeArgs(2, 4), true) - output, err := executeCommand(c, "three", "one", "two") - expectSuccess(output, err, t) + o, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "one", "two") + expectSuccess(o, e, t) } func TestRangeArgsWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(RangeArgs(2, 4), true) - _, err := executeCommand(c, "three", "a", "two") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(RangeArgs(2, 4), true), "three", "a", "two") + expectError(e, t, "valid") } func TestRangeArgsWithInvalidCount(t *testing.T) { - c := getCommand(RangeArgs(2, 4), false) - _, err := executeCommand(c, "a") - expectError(err, t, "range") + _, e := executeCommand(newCommand(RangeArgs(2, 4), false), "a") + expectError(e, t, "range") } func TestRangeArgsWithInvalidCountWithValid(t *testing.T) { - c := getCommand(RangeArgs(2, 4), true) - _, err := executeCommand(c, "two") - expectError(err, t, "range") + _, e := executeCommand(newCommand(RangeArgs(2, 4), true), "two") + expectError(e, t, "range") } func TestRangeArgsWithInvalidCountWithValidWithInvalidArgs(t *testing.T) { - c := getCommand(RangeArgs(2, 4), true) - _, err := executeCommand(c, "a") - expectError(err, t, "valid") + _, e := executeCommand(newCommand(RangeArgs(2, 4), true), "a") + expectError(e, t, "valid") } // Takes(No)Args