Closed
Description
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
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]cmd/go: test -coverpkg=./... ./... incompatible with template.Must for local files.[/-][+]cmd/go: -coverpkg packages imported by all tests, even ones that otherwise do not use it[/+]ianlancetaylor commentedon Mar 28, 2018
I think the problem is that cmd/go rewrites tests to import all packages listed in
-coverpkgs
. It then runs the test for packagesubdir
in thesubdir
directory. In your case the main package is listed in-coverpkgs
, so the test imports it. The only thing that is run in the main package is the initializers. In your program that is what fails: the initializer loads a relative file and can only run in the main package directory, not in the subdirectory.Not sure what the right fix is.
rsc commentedon Apr 18, 2018
/cc @bcmills
nvartolomei commentedon Nov 28, 2018
Sounds like #27336
29 remaining items