Navigation Menu

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

Closed
shuLhan opened this issue Aug 20, 2018 · 8 comments
Closed

cmd/go: 'go tool cover' fails when import path has a '.go' suffix #27096

shuLhan opened this issue Aug 20, 2018 · 8 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@shuLhan
Copy link
Contributor

shuLhan 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
Copy link

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
Copy link
Member

andybons commented Sep 4, 2018

@rsc @bcmills

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label 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
Copy link

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

@bcmills
Copy link
Contributor

bcmills commented May 14, 2019

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

@derekcollison
Copy link

Hmm well that's not good ;)

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

@bcmills
Copy link
Contributor

bcmills 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
Copy link

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

@agnivade
Copy link
Contributor

This is fixed now:

11:29:22-agniva-/tmp/gotoolcover.go$ll
total 72
drwxr-xr-x   2 agniva agniva  4096 Oct 22 11:29 ./
drwxrwxrwt 107 root   root   57344 Oct 22 11:29 ../
-rw-r--r--   1 agniva agniva    63 Oct 22 11:21 main.go
-rw-r--r--   1 agniva agniva    92 Oct 22 11:21 main_test.go
11:29:23-agniva-/tmp/gotoolcover.go$gotip test -count=1 -coverprofile=cover.out ./...
ok  	_/tmp/gotoolcover.go	0.001s	coverage: 100.0% of statements
11:29:26-agniva-/tmp/gotoolcover.go$

@golang golang locked and limited conversation to collaborators Oct 21, 2020
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

7 participants