From 7d1c61cde532d60fcaa188a42e5479f930035018 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Thu, 29 Aug 2019 09:49:36 -0700 Subject: [PATCH] [release-branch.go1.13] cmd/cover: skip go list when profile is empty 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 #33984 Change-Id: I02d4e374405d86f03d105fe14648aa03b4d2284c Reviewed-on: https://go-review.googlesource.com/c/go/+/192340 Reviewed-by: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot (cherry picked from commit 9d480edadc6144d9f9f5a896d729d1642e46083b) Reviewed-on: https://go-review.googlesource.com/c/go/+/192722 --- src/cmd/cover/func.go | 4 ++++ src/cmd/go/testdata/script/cover_mod_empty.txt | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/cmd/go/testdata/script/cover_mod_empty.txt diff --git a/src/cmd/cover/func.go b/src/cmd/cover/func.go index fe64374189..988c4caebf 100644 --- a/src/cmd/cover/func.go +++ b/src/cmd/cover/func.go @@ -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 index 0000000000..3c45243edb --- /dev/null +++ b/src/cmd/go/testdata/script/cover_mod_empty.txt @@ -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 -- -- 2.50.0