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: 'go tool cover' fails when import path has a '.go' suffix #27096

Open
shuLhan opened this issue Aug 20, 2018 · 7 comments

Comments

@shuLhan
Copy link
Contributor

commented Aug 20, 2018

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

Go 1.11rc1 and bf80e3b

Does this issue reproduce with the latest release?

If by latest release means stable release, then no.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ms/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ms/go"
GOPROXY=""
GORACE=""
GOROOT="/home/ms/Programs/go"
GOTMPDIR=""
GOTOOLDIR="/home/ms/Programs/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build787046816=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  • Create a directory named "gotoolcover.go"
  • Create source and test file, for example, main.go
package main

func printHello() {
        println("Hello")
}

and main_test.go

package main

import "testing"

func TestPrintHello(t *testing.T) {
        printHello()
}
  • Run test with profile coverage,
$ go test -count=1 -coverprofile=cover.out ./...
  • Convert test profile to HTML,
$ go tool cover -html=cover.out -o cover.html

What did you expect to see?

No error.

What did you see instead?

cover: cannot run go list: exit status 1
stat bug/gotoolcover.go: no such file or directory

Notes

  • If I change the directory name to any text, i.e. ".any", it run successfully.
16:03 ~/tmp/sandbox/go/src/bug/gotoolcover.go
master ms 1 % cd ..

16:04 ~/tmp/sandbox/go/src/bug
master ms 0 % mv gotoolcover.go gotoolcover.any

16:04 ~/tmp/sandbox/go/src/bug
master ms 2 % cd gotoolcover.any

16:04 ~/tmp/sandbox/go/src/bug/gotoolcover.any
master ms 0 % go test -count=1 -coverprofile=cover.out ./...
ok      bug/gotoolcover.any     0.001s  coverage: 100.0% of statements

16:04 ~/tmp/sandbox/go/src/bug/gotoolcover.any
master ms 0 % go tool cover -html=cover.out -o cover.html
  • This is not an issue in Go 1.10.3,
16:06 ~/tmp/sandbox/go/src/bug/gotoolcover.any
master ms 0 % go version
go version go1.10.3 linux/amd64

16:06 ~/tmp/sandbox/go/src/bug/gotoolcover.any
master ms 0 % go test -count=1 -coverprofile=cover.out ./...
ok      bug/gotoolcover.any     0.001s  coverage: 100.0% of statements

16:06 ~/tmp/sandbox/go/src/bug/gotoolcover.any
master ms 0 % go tool cover -html=cover.out -o cover.html

16:06 ~/tmp/sandbox/go/src/bug/gotoolcover.any
master ms 0 %
@ALTree ALTree changed the title [cmd/go] "go tool cover" error when running on directory have ".go" suffix cmd/go: "go tool cover" error when running on directory have ".go" suffix Aug 20, 2018
@iamtyler

This comment has been minimized.

Copy link

commented Aug 26, 2018

I ran into this as well. This has pushed me back to 1.10 for code coverage analysis.

@shuLhan FYI in your 1.10.3 example the directory suffix should be .go instead of .any to show it does work in 1.10.3. 😄

@andybons

This comment has been minimized.

Copy link
Member

commented Sep 4, 2018

@andybons andybons added this to the Unplanned milestone Sep 4, 2018
@bcmills bcmills changed the title cmd/go: "go tool cover" error when running on directory have ".go" suffix cmd/go: 'go tool cover' fails when import path has a '.go' suffix Jan 18, 2019
@derekcollison

This comment has been minimized.

Copy link

commented May 14, 2019

Any update in this for a fix? We renamed our NATS.io client to nats.go and are getting support issues ourselves.

@bcmills

This comment has been minimized.

Copy link
Member

commented May 14, 2019

@derekcollison, work on this issue is unplanned (per its milestone).

@derekcollison

This comment has been minimized.

Copy link

commented May 14, 2019

Hmm well that's not good ;)

Seems like should be a one line fix in the Go tooling no?

@bcmills

This comment has been minimized.

Copy link
Member

commented May 14, 2019

@derekcollison, if you have a one-line fix then please send it. 🙂
(https://golang.org/doc/contribute.html)

(CC @jayconrod)

@derekcollison

This comment has been minimized.

Copy link

commented May 16, 2019

I have used that line before to for https://nats.io 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.