diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index d9b09077c1ae1..3fd697f3df31b 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -723,6 +723,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) { b.IsCmdList = true b.NeedExport = *listExport b.NeedCompiledGoFiles = *listCompiled + if cfg.Experiment.CoverageRedesign && cfg.BuildCover { + load.PrepareForCoverageBuild(pkgs) + } a := &work.Action{} // TODO: Use pkgsFilter? for _, p := range pkgs { @@ -730,9 +733,6 @@ func runList(ctx context.Context, cmd *base.Command, args []string) { a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p)) } } - if cfg.Experiment.CoverageRedesign && cfg.BuildCover { - load.PrepareForCoverageBuild(pkgs) - } b.Do(ctx, a) } diff --git a/src/cmd/go/testdata/script/cover_list.txt b/src/cmd/go/testdata/script/cover_list.txt index 6b8aaf45d1e12..1b1f326662215 100644 --- a/src/cmd/go/testdata/script/cover_list.txt +++ b/src/cmd/go/testdata/script/cover_list.txt @@ -38,6 +38,10 @@ cp stdout $WORK/toolbuildid.txt # Build IDs should match here. cmp $WORK/toolbuildid.txt $WORK/listbuildid.txt +# Make sure that the build succeeds regardless of covermode. +go list -export -covermode=atomic m/example +go list -export -covermode=count m/example + -- go.mod -- module m