Merge commit '0d0d329' into v3-porting

This commit is contained in:
2022-11-07 08:27:19 -05:00
13 changed files with 293 additions and 423 deletions

View File

@@ -683,24 +683,6 @@ func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
expect(t, cCtx.String("lang"), "spanish")
}
func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) {
a := App{
Name: "cmd",
Flags: []Flag{
&StringFlag{Name: "foo"},
},
Writer: bytes.NewBufferString(""),
}
set := flag.NewFlagSet("", flag.ContinueOnError)
_ = set.Parse([]string{"", "-bar"})
c := &Context{flagSet: set}
err := a.RunAsSubcommand(c)
expect(t, err.Error(), "flag provided but not defined: -bar")
}
func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) {
var parsedOption string
var args Args
@@ -1547,6 +1529,9 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) {
Subcommands: []*Command{{
Name: "mySubCommand",
Flags: []Flag{&StringFlag{Name: "requiredFlag", Required: true}},
Action: func(c *Context) error {
return nil
},
}},
}},
},
@@ -1929,12 +1914,12 @@ func TestApp_Run_CommandHelpName(t *testing.T) {
output := buf.String()
expected := "command foo bar - does bar things"
expected := "command custom bar - does bar things"
if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %s", expected, output)
}
expected = "command foo bar [command options] [arguments...]"
expected = "command custom bar [command options] [arguments...]"
if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %s", expected, output)
}
@@ -2036,7 +2021,7 @@ func TestApp_Run_Help(t *testing.T) {
}
err := app.Run(tt.helpArguments)
if err != nil && err.Error() != tt.wantErr.Error() {
if err != nil && tt.wantErr != nil && err.Error() != tt.wantErr.Error() {
t.Errorf("want err: %s, did note %s\n", tt.wantErr, err)
}