Skip to content

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

@thaJeztah

Description

@thaJeztah

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions