Skip to content

Commit

Permalink
Merge pull request #1260 from dearchap/issue_1254
Browse files Browse the repository at this point in the history
Add test case for short option handling
  • Loading branch information
meatballhat committed Apr 24, 2022
2 parents 801780f + 8c5f1fb commit c864c24
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions flag_test.go
Expand Up @@ -2241,3 +2241,42 @@ func TestTimestampFlagApply_WithDestination(t *testing.T) {
expect(t, err, nil)
expect(t, *fl.Destination.timestamp, expectedResult)
}

// Test issue #1254
// StringSlice() with UseShortOptionHandling causes duplicated entries, depending on the ordering of the flags
func TestSliceShortOptionHandle(t *testing.T) {
wasCalled := false
err := (&App{
Commands: []*Command{
{
Name: "foobar",
UseShortOptionHandling: true,
Action: func(ctx *Context) error {
wasCalled = true
if ctx.Bool("i") != true {
t.Error("bool i not set")
}
if ctx.Bool("t") != true {
t.Error("bool i not set")
}
ss := ctx.StringSlice("net")
if !reflect.DeepEqual(ss, []string{"foo"}) {
t.Errorf("Got different slice(%v) than expected", ss)
}
return nil
},
Flags: []Flag{
&StringSliceFlag{Name: "net"},
&BoolFlag{Name: "i"},
&BoolFlag{Name: "t"},
},
},
},
}).Run([]string{"run", "foobar", "--net=foo", "-it"})
if err != nil {
t.Fatal(err)
}
if !wasCalled {
t.Fatal("Action callback was never called")
}
}

0 comments on commit c864c24

Please sign in to comment.