Skip to content

cmd/go: -coverpkg packages imported by all tests, even ones that otherwise do not use it #23910

@ChrisHines

Description

@ChrisHines

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10 windows/amd64

Does this issue reproduce with the latest release?

Yes.

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

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Chris\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Chris\Go
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Chris\AppData\Local\Temp\go-build675280250=/tmp/go-build -gno-record-gcc-switches

What did you do?

>go get github.com/ChrisHines/coverpkgtest

>cd $GOPATH/github.com/ChrisHines/coverpkgtest

>go run main.go
9

>go test ./...
?       github.com/ChrisHines/coverpkgtest      [no test files]
ok      github.com/ChrisHines/coverpkgtest/subdir       (cached)

>go test -coverpkg=./... .
?       github.com/ChrisHines/coverpkgtest      [no test files]

>go test -coverpkg=./... ./subdir
ok      github.com/ChrisHines/coverpkgtest/subdir       0.052s  coverage: 0.0% of statements in ./...

>go test -coverpkg=. ./subdir
warning: no packages being tested depend on matches for pattern .
ok      github.com/ChrisHines/coverpkgtest/subdir       0.057s  coverage: 0.0% of statements in .

>go test -coverpkg=. ./...
?       github.com/ChrisHines/coverpkgtest      [no test files]
panic: open tmpl.txt: The system cannot find the file specified.

goroutine 1 [running]:
text/template.Must(0x0, 0x5c8ba0, 0xc042064390, 0x1)
        C:/Go/src/text/template/helper.go:23 +0x5b
FAIL    github.com/ChrisHines/coverpkgtest/subdir       0.056s

>go test -coverpkg=./... ./...
?       github.com/ChrisHines/coverpkgtest      [no test files]
panic: open tmpl.txt: The system cannot find the file specified.

goroutine 1 [running]:
text/template.Must(0x0, 0x5c8ba0, 0xc042074390, 0x1)
        C:/Go/src/text/template/helper.go:23 +0x5b
FAIL    github.com/ChrisHines/coverpkgtest/subdir       0.055s

What did you expect to see?

I expected the tests to pass regardless of how they are launched by the go tool.

What did you see instead?

Using -coverpkg=./... in combination with the test package pattern ./... caused a panic for a missing file even though the file exists. It is also confusing that running the tests on individual packages or without -coverpkg=./... does not panic.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions