diff options
| author | Andrea Tarocchi <[email protected]> | 2025-04-13 11:25:48 +0200 |
|---|---|---|
| committer | Andrea Tarocchi <[email protected]> | 2025-05-14 11:59:31 +0200 |
| commit | 9c97fadb5c53411b3c4f0c1021f605b967632efd (patch) | |
| tree | 9dda321340d46f7f2d86aeaa0d23ceeacb46aa9b /golangflag_test.go | |
| parent | 19c9c4072e41218b18b93dbfc3798c18835d2fd5 (diff) | |
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") |
