Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using flag breaks tests #34155

Closed
andy-trimble opened this issue Sep 6, 2019 · 2 comments
Closed

Using flag breaks tests #34155

andy-trimble opened this issue Sep 6, 2019 · 2 comments

Comments

@andy-trimble
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/andrewtrimble/Library/Caches/go-build"
GOENV="/Users/andrewtrimble/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/andrewtrimble/Workspace/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bg/m0hrtm6s7v9drh13khyj29t80000gn/T/go-build368297642=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

main.go

package main

import (
	"flag"
	"fmt"
)

var (
	fl = flag.Bool("fl", false, "")
)

func init() {
	flag.Parse()
}

func main() {
	fmt.Printf("%t\n", *fl)
}

main_test.go

package main

import "testing"

func TestBug(t *testing.T) {

}

What did you expect to see?

go test
PASS
ok      github.com/andy-trimble/flag-bug        0.005s

What did you see instead?

go test
flag provided but not defined: -test.timeout
Usage of /var/folders/bg/m0hrtm6s7v9drh13khyj29t80000gn/T/go-build828887410/b001/flag-bug.test:
  -fl
    
exit status 2
FAIL    github.com/andy-trimble/flag-bug        0.005s
@andy-trimble
Copy link
Author

This is similar to #31859.

@ALTree
Copy link
Member

ALTree commented Sep 6, 2019

This is expected. From the 1.13 release notes:

Testing flags are now registered in the new Init function, which is invoked by the generated main function for the test. As a result, testing flags are now only registered when running a test binary, and packages that call flag.Parse during package initialization may cause tests to fail.

https://tip.golang.org/doc/go1.13#testing

Closing here as a dup of #31859

@ALTree ALTree closed this as completed Sep 6, 2019
@golang golang locked and limited conversation to collaborators Sep 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants