-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/cover: cannot find package in local directory outside GOPATH #17269
Comments
As basically everything the go tool works on has to be under GOPATH I think the "fix" should be the other way around: The original |
If thats the case then I agree |
We could have cover run 'go list -json .' or just build.Import(".") and if it succeeds and produces the import path we're looking for, use that. |
How about de-normalize prefixes? diff --git a/src/cmd/cover/func.go b/src/cmd/cover/func.go
index 66ec242..feeb799 100644
--- a/src/cmd/cover/func.go
+++ b/src/cmd/cover/func.go
@@ -15,6 +15,9 @@ import (
"go/token"
"os"
"path/filepath"
+ "regexp"
+ "runtime"
+ "strings"
"text/tabwriter"
)
@@ -54,7 +57,7 @@ func funcOutput(profile, outputFile string) error {
var total, covered int64
for _, profile := range profiles {
- fn := profile.FileName
+ fn := denormalize(profile.FileName)
file, err := findFile(fn)
if err != nil {
return err
@@ -153,12 +156,31 @@ func (f *FuncExtent) coverage(profile *Profile) (num, den int64) {
return covered, total
}
+func denormalize(file string) string {
+ if runtime.GOOS == "windows" {
+ re := regexp.MustCompile(`^_\\([A-Z])_\\`)
+ if re.MatchString(file) {
+ m := re.FindStringSubmatch(file)
+ if len(m) == 2 {
+ file = m[1] + ":" + file[4:]
+ }
+ }
+ } else {
+ if strings.HasPrefix(file, "_/") {
+ file = file[2:]
+ }
+ }
+ return file
+}
+
// findFile finds the location of the named file in GOROOT, GOPATH etc.
func findFile(file string) (string, error) {
dir, file := filepath.Split(file)
pkg, err := build.Import(dir, ".", build.FindOnly)
if err != nil {
- return "", fmt.Errorf("can't find %q: %v", file, err)
+ if _, err2 := os.Stat(file); err2 != nil {
+ return "", fmt.Errorf("can't find %q: %v", file, err)
+ }
}
return filepath.Join(pkg.Dir, file), nil
} I'm not sure |
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
`go tool cover` and `go test` create package paths differently when code is not inside a "src" directory, and circleci doesn't clone code into a src directory. golang/go#17269
Moving to Go 1.11. Will need to revisit with package management anyway. |
I've just run into this. I suppose I'll have to edit my GOPATH, but it would be nice to shed the importance of that ENV variable, instead establish expectations of folder structures or as mentioned above a json file |
probably no longer relevant with modules. |
version go1.7.1 darwin/amd64
When I try the following
I get this coverage.out:
But when I then do
the cover tool doesn't understand "_/Users/gert/Desktop/httx/"
Note that
go test -cover
works.I tried to be sure if I wasn't doing something wrong and asked on slack and stackoverflow
Can the cover tool first check for "_/Users/gert/Desktop/httx/auth.go" in the directory the go tool cover is launched in like
go test -cover
does?For me it's counter intuitive to be forced to put it in your GOPATH for it to work.
The text was updated successfully, but these errors were encountered: