Skip to content

Commit 2f55f51

Browse files
Add test
1 parent e77d5b8 commit 2f55f51

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

command_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4096,6 +4096,21 @@ func TestCheckRequiredFlags(t *testing.T) {
40964096
}
40974097
}
40984098

4099+
func TestCheckRequiredFlagsWithOnUsageError(t *testing.T) {
4100+
expectedError := errors.New("OnUsageError")
4101+
cmd := &Command{
4102+
Name: "foo",
4103+
Flags: []Flag{
4104+
&StringFlag{Name: "requiredFlag", Required: true},
4105+
},
4106+
OnUsageError: func(_ context.Context, _ *Command, _ error, _ bool) error {
4107+
return expectedError
4108+
},
4109+
}
4110+
actualError := cmd.Run(buildTestContext(t), []string{"requiredFlag"})
4111+
require.ErrorIs(t, actualError, expectedError)
4112+
}
4113+
40994114
func TestCommand_ParentCommand_Set(t *testing.T) {
41004115
cmd := &Command{
41014116
parent: &Command{

0 commit comments

Comments
 (0)