Remove NewApp
initializer
and move defaulting to `App.Setup`
This commit is contained in:
@@ -22,8 +22,7 @@ func TestCommandFlagParsing(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
app := NewApp()
|
||||
app.Writer = ioutil.Discard
|
||||
app := &App{Writer: ioutil.Discard}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Parse(c.testArgs)
|
||||
|
||||
@@ -47,15 +46,16 @@ func TestCommandFlagParsing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommand_Run_DoesNotOverwriteErrorFromBefore(t *testing.T) {
|
||||
app := NewApp()
|
||||
app.Commands = []*Command{
|
||||
{
|
||||
Name: "bar",
|
||||
Before: func(c *Context) error {
|
||||
return fmt.Errorf("before error")
|
||||
},
|
||||
After: func(c *Context) error {
|
||||
return fmt.Errorf("after error")
|
||||
app := &App{
|
||||
Commands: []*Command{
|
||||
{
|
||||
Name: "bar",
|
||||
Before: func(c *Context) error {
|
||||
return fmt.Errorf("before error")
|
||||
},
|
||||
After: func(c *Context) error {
|
||||
return fmt.Errorf("after error")
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -74,18 +74,19 @@ func TestCommand_Run_DoesNotOverwriteErrorFromBefore(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommand_OnUsageError_WithWrongFlagValue(t *testing.T) {
|
||||
app := NewApp()
|
||||
app.Commands = []*Command{
|
||||
{
|
||||
Name: "bar",
|
||||
Flags: []Flag{
|
||||
&IntFlag{Name: "flag"},
|
||||
},
|
||||
OnUsageError: func(c *Context, err error, _ bool) error {
|
||||
if !strings.HasPrefix(err.Error(), "invalid value \"wrong\"") {
|
||||
t.Errorf("Expect an invalid value error, but got \"%v\"", err)
|
||||
}
|
||||
return errors.New("intercepted: " + err.Error())
|
||||
app := &App{
|
||||
Commands: []*Command{
|
||||
{
|
||||
Name: "bar",
|
||||
Flags: []Flag{
|
||||
&IntFlag{Name: "flag"},
|
||||
},
|
||||
OnUsageError: func(c *Context, err error, _ bool) error {
|
||||
if !strings.HasPrefix(err.Error(), "invalid value \"wrong\"") {
|
||||
t.Errorf("Expect an invalid value error, but got \"%v\"", err)
|
||||
}
|
||||
return errors.New("intercepted: " + err.Error())
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user