diff options
| author | Tomas Aschan <[email protected]> | 2025-05-14 21:39:01 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-14 21:39:01 +0200 |
| commit | 7322552c7c20c512a8b5bedeb1ad4a9504fcee00 (patch) | |
| tree | 8f65bfadb6ff474bb04d04683e7a3b3cfeab38a6 /golangflag_test.go | |
| parent | 957ea4b77e38a9c6673053aa3513a727393b6941 (diff) | |
| parent | 9c97fadb5c53411b3c4f0c1021f605b967632efd (diff) | |
Merge pull request #424 from valdar/issue/423
fix #423 : Add helper function and some documentation to parse shorthand go test flags.
Diffstat (limited to 'golangflag_test.go')
| -rw-r--r-- | golangflag_test.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/golangflag_test.go b/golangflag_test.go index 5bd831b..2ecefef 100644 --- a/golangflag_test.go +++ b/golangflag_test.go @@ -12,11 +12,14 @@ import ( func TestGoflags(t *testing.T) { goflag.String("stringFlag", "stringFlag", "stringFlag") goflag.Bool("boolFlag", false, "boolFlag") + var testxxxValue string + goflag.StringVar(&testxxxValue, "test.xxx", "test.xxx", "it is a test flag") f := NewFlagSet("test", ContinueOnError) f.AddGoFlagSet(goflag.CommandLine) - err := f.Parse([]string{"--stringFlag=bob", "--boolFlag"}) + args := []string{"--stringFlag=bob", "--boolFlag", "-test.xxx=testvalue"} + err := f.Parse(args) if err != nil { t.Fatal("expected no error; get", err) } @@ -40,6 +43,17 @@ func TestGoflags(t *testing.T) { t.Fatal("f.Parsed() return false after f.Parse() called") } + if testxxxValue != "test.xxx" { + t.Fatalf("expected testxxxValue to be test.xxx but got %v", testxxxValue) + } + err = ParseSkippedFlags(args, goflag.CommandLine) + if err != nil { + t.Fatal("expected no error; ParseSkippedFlags", err) + } + if testxxxValue != "testvalue" { + t.Fatalf("expected testxxxValue to be testvalue but got %v", testxxxValue) + } + // 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") |
