From 710c8f71c46f4d1d3c54cc554c7479d16c6c0a76 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Sat, 2 May 2020 19:45:17 +0200 Subject: [PATCH 1/2] test(context): Added regression test for requiredFlagsError This adds a test verifying that the requiredFlagsError does contain the long option of the missing flag, instead of the short option and a space, which was the old behaviour. Signed-off-by: Ole Petter (cherry picked from commit f842187ebb32ee7d5109783d02fe9902b68ee54e) --- context_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/context_test.go b/context_test.go index f302caf..2692b2a 100644 --- a/context_test.go +++ b/context_test.go @@ -534,6 +534,14 @@ func TestCheckRequiredFlags(t *testing.T) { }, parseInput: []string{"-n", "asd", "-n", "qwe"}, }, + { + testCase: "required_flag_with_short_alias_not_printed_on_error", + expectedAnError: true, + expectedErrorContents: []string{"Required flag \"names\" not set"}, + flags: []Flag{ + StringSliceFlag{Name: "names, n", Required: true}, + }, + }, } for _, test := range tdata { From 48392103ce8be0b28d0e9f24660dd71d223e0cf8 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Sun, 3 May 2020 11:08:30 +0200 Subject: [PATCH 2/2] test(context): Change the StringSliceFlag to a pointer StringSliceFlag needs to be a pointer, and not a struct. Also formatted the test. See: https://github.com/urfave/cli/pull/1126 for a description of the regression tested for. Signed-off-by: Ole Petter --- context_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/context_test.go b/context_test.go index 2692b2a..61d6268 100644 --- a/context_test.go +++ b/context_test.go @@ -535,11 +535,11 @@ func TestCheckRequiredFlags(t *testing.T) { parseInput: []string{"-n", "asd", "-n", "qwe"}, }, { - testCase: "required_flag_with_short_alias_not_printed_on_error", - expectedAnError: true, + testCase: "required_flag_with_short_alias_not_printed_on_error", + expectedAnError: true, expectedErrorContents: []string{"Required flag \"names\" not set"}, flags: []Flag{ - StringSliceFlag{Name: "names, n", Required: true}, + &StringSliceFlag{Name: "names, n", Required: true}, }, }, }