Skip to content

Why -test.v flag does not work? #238

@urbainleverrier

Description

@urbainleverrier

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions