Skip to content

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

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?

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 4, 2019
  2. ALTree commented on Sep 4, 2019

    @ALTree
    Member

    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

  3. 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)[/+] on Sep 4, 2019
  4. bcmills commented on Sep 4, 2019

    @bcmills
    Contributor

    Duplicate of #31859

  5. thaJeztah commented on Sep 4, 2019

    @thaJeztah
    ContributorAuthor

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

  6. locked and limited conversation to collaborators on Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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