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

testing: go test fails with -race and test that calls flag.Parse() (go 1.13) #34073

Closed
thaJeztah opened this issue Sep 4, 2019 · 3 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@thaJeztah
Copy link
Contributor

thaJeztah commented Sep 4, 2019

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

$ go version
go version go1.13 linux/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build162773325=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Go 1.13 regression: go test -race fails if test calls flag.Parse() and additional test-flags are provided

Steps to reproduce:

mkdir 113_regression && cd 113_regression

cat > repro_test.go <<EOF
package main

import "flag"
import "testing"

func init() { flag.Parse() }

func TestHello(t *testing.T) {}
EOF

On Go 1.12

go get golang.org/dl/go1.12.9 && go1.12.9 download

go1.12.9 test -race -test.parallel 8

# PASS
# ok  	_/go/113_regression	1.009s

On Go 1.13, running the test fails

go get golang.org/dl/go1.13 && go1.13 download

go1.13 test -race -test.parallel 8

# flag provided but not defined: -test.parallel
# Usage of /tmp/go-build008991056/b001/113_regression.test:
# exit status 2
# FAIL	_/go/113_regression	0.008s

The problem looks related to calling flag.Parse(). Trying an example on Go 1.13 on a test without flag.Parse()

cat > repro_test.go <<EOF
package main

import "testing"

func TestHello(t *testing.T) {}
EOF


go1.13 test -race -test.parallel 8

# PASS
# ok  	_/go/113_regression	1.009s

What did you expect to see?

What did you see instead?

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 4, 2019
@ALTree
Copy link
Member

ALTree commented Sep 4, 2019

From the 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

@ALTree ALTree changed the title go test fails with -race and test that calls flag.Parse() (go 1.13) testing: go test fails with -race and test that calls flag.Parse() (go 1.13) Sep 4, 2019
@bcmills
Copy link
Member

bcmills commented Sep 4, 2019

Duplicate of #31859

@bcmills bcmills marked this as a duplicate of #31859 Sep 4, 2019
@bcmills bcmills closed this as completed Sep 4, 2019
@thaJeztah
Copy link
Contributor Author

thaJeztah commented Sep 4, 2019

Thanks! Missed that one, and fixed it in my code 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants