aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/coverage/testsupport.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2022-09-19 14:55:09 -0400
committerThan McIntosh <thanm@google.com>2022-09-29 14:13:26 +0000
commit9d6dc32edd03f24a3ecacfcf4cdf54f561834c33 (patch)
treeebdd3e7b71ca6faf763994aa37e7ec07f2cc3c5e /src/runtime/coverage/testsupport.go
parent690851ee3e48b85088698a9dbcc7dd112cef9eb5 (diff)
downloadgo-9d6dc32edd03f24a3ecacfcf4cdf54f561834c33.tar.xz
runtime/coverage: improve unit tests
Add a testpoint to cover support routines used to help implement "go test -cover". Change-Id: Ic28bf884a4e0d2c0a6d8fd04fc29c0c949227f21 Reviewed-on: https://go-review.googlesource.com/c/go/+/432315 Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/runtime/coverage/testsupport.go')
-rw-r--r--src/runtime/coverage/testsupport.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/runtime/coverage/testsupport.go b/src/runtime/coverage/testsupport.go
index 0d0605c0f2..462d06c878 100644
--- a/src/runtime/coverage/testsupport.go
+++ b/src/runtime/coverage/testsupport.go
@@ -13,6 +13,7 @@ import (
"internal/coverage/decodecounter"
"internal/coverage/decodemeta"
"internal/coverage/pods"
+ "io"
"os"
)
@@ -21,6 +22,12 @@ import (
// intended to be used other than internally by the Go command's
// generated code.
func processCoverTestDir(dir string, cfile string, cm string, cpkg string) error {
+ return processCoverTestDirInternal(dir, cfile, cm, cpkg, os.Stdout)
+}
+
+// processCoverTestDirInternal is an io.Writer version of processCoverTestDir,
+// exposed for unit testing.
+func processCoverTestDirInternal(dir string, cfile string, cm string, cpkg string, w io.Writer) error {
cmode := coverage.ParseCounterMode(cm)
if cmode == coverage.CtrModeInvalid {
return fmt.Errorf("invalid counter mode %q", cm)
@@ -80,7 +87,7 @@ func processCoverTestDir(dir string, cfile string, cm string, cpkg string) error
}
// Emit percent.
- if err := ts.cf.EmitPercent(os.Stdout, cpkg, true); err != nil {
+ if err := ts.cf.EmitPercent(w, cpkg, true); err != nil {
return err
}