From 1ce0cc6db4029d97571db82f85092fccedb572ce Mon Sep 17 00:00:00 2001 From: childe Date: Tue, 3 Apr 2018 19:55:18 +0800 Subject: make x.Parsed() return true after AddGoFlagSet(x) and pflag.Parse() (#162) * make GoFlagSets.Parsed() true after pflag.Parse some third part lib such as glog use go flag package, and its some actions depends on if goflag.Parsed(). * add test case for goflag.CommandLine.Parsed() * add comment to goflag.CommandLine.Parsed test case --- golangflag_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'golangflag_test.go') diff --git a/golangflag_test.go b/golangflag_test.go index 77e2d7d..5bd831b 100644 --- a/golangflag_test.go +++ b/golangflag_test.go @@ -36,4 +36,12 @@ func TestGoflags(t *testing.T) { if getBool != true { t.Fatalf("expected getBool=true but got getBool=%v", getBool) } + if !f.Parsed() { + t.Fatal("f.Parsed() return false after f.Parse() called") + } + + // in fact it is useless. because `go test` called flag.Parse() + if !goflag.CommandLine.Parsed() { + t.Fatal("goflag.CommandLine.Parsed() return false after f.Parse() called") + } } -- cgit v1.2.3