Merge remote-tracking branch 'origin/main' into release-metadata

main
Dan Buch 2 years ago
commit 68da1cd6bc
Signed by: meatballhat
GPG Key ID: A12F782281063434

@ -2241,3 +2241,42 @@ func TestTimestampFlagApply_WithDestination(t *testing.T) {
expect(t, err, nil) expect(t, err, nil)
expect(t, *fl.Destination.timestamp, expectedResult) 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")
}
}

Loading…
Cancel
Save