diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-04-24 20:11:36 -0400 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-04-24 20:11:36 -0400 |
commit | f5437632f486b7d0a0a181c58f113c86d032b02c (patch) | |
tree | 407388e3003a210a89f4b2128d7ad656f8b79d26 /vendor/github.com/spf13/cobra/command_test.go | |
parent | 7f68a60f8c228d5604e0566bf84cabb145d16c37 (diff) | |
download | chat-f5437632f486b7d0a0a181c58f113c86d032b02c.tar.gz chat-f5437632f486b7d0a0a181c58f113c86d032b02c.tar.bz2 chat-f5437632f486b7d0a0a181c58f113c86d032b02c.zip |
Upgrading server dependancies (#6215)
Diffstat (limited to 'vendor/github.com/spf13/cobra/command_test.go')
-rw-r--r-- | vendor/github.com/spf13/cobra/command_test.go | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/vendor/github.com/spf13/cobra/command_test.go b/vendor/github.com/spf13/cobra/command_test.go index 7947f6c4a..3921a0be7 100644 --- a/vendor/github.com/spf13/cobra/command_test.go +++ b/vendor/github.com/spf13/cobra/command_test.go @@ -6,6 +6,8 @@ import ( "os" "reflect" "testing" + + "github.com/spf13/pflag" ) // test to ensure hidden commands run as intended @@ -191,8 +193,15 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) { EnableCommandSorting = true } -func TestFlagErrorFunc(t *testing.T) { +func TestSetOutput(t *testing.T) { + cmd := &Command{} + cmd.SetOutput(nil) + if out := cmd.OutOrStdout(); out != os.Stdout { + t.Fatalf("expected setting output to nil to revert back to stdout, got %v", out) + } +} +func TestFlagErrorFunc(t *testing.T) { cmd := &Command{ Use: "print", RunE: func(cmd *Command, args []string) error { @@ -214,3 +223,38 @@ func TestFlagErrorFunc(t *testing.T) { t.Errorf("expected %v, got %v", expected, err.Error()) } } + +// TestSortedFlags checks, +// if cmd.LocalFlags() is unsorted when cmd.Flags().SortFlags set to false. +// https://github.com/spf13/cobra/issues/404 +func TestSortedFlags(t *testing.T) { + cmd := &Command{} + cmd.Flags().SortFlags = false + names := []string{"C", "B", "A", "D"} + for _, name := range names { + cmd.Flags().Bool(name, false, "") + } + + i := 0 + cmd.LocalFlags().VisitAll(func(f *pflag.Flag) { + if i == len(names) { + return + } + if contains(f.Name, names) { + if names[i] != f.Name { + t.Errorf("Incorrect order. Expected %v, got %v", names[i], f.Name) + } + i++ + } + }) +} + +// contains checks, if s is in ss. +func contains(s string, ss []string) bool { + for _, v := range ss { + if v == s { + return true + } + } + return false +} |