urfave-cli/command_test.go

50 lines
1.0 KiB
Go
Raw Normal View History

2014-04-14 21:44:32 +00:00
package cli_test
import (
2014-06-18 05:33:30 +00:00
"flag"
2014-04-14 21:44:32 +00:00
"testing"
2014-08-04 18:30:13 +00:00
"github.com/codegangsta/cli"
2014-04-14 21:44:32 +00:00
)
func TestCommandDoNotIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah", "-break"}
set.Parse(test)
c := cli.NewContext(app, set, set)
2014-06-18 05:33:30 +00:00
command := cli.Command{
Name: "test-cmd",
Aliases: []string{"tc"},
2014-06-18 05:33:30 +00:00
Usage: "this is for testing",
2014-04-14 21:44:32 +00:00
Description: "testing",
2014-06-18 05:33:30 +00:00
Action: func(_ *cli.Context) {},
2014-04-14 21:44:32 +00:00
}
err := command.Run(c)
expect(t, err.Error(), "flag provided but not defined: -break")
}
func TestCommandIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah"}
set.Parse(test)
c := cli.NewContext(app, set, set)
2014-06-18 05:33:30 +00:00
command := cli.Command{
Name: "test-cmd",
Aliases: []string{"tc"},
2014-06-18 05:33:30 +00:00
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) {},
2014-04-14 21:44:32 +00:00
SkipFlagParsing: true,
}
err := command.Run(c)
expect(t, err, nil)
}