]> Cypherpunks repositories - gostls13.git/commit
cmd{cover,covdata,go}: better coverage for tests that build tools
authorThan McIntosh <thanm@google.com>
Wed, 18 May 2022 22:48:56 +0000 (18:48 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 29 Sep 2022 14:13:50 +0000 (14:13 +0000)
commitf2ee3414689add84c6e6d2d3f44dacde5129b18d
treeabe1be466d83d0c3ea1a7468d9f285ac09dd7d5b
parent9d6dc32edd03f24a3ecacfcf4cdf54f561834c33
cmd{cover,covdata,go}: better coverage for tests that build tools

Some of the unit tests in Go's "cmd" tree wind up building a separate
copy of the tool being tested, then exercise the freshly built tool as
a way of doing regression tests. The intent is to make sure that "go
test" is testing the current state of the source code, as opposed to
whatever happened to be current when "go install <tool>" was last run.

Doing things this way is unfriendly for coverage testing. If I run "go
test -cover cmd/mumble", and the cmd/mumble test harness builds a
fresh copy of mumble.exe, any runs of that new executable won't
generate coverage data.

This patch updates the test harnesses to use the unit test executable
as a stand-in for the tool itself, so that if "go test -cover" is in
effect, we get the effect of building the tool executable for coverage
as well. Doing this brings up the overall test coverage number for
cmd/cover quite dramatically:

before change:

  $ go test -cover .
  ok   cmd/cover 1.100s coverage: 1.5% of statements

after change:

  $ go test -cover .
  ok   cmd/cover 1.299s coverage: 84.2% of statements

Getting this to work requires a small change in the Go command as
well, to set GOCOVERDIR prior to executing a test binary.

Updates #51430.

Change-Id: Ifcf0ea85773b80fcda794aae3702403ec8e0b733
Reviewed-on: https://go-review.googlesource.com/c/go/+/404299
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/covdata/export_test.go [new file with mode: 0644]
src/cmd/covdata/tool_test.go
src/cmd/cover/cfg_test.go
src/cmd/cover/cover_test.go
src/cmd/cover/export_test.go [new file with mode: 0644]
src/cmd/cover/testdata/toolexec.go [deleted file]
src/cmd/go/internal/test/test.go