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=./... fails to change working directory #33016

Closed
jba opened this issue Jul 9, 2019 · 1 comment
Closed

cmd/go: test -coverpkg=./... fails to change working directory #33016

jba opened this issue Jul 9, 2019 · 1 comment

Comments

@jba
Copy link
Contributor

@jba jba commented Jul 9, 2019

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

$ go version
go version go1.12.5 linux/amd64   

Also at tip: go version devel +84fce9832b Tue Jul 9 19:21:43 2019 +0000 linux/amd64

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/jba/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/jba/go"
GOPROXY="https://proxy.golang.org"
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/usr/local/google/home/jba/git-repos/go-cloud/samples/go.mod"
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=/tmp/go-build539152533=/tmp/go-build -gno-record-gcc-switches"   

What did you do?

git clone https://github.com/jba/go-cloud 
cd go-cloud/samples
git checkout coverbug
go test -v -coverpkg=./...  ./...  

What did you expect to see?

Output of go test -v ./...:

=== RUN   Test
--- PASS: Test (0.00s)
PASS
ok      gocloud.dev/samples/gocdk-blob  0.137s
#### /tmp/go-cloud/samples/order <nil>
=== RUN   TestOrderForm
--- PASS: TestOrderForm (0.00s)
=== RUN   TestCreateOrder
--- PASS: TestCreateOrder (0.00s)
=== RUN   TestListOrders
--- PASS: TestListOrders (0.00s)
=== RUN   TestHandleRequest
2019/07/09 18:18:32 received {ID:x Email: InImage: CreateTime:0001-01-01 00:00:00 +0000 UTC}
--- PASS: TestHandleRequest (0.00s)
=== RUN   TestProcessOrder
--- PASS: TestProcessOrder (4.03s)
PASS
ok      gocloud.dev/samples/order       4.124s

What did you see instead?

> go test -v -coverpkg=./...  ./...
#### /tmp/go-cloud/samples/gocdk-blob <nil>
panic: open list.htmlt: no such file or directory

goroutine 1 [running]:
html/template.Must(...)
        /usr/lib/google-golang/src/html/template/template.go:373
gocloud.dev/samples/order.init.0()
        /tmp/go-cloud/samples/order/frontend.go:54 +0x23e
FAIL    gocloud.dev/samples/gocdk-blob  0.261s
#### /tmp/go-cloud/samples/order <nil>
=== RUN   TestOrderForm
--- PASS: TestOrderForm (0.00s)
=== RUN   TestCreateOrder
--- PASS: TestCreateOrder (0.00s)
=== RUN   TestListOrders
--- PASS: TestListOrders (0.00s)
=== RUN   TestHandleRequest
2019/07/09 18:19:04 received {ID:x Email: InImage: CreateTime:0001-01-01 00:00:00 +0000 UTC}
--- PASS: TestHandleRequest (0.00s)
=== RUN   TestProcessOrder
--- PASS: TestProcessOrder (4.03s)
PASS
coverage: 37.6% of statements in ./...
ok      gocloud.dev/samples/order       4.182s  coverage: 37.6% of statements in ./...

Note the line beginning with ####. This is the working directory of the samples/order test binary. In the bad case, it is .../samples/gocdk-blob instead of .../samples/gocdk-order.

NOTE: To test against tip, you will need to replace golang.org/x/xerrors with the contents of https://go-review.googlesource.com/c/xerrors/+/184937.

@jayconrod jayconrod added this to the Go1.14 milestone Jul 9, 2019
@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Jul 10, 2019

Reproduced, but it looks like this is working as intended.

The gocloud.dev/samples/order package tries to open the file "list.htmlt" in its initialization.

When the test gocloud.dev/samples/gocdk-blog is built, it includes the order package. -coverpkg=./... will cause the packages ./... to be instrumented and linked into each test binary, and that includes order. So when order is initialized within the gocdk-blog executable, it fails because it's run from the gocdk-blog directory.

@jayconrod jayconrod closed this Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.