]> Cypherpunks repositories - gostls13.git/commit
cmd/{go,cover,covdata}: fix 'package main' inconsistent handling
authorThan McIntosh <thanm@google.com>
Thu, 8 Dec 2022 15:58:49 +0000 (10:58 -0500)
committerThan McIntosh <thanm@google.com>
Thu, 8 Dec 2022 18:29:31 +0000 (18:29 +0000)
commit7973b0e50861c49c1852a545b51b7ab977135d6d
tree5468b5cfc4fd900f4095282360c1e666abe0578e
parent0aad4d3257d59de460bfe52e59dac4e357082fa1
cmd/{go,cover,covdata}: fix 'package main' inconsistent handling

Fix a buglet in cmd/cover in how we handle package name/path for the
"go build -o foo.exe *.go" and "go run *.go" cases.

The go command assigns a dummy import path of "command-line-arguments"
to the main package built in these cases; rather than expose this
dummy to the user in coverage reports, the cover tool had a special
case hack intended to rewrite such package paths to "main". The hack
was too general, however, and was rewriting the import path of all
packages with (p.name == "main") to an import path of "main". The hack
also produced unexpected results for cases such as

  go test -cover foo.go foo_test.go

This patch removes the hack entirely, leaving the package path for
such cases as "command-line-arguments".

Fixes #57169.

Change-Id: Ib6071db5e3485da3b8c26e16ef57f6fa1712402c
Reviewed-on: https://go-review.googlesource.com/c/go/+/456237
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/covdata/tool_test.go
src/cmd/cover/cover.go
src/cmd/go/testdata/script/cover_build_cmdline_pkgs.txt
src/cmd/go/testdata/script/cover_main_import_path.txt [new file with mode: 0644]
src/runtime/coverage/emitdata_test.go