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: flags from different packages interact with GOEXPERIMENT=nocoverageredesign #65763

Closed
jasonphi opened this issue Feb 16, 2024 · 2 comments

Comments

@jasonphi
Copy link

Go version

1.22

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/jphillips/.cache/go-build'
GOENV='/home/jphillips/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jphillips/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jphillips/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/jphillips/devel/go1.22cover/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1439783943=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Due to #65570 my org wants to disable the coverage redesign in Go 1.22. When doing so via GOEXPERIMENT=nocoverageredesign it results in a panic from flags in different packages seemingly being compiled together.

What did you see happen?

> GOEXPERIMENT=nocoverageredesign go test -v -race -coverpkg=./... -coverprofile=profile.cov ./...
/tmp/go-build4211356336/b001/maina.test flag redefined: a
panic: /tmp/go-build4211356336/b001/maina.test flag redefined: a

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc00014c000, {0x620ed0, 0xc00012a04f}, {0x61fb38, 0x1}, {0x5e6365, 0x6})
        /usr/local/go/src/flag/flag.go:1028 +0x54d
flag.(*FlagSet).BoolVar(...)
        /usr/local/go/src/flag/flag.go:749
flag.(*FlagSet).Bool(0xc00014c000, {0x61fb38, 0x1}, 0x0, {0x5e6365, 0x6})
        /usr/local/go/src/flag/flag.go:762 +0x85
flag.Bool(...)
        /usr/local/go/src/flag/flag.go:769
example.com/go122cover/maina.init()
        /home/jphillips/devel/go1.22cover/maina/main.go:8 +0x4f
FAIL    example.com/go122cover/maina    0.012s
/tmp/go-build4211356336/b096/mainb.test flag redefined: a
panic: /tmp/go-build4211356336/b096/mainb.test flag redefined: a

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000bc000, {0x620ed0, 0xc00001413f}, {0x61fb38, 0x1}, {0x5e6365, 0x6})
        /usr/local/go/src/flag/flag.go:1028 +0x54d
flag.(*FlagSet).BoolVar(...)
        /usr/local/go/src/flag/flag.go:749
flag.(*FlagSet).Bool(0xc0000bc000, {0x61fb38, 0x1}, 0x0, {0x5e6365, 0x6})
        /usr/local/go/src/flag/flag.go:762 +0x85
flag.Bool(...)
        /usr/local/go/src/flag/flag.go:769
example.com/go122cover/mainb.init()
        /home/jphillips/devel/go1.22cover/mainb/main.go:8 +0x4f
FAIL    example.com/go122cover/mainb    0.012s
FAIL

What did you expect to see?

Tests running successfully. The same command runs fine in Go 1.21 and 1.22 without GOEXPERIMENT=nocoverageredesign.

> go test -v -race -coverpkg=./... -coverprofile=profile.cov ./...
=== RUN   TestHelloWorld
hello, world
--- PASS: TestHelloWorld (0.00s)
PASS
coverage: 0.0% of statements in ./...
ok      example.com/go122cover/maina    1.012s  coverage: 0.0% of statements in ./...
=== RUN   TestHelloWorld
hello, world
--- PASS: TestHelloWorld (0.00s)
PASS
coverage: 0.0% of statements in ./...
ok      example.com/go122cover/mainb    1.013s  coverage: 0.0% of statements in ./...
@jasonphi
Copy link
Author

jasonphi commented Feb 16, 2024

-- go.mod --
module play.ground
-- maina/main.go --
package main

import (
	"flag"
	"fmt"
)

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

func main() {
	flag.Parse()
	fmt.Println("Hello, world")
}
-- maina/main_test.go --
package main

import (
	"fmt"
	"testing"
)

func TestHelloWorld(t *testing.T) {
	fmt.Println("hello, world")
}
-- mainb/main.go --
package main

import (
	"flag"
	"fmt"
)

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

func main() {
	flag.Parse()
	fmt.Println("Hello, world")
}
-- mainb/main_test.go --
package main

import (
	"fmt"
	"testing"
)

func TestHelloWorld(t *testing.T) {
	fmt.Println("hello, world")
}

@seankhliao
Copy link
Member

Duplicate of #23910

@seankhliao seankhliao marked this as a duplicate of #23910 Feb 16, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants