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

cmd/go: "go test" passes appends arg which causes flag.Parse() to fail #36709

Closed
integrii opened this issue Jan 23, 2020 · 2 comments
Closed

Comments

@integrii
Copy link

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

$ go version
go version go1.13.6 darwin/amd64

Does this issue reproduce with the latest release?

yes, including beta 1.14beta1

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/ericgreer/go/bin"
GOCACHE="/Users/ericgreer/Library/Caches/go-build"
GOENV="/Users/ericgreer/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ericgreer/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.6/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/nt/y0clsxwx4wjf7w8b9kcb7wgc0000gn/T/go-build151938383=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Here is a simple repo to illustrate the issue. The go test command is appending a -test.timeout flag which causes flag.Parse() to always fail, even when -args is used on go test.

What did you expect to see?

go test -args -f passes -f causing the bool someFlag to be true.

Here is the repo to reproduce this problem. It seems like the automatic appending things onto the arguments line invisibly is confusing and breaks the flag package completely.

What did you see instead?

flag provided but not defined: -test.timeout
Usage of /var/folders/nt/y0clsxwx4wjf7w8b9kcb7wgc0000gn/T/go-build666703793/b001/go-test-bug.test:
  -f	An example bool flag
exit status 2
FAIL	_/Users/ericgreer/git/go-test-bug	0.004s
@AlexRouSg
Copy link
Contributor

See https://golang.org/doc/go1.13#testing and #31859

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.

@ALTree
Copy link
Member

ALTree commented Jan 23, 2020

Yes, this was changed (and documented) in go1.13. See the issue linked above (and the many many issues opened and linked to that one) for more discussion. Closing here.

@ALTree ALTree closed this as completed Jan 23, 2020
@golang golang locked and limited conversation to collaborators Jan 22, 2021
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

4 participants