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: test coverpkg panics when defining the same flag in multiple packages #27336

Closed
schoentoon opened this issue Aug 29, 2018 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@schoentoon
Copy link

schoentoon commented Aug 29, 2018

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

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="<HOME>/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="<HOME>/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
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/qk/76c0lh7166nbz10bntlqwqw80000gn/T/go-build524001766=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

In a project consisting of multiple binaries I ran the tests using go test -coverpkg=all ./.... I later managed to reproduce this in a small dummy 'project' with the following file structure

./cmd/test1/main.go
./cmd/test2/main.go
./dummy_test.go

Where both main.go files would look like the following

package main

import (
	"flag"
	"fmt"
)

var t = flag.String("t", "", "Dummy value")

func main() {
	fmt.Printf("t is %s\n", *t)
}

A simple go test ./... works just fine, a go test -coverpkg=all ./... would end up panic'ing.

What did you expect to see?

ok  	_/<HOME>/git/test	0.010s
?   	_/<HOME>/git/test/cmd/test1	[no test files]
?   	_/<HOME>/git/test/cmd/test2	[no test files]

What did you see instead?

/var/folders/qk/76c0lh7166nbz10bntlqwqw80000gn/T/go-build966215784/b001/test.test flag redefined: t
panic: /var/folders/qk/76c0lh7166nbz10bntlqwqw80000gn/T/go-build966215784/b001/test.test flag redefined: t

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc00007a120, 0x1196d20, 0xc000060400, 0x1176a02, 0x1, 0x1177c0f, 0xb)
	/usr/local/go/src/flag/flag.go:805 +0x590
flag.(*FlagSet).StringVar(0xc00007a120, 0xc000060400, 0x1176a02, 0x1, 0x0, 0x0, 0x1177c0f, 0xb)
	/usr/local/go/src/flag/flag.go:708 +0x9e
flag.(*FlagSet).String(0xc00007a120, 0x1176a02, 0x1, 0x0, 0x0, 0x1177c0f, 0xb, 0xc0000603f0)
	/usr/local/go/src/flag/flag.go:721 +0x95
flag.String(0x1176a02, 0x1, 0x0, 0x0, 0x1177c0f, 0xb, 0xc0000603f0)
	/usr/local/go/src/flag/flag.go:728 +0x73
FAIL	_/<HOME>/git/test	0.012s
?   	_/<HOME>/git/test/cmd/test1	[no test files]
?   	_/<HOME>/git/test/cmd/test2	[no test files]
@agnivade agnivade changed the title go test coverpkg panics when defining the same flag in multiple packages cmd/go: test coverpkg panics when defining the same flag in multiple packages Aug 29, 2018
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 29, 2018
@agnivade agnivade added this to the Go1.12 milestone Aug 29, 2018
@agnivade
Copy link
Contributor

/cc @bcmills @rsc

@bcmills
Copy link
Contributor

bcmills commented Nov 28, 2018

Duplicate of #23910.

@bcmills bcmills closed this as completed Nov 28, 2018
@golang golang locked and limited conversation to collaborators Nov 28, 2019
@rsc rsc unassigned bcmills Jun 23, 2022
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