diff options
author | Rob Pike <r@golang.org> | 2013-06-20 10:27:44 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2013-06-20 10:27:44 -0700 |
commit | 3dba47c8c35453df75edf0c9002ed5f4abacd456 (patch) | |
tree | c6696ee909f6c27c4a03f1077e4e8f5cb29bff4d /src/cmd/go/test.go | |
parent | ac09a7f51f09e3b2f0e12aababda5239936bad47 (diff) | |
download | go-3dba47c8c35453df75edf0c9002ed5f4abacd456.tar.gz |
cmd/go: put the coverage information on the summary line.
Output now:
ok crypto/aes 0.060s coverage: 89.8% of statements
ok crypto/des 0.074s coverage: 92.2% of statements
ok crypto/dsa 0.056s coverage: 34.5% of statements
ok crypto/ecdsa 0.058s coverage: 86.8% of statements
ok crypto/elliptic 0.039s coverage: 94.6% of statements
ok crypto/hmac 0.037s coverage: 93.5% of statements
ok crypto/md5 0.031s coverage: 96.2% of statements
ok crypto/rand 0.074s coverage: 9.9% of statements
ok crypto/rc4 0.090s coverage: 66.7% of statements
ok crypto/rsa 0.253s coverage: 83.5% of statements
R=rsc, adg
CC=golang-dev
https://codereview.appspot.com/10413044
Diffstat (limited to 'src/cmd/go/test.go')
-rw-r--r-- | src/cmd/go/test.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index 2e2352653..32f342288 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -16,6 +16,7 @@ import ( "os/exec" "path" "path/filepath" + "regexp" "runtime" "sort" "strings" @@ -781,7 +782,7 @@ func (b *builder) runTest(a *action) error { if testShowPass { a.testOutput.Write(out) } - fmt.Fprintf(a.testOutput, "ok \t%s\t%s\n", a.p.ImportPath, t) + fmt.Fprintf(a.testOutput, "ok \t%s\t%s%s\n", a.p.ImportPath, t, coveragePercentage(out)) return nil } @@ -797,6 +798,23 @@ func (b *builder) runTest(a *action) error { return nil } +// coveragePercentage returns the coverage results (if enabled) for the +// test. It uncovers the data by scanning the output from the test run. +func coveragePercentage(out []byte) string { + if !testCover { + return "" + } + // The string looks like + // test coverage for encoding/binary: 79.9% of statements + // Extract the piece from the percentage to the end of the line. + re := regexp.MustCompile(`test coverage for [^ ]+: (.*)\n`) + matches := re.FindSubmatch(out) + if matches == nil { + return "(missing coverage statistics)" + } + return fmt.Sprintf("\tcoverage: %s", matches[1]) +} + // cleanTest is the action for cleaning up after a test. func (b *builder) cleanTest(a *action) error { if buildWork { |