diff --git a/command_test.go b/command_test.go index d390abd0a1..b9c1ba0dc2 100644 --- a/command_test.go +++ b/command_test.go @@ -1253,41 +1253,11 @@ func TestCommand_ParseSliceFlags(t *testing.T) { }, } - _ = cmd.Run(buildTestContext(t), []string{"", "cmd", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"}) - - IntsEquals := func(a, b []int64) bool { - if len(a) != len(b) { - return false - } - for i, v := range a { - if v != b[i] { - return false - } - } - return true - } - - StrsEquals := func(a, b []string) bool { - if len(a) != len(b) { - return false - } - for i, v := range a { - if v != b[i] { - return false - } - } - return true - } - expectedIntSlice := []int64{22, 80} - expectedStringSlice := []string{"8.8.8.8", "8.8.4.4"} - - if !IntsEquals(parsedIntSlice, expectedIntSlice) { - t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice) - } + r := require.New(t) - if !StrsEquals(parsedStringSlice, expectedStringSlice) { - t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice) - } + r.NoError(cmd.Run(buildTestContext(t), []string{"", "cmd", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})) + r.Equal([]int64{22, 80}, parsedIntSlice) + r.Equal([]string{"8.8.8.8", "8.8.4.4"}, parsedStringSlice) } func TestCommand_ParseSliceFlagsWithMissingValue(t *testing.T) { @@ -1311,18 +1281,11 @@ func TestCommand_ParseSliceFlagsWithMissingValue(t *testing.T) { }, } - _ = cmd.Run(buildTestContext(t), []string{"", "cmd", "-a", "2", "-str", "A"}) - - expectedIntSlice := []int64{2} - expectedStringSlice := []string{"A"} - - if parsedIntSlice[0] != expectedIntSlice[0] { - t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0]) - } + r := require.New(t) - if parsedStringSlice[0] != expectedStringSlice[0] { - t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0]) - } + r.NoError(cmd.Run(buildTestContext(t), []string{"", "cmd", "-a", "2", "-str", "A"})) + r.Equal([]int64{2}, parsedIntSlice) + r.Equal([]string{"A"}, parsedStringSlice) } func TestCommand_DefaultStdin(t *testing.T) { @@ -2776,16 +2739,6 @@ func TestFlagAction(t *testing.T) { { name: "flag_uint_error", args: []string{"app", "--f_uint=0"}, - err: "zero uint", - }, - { - name: "flag_uint64", - args: []string{"app", "--f_uint64=1"}, - exp: "1 ", - }, - { - name: "flag_uint64_error", - args: []string{"app", "--f_uint64=0"}, err: "zero uint64", }, { @@ -2940,18 +2893,8 @@ func TestFlagAction(t *testing.T) { return err }, }, - &UintFlag{ - Name: "f_uint", - Action: func(cCtx *Context, v uint) error { - if v == 0 { - return fmt.Errorf("zero uint") - } - _, err := cCtx.Command.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v))) - return err - }, - }, &Uint64Flag{ - Name: "f_uint64", + Name: "f_uint", Action: func(cCtx *Context, v uint64) error { if v == 0 { return fmt.Errorf("zero uint64") @@ -3156,10 +3099,10 @@ func TestFlagDuplicates(t *testing.T) { name: "all args present once", args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10"}, }, - /*{ + { name: "duplicate non slice flag(duplicatable)", args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10", "--iflag", "20"}, - },*/ + }, { name: "duplicate non slice flag(non duplicatable)", args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10", "--sflag", "trip"}, diff --git a/flag_impl.go b/flag_impl.go index a1ddeb90fc..d3e271e6f7 100644 --- a/flag_impl.go +++ b/flag_impl.go @@ -40,9 +40,8 @@ func (f fnValue) Serialize() string { return f.v.String() } -func (f fnValue) IsBoolFlag() bool { return f.isBool } -func (f fnValue) GetFlagValue() Value { return f.v } -func (f fnValue) Count() int { return *f.count } +func (f fnValue) IsBoolFlag() bool { return f.isBool } +func (f fnValue) Count() int { return *f.count } // ValueCreator is responsible for creating a flag.Value emulation // as well as custom formatting diff --git a/flag_test.go b/flag_test.go index 94c95fb1f5..de5b1ccc41 100644 --- a/flag_test.go +++ b/flag_test.go @@ -1151,7 +1151,7 @@ func TestIntSliceFlagApply_UsesEnvValues_noDefault(t *testing.T) { r := require.New(t) r.NoError(fl.Apply(set)) r.NoError(set.Parse(nil)) - //r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get()) + r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get()) } func TestIntSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { @@ -1164,7 +1164,7 @@ func TestIntSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) { r.NoError(fl.Apply(set)) r.NoError(set.Parse(nil)) r.Equal([]int64{3, 4}, val) - //r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get()) + r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get()) } func TestIntSliceFlagApply_DefaultValueWithDestination(t *testing.T) {