]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cover: skip go list when profile is empty
authorRhys Hiltner <rhys@justin.tv>
Thu, 29 Aug 2019 16:49:36 +0000 (09:49 -0700)
committerBryan C. Mills <bcmills@google.com>
Fri, 30 Aug 2019 17:07:53 +0000 (17:07 +0000)
Only call "go list" when explicitly listing packages. An empty coverage
profile references no packages, and would otherwise lead to "go list"
implicitly looking at the package in "." (which might not exist).

Fixes #33855

Change-Id: I02d4e374405d86f03d105fe14648aa03b4d2284c
Reviewed-on: https://go-review.googlesource.com/c/go/+/192340
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/cover/func.go
src/cmd/go/testdata/script/cover_mod_empty.txt [new file with mode: 0644]

index fe64374189067ae3cd9b930d450e010d1ea98f42..988c4caebffe13dc11e6bffb304016abc5673723 100644 (file)
@@ -191,6 +191,10 @@ func findPkgs(profiles []*Profile) (map[string]*Pkg, error) {
                }
        }
 
+       if len(list) == 0 {
+               return pkgs, nil
+       }
+
        // Note: usually run as "go tool cover" in which case $GOROOT is set,
        // in which case runtime.GOROOT() does exactly what we want.
        goTool := filepath.Join(runtime.GOROOT(), "bin/go")
diff --git a/src/cmd/go/testdata/script/cover_mod_empty.txt b/src/cmd/go/testdata/script/cover_mod_empty.txt
new file mode 100644 (file)
index 0000000..3c45243
--- /dev/null
@@ -0,0 +1,9 @@
+go tool cover -func=cover.out
+stdout total.*statements.*0.0%
+
+go mod init golang.org/issue/33855
+
+go tool cover -func=cover.out
+stdout total.*statements.*0.0%
+
+-- cover.out --