summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/pflag/flag_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/pflag/flag_test.go')
-rw-r--r--vendor/github.com/spf13/pflag/flag_test.go66
1 files changed, 62 insertions, 4 deletions
diff --git a/vendor/github.com/spf13/pflag/flag_test.go b/vendor/github.com/spf13/pflag/flag_test.go
index b294fc768..b83a0ed6a 100644
--- a/vendor/github.com/spf13/pflag/flag_test.go
+++ b/vendor/github.com/spf13/pflag/flag_test.go
@@ -333,6 +333,59 @@ func testParse(f *FlagSet, t *testing.T) {
}
}
+func testParseAll(f *FlagSet, t *testing.T) {
+ if f.Parsed() {
+ fmt.Errorf("f.Parse() = true before Parse")
+ }
+ f.BoolP("boola", "a", false, "bool value")
+ f.BoolP("boolb", "b", false, "bool2 value")
+ f.BoolP("boolc", "c", false, "bool3 value")
+ f.BoolP("boold", "d", false, "bool4 value")
+ f.StringP("stringa", "s", "0", "string value")
+ f.StringP("stringz", "z", "0", "string value")
+ f.StringP("stringx", "x", "0", "string value")
+ f.StringP("stringy", "y", "0", "string value")
+ f.Lookup("stringx").NoOptDefVal = "1"
+ args := []string{
+ "-ab",
+ "-cs=xx",
+ "--stringz=something",
+ "-d=true",
+ "-x",
+ "-y",
+ "ee",
+ }
+ want := []string{
+ "boola", "true",
+ "boolb", "true",
+ "boolc", "true",
+ "stringa", "xx",
+ "stringz", "something",
+ "boold", "true",
+ "stringx", "1",
+ "stringy", "ee",
+ }
+ got := []string{}
+ store := func(flag *Flag, value string) error {
+ got = append(got, flag.Name)
+ if len(value) > 0 {
+ got = append(got, value)
+ }
+ return nil
+ }
+ if err := f.ParseAll(args, store); err != nil {
+ t.Errorf("expected no error, got ", err)
+ }
+ if !f.Parsed() {
+ t.Errorf("f.Parse() = false after Parse")
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("f.ParseAll() fail to restore the args")
+ t.Errorf("Got: %v", got)
+ t.Errorf("Want: %v", want)
+ }
+}
+
func TestShorthand(t *testing.T) {
f := NewFlagSet("shorthand", ContinueOnError)
if f.Parsed() {
@@ -398,16 +451,21 @@ func TestParse(t *testing.T) {
testParse(GetCommandLine(), t)
}
+func TestParseAll(t *testing.T) {
+ ResetForTesting(func() { t.Error("bad parse") })
+ testParseAll(GetCommandLine(), t)
+}
+
func TestFlagSetParse(t *testing.T) {
testParse(NewFlagSet("test", ContinueOnError), t)
}
func TestChangedHelper(t *testing.T) {
f := NewFlagSet("changedtest", ContinueOnError)
- _ = f.Bool("changed", false, "changed bool")
- _ = f.Bool("settrue", true, "true to true")
- _ = f.Bool("setfalse", false, "false to false")
- _ = f.Bool("unchanged", false, "unchanged bool")
+ f.Bool("changed", false, "changed bool")
+ f.Bool("settrue", true, "true to true")
+ f.Bool("setfalse", false, "false to false")
+ f.Bool("unchanged", false, "unchanged bool")
args := []string{"--changed", "--settrue", "--setfalse=false"}
if err := f.Parse(args); err != nil {