From c5eb49e3f5d73999821ba4312d040bbe48661a4e Mon Sep 17 00:00:00 2001 From: spf13 Date: Tue, 10 Sep 2013 18:26:46 -0400 Subject: [PATCH] Add better persistent flags testing --- cobra_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cobra_test.go b/cobra_test.go index 38e71727..e545c9bc 100644 --- a/cobra_test.go +++ b/cobra_test.go @@ -223,4 +223,21 @@ func TestPersistentFlags(t *testing.T) { t.Errorf("string flag didn't get correct value, had %v", flags1) } + c = initialize() + cmdEcho.AddCommand(cmdTimes) + c.AddCommand(cmdPrint, cmdEcho) + c.SetArgs(strings.Split("echo times -s again -c test here", " ")) + c.Execute() + + if strings.Join(tt, " ") != "test here" { + t.Errorf("flags didn't leave proper args remaining..%s given", tt) + } + + if flags1 != "again" { + t.Errorf("string flag didn't get correct value, had %v", flags1) + } + + if flagb2 != true { + t.Errorf("local flag not parsed correctly. Expected false, had %v", flagb2) + } }