@@ -12,11 +12,14 @@ import (
1212func TestGoflags (t * testing.T ) {
1313 goflag .String ("stringFlag" , "stringFlag" , "stringFlag" )
1414 goflag .Bool ("boolFlag" , false , "boolFlag" )
15+ var testxxxValue string
16+ goflag .StringVar (& testxxxValue , "test.xxx" , "test.xxx" , "it is a test flag" )
1517
1618 f := NewFlagSet ("test" , ContinueOnError )
1719
1820 f .AddGoFlagSet (goflag .CommandLine )
19- err := f .Parse ([]string {"--stringFlag=bob" , "--boolFlag" })
21+ args := []string {"--stringFlag=bob" , "--boolFlag" , "-test.xxx=testvalue" }
22+ err := f .Parse (args )
2023 if err != nil {
2124 t .Fatal ("expected no error; get" , err )
2225 }
@@ -40,6 +43,17 @@ func TestGoflags(t *testing.T) {
4043 t .Fatal ("f.Parsed() return false after f.Parse() called" )
4144 }
4245
46+ if testxxxValue != "test.xxx" {
47+ t .Fatalf ("expected testxxxValue to be test.xxx but got %v" , testxxxValue )
48+ }
49+ err = ParseGoTestFlags (args , goflag .CommandLine )
50+ if err != nil {
51+ t .Fatal ("expected no error; ParseGoTestFlags" , err )
52+ }
53+ if testxxxValue != "testvalue" {
54+ t .Fatalf ("expected testxxxValue to be testvalue but got %v" , testxxxValue )
55+ }
56+
4357 // in fact it is useless. because `go test` called flag.Parse()
4458 if ! goflag .CommandLine .Parsed () {
4559 t .Fatal ("goflag.CommandLine.Parsed() return false after f.Parse() called" )
0 commit comments