forked from ogier/pflag
-
Notifications
You must be signed in to change notification settings - Fork 360
Closed
Description
I want to use pflag package with testing. Such as...
package main
import (
"fmt"
"os"
"testing"
goflag "flag"
"github.com/spf13/pflag"
)
var ip *int = pflag.Int("flagname", 1234, "help message for flagname")
func TestMain(m *testing.M) {
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
pflag.Parse()
os.Exit(m.Run())
}
func TestHello(t *testing.T) {
fmt.Printf("-test.v is specified %t\n", testing.Verbose()) // -> -test.v is specified false
if *ip != 5678 {
t.Fatal("not good.")
}
t.Log("called") // -> No output
}
Which results in:
$ go test main_test.go --flagname 5678 -v
-test.v is specified false
PASS
ok command-line-arguments 0.006s
Could you give me some advice?
Go version: 1.13.6
pflag version: v1.0.5
aLekSer
Metadata
Metadata
Assignees
Labels
No labels