mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-06 21:48:08 -05:00
Merge pull request #73 from brittinator/master
Adds benchmarking parser and formatter
This commit is contained in:
commit
b27aeca3e6
18
README.md
18
README.md
@ -15,15 +15,31 @@ command:
|
|||||||
go get -u github.com/jstemmer/go-junit-report
|
go get -u github.com/jstemmer/go-junit-report
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
Create an Issue and discuss the fix or feature, then fork the package.
|
||||||
|
Clone to github.com/jstemmer/go-junit-report. This is necessary because go import uses this path.
|
||||||
|
Fix or implement feature. Test and then commit change.
|
||||||
|
Specify #Issue and describe change in the commit message.
|
||||||
|
Create Pull Request. It can be merged by owner or administrator then.
|
||||||
|
|
||||||
|
## Run Tests
|
||||||
|
go test
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
go-junit-report reads the `go test` verbose output from standard in and writes
|
go-junit-report reads the `go test` verbose output from standard in and writes
|
||||||
junit compatible XML to standard out.
|
junit compatible XML to standard out.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go test -v 2>&1 | go-junit-report > report.xml
|
go test -v -count 5 2>&1 | go-junit-report > report.xml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that it also can parse benchmark output with `-bench` flag:
|
||||||
|
```bash
|
||||||
|
go test -v -bench . 2>&1 | ./go-junit-report > report.xml
|
||||||
|
```
|
||||||
|
|
||||||
[travis-badge]: https://travis-ci.org/jstemmer/go-junit-report.svg
|
[travis-badge]: https://travis-ci.org/jstemmer/go-junit-report.svg
|
||||||
[travis-link]: https://travis-ci.org/jstemmer/go-junit-report
|
[travis-link]: https://travis-ci.org/jstemmer/go-junit-report
|
||||||
[report-badge]: https://goreportcard.com/badge/github.com/jstemmer/go-junit-report
|
[report-badge]: https://goreportcard.com/badge/github.com/jstemmer/go-junit-report
|
||||||
|
@ -65,8 +65,9 @@ func JUnitReportXML(report *parser.Report, noXMLHeader bool, goVersion string, w
|
|||||||
|
|
||||||
// convert Report to JUnit test suites
|
// convert Report to JUnit test suites
|
||||||
for _, pkg := range report.Packages {
|
for _, pkg := range report.Packages {
|
||||||
|
pkg.Benchmarks = mergeBenchmarks(pkg.Benchmarks)
|
||||||
ts := JUnitTestSuite{
|
ts := JUnitTestSuite{
|
||||||
Tests: len(pkg.Tests),
|
Tests: len(pkg.Tests) + len(pkg.Benchmarks),
|
||||||
Failures: 0,
|
Failures: 0,
|
||||||
Time: formatTime(pkg.Duration),
|
Time: formatTime(pkg.Duration),
|
||||||
Name: pkg.Name,
|
Name: pkg.Name,
|
||||||
@ -114,6 +115,18 @@ func JUnitReportXML(report *parser.Report, noXMLHeader bool, goVersion string, w
|
|||||||
ts.TestCases = append(ts.TestCases, testCase)
|
ts.TestCases = append(ts.TestCases, testCase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// individual benchmarks
|
||||||
|
for _, benchmark := range pkg.Benchmarks {
|
||||||
|
benchmarkCase := JUnitTestCase{
|
||||||
|
Classname: classname,
|
||||||
|
Name: benchmark.Name,
|
||||||
|
Time: formatBenchmarkTime(benchmark.Duration),
|
||||||
|
Failure: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
ts.TestCases = append(ts.TestCases, benchmarkCase)
|
||||||
|
}
|
||||||
|
|
||||||
suites.Suites = append(suites.Suites, ts)
|
suites.Suites = append(suites.Suites, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +149,35 @@ func JUnitReportXML(report *parser.Report, noXMLHeader bool, goVersion string, w
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mergeBenchmarks(benchmarks []*parser.Benchmark) []*parser.Benchmark {
|
||||||
|
var merged []*parser.Benchmark
|
||||||
|
benchmap := make(map[string][]*parser.Benchmark)
|
||||||
|
for _, bm := range benchmarks {
|
||||||
|
if _, ok := benchmap[bm.Name]; !ok {
|
||||||
|
merged = append(merged, &parser.Benchmark{Name: bm.Name})
|
||||||
|
}
|
||||||
|
benchmap[bm.Name] = append(benchmap[bm.Name], bm)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, bm := range merged {
|
||||||
|
for _, b := range benchmap[bm.Name] {
|
||||||
|
bm.Allocs += b.Allocs
|
||||||
|
bm.Bytes += b.Bytes
|
||||||
|
bm.Duration += b.Duration
|
||||||
|
}
|
||||||
|
n := len(benchmap[bm.Name])
|
||||||
|
bm.Allocs /= n
|
||||||
|
bm.Bytes /= n
|
||||||
|
bm.Duration /= time.Duration(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
return merged
|
||||||
|
}
|
||||||
|
|
||||||
func formatTime(d time.Duration) string {
|
func formatTime(d time.Duration) string {
|
||||||
return fmt.Sprintf("%.3f", d.Seconds())
|
return fmt.Sprintf("%.3f", d.Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatBenchmarkTime(d time.Duration) string {
|
||||||
|
return fmt.Sprintf("%.9f", d.Seconds())
|
||||||
|
}
|
||||||
|
@ -919,6 +919,261 @@ var testCases = []TestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "22-bench.txt",
|
||||||
|
reportName: "22-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "package/basic",
|
||||||
|
Duration: 3212 * time.Millisecond,
|
||||||
|
Time: 3212,
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkParse",
|
||||||
|
Duration: 604 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkReadingList",
|
||||||
|
Duration: 1425 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "23-benchmem.txt",
|
||||||
|
reportName: "23-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "package/one",
|
||||||
|
Duration: 9415 * time.Millisecond,
|
||||||
|
Time: 9415,
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkIpsHistoryInsert",
|
||||||
|
Duration: 52568 * time.Nanosecond,
|
||||||
|
Bytes: 24879,
|
||||||
|
Allocs: 494,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkIpsHistoryLookup",
|
||||||
|
Duration: 15208 * time.Nanosecond,
|
||||||
|
Bytes: 7369,
|
||||||
|
Allocs: 143,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "24-benchtests.txt",
|
||||||
|
reportName: "24-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "package3/baz",
|
||||||
|
Duration: 1382 * time.Millisecond,
|
||||||
|
Time: 1382,
|
||||||
|
Tests: []*parser.Test{
|
||||||
|
{
|
||||||
|
Name: "TestNew",
|
||||||
|
Duration: 0,
|
||||||
|
Time: 0,
|
||||||
|
Result: parser.PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TestNew/no",
|
||||||
|
Duration: 0,
|
||||||
|
Time: 0,
|
||||||
|
Result: parser.PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TestNew/normal",
|
||||||
|
Duration: 0,
|
||||||
|
Time: 0,
|
||||||
|
Result: parser.PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TestWriteThis",
|
||||||
|
Duration: 0,
|
||||||
|
Time: 0,
|
||||||
|
Result: parser.PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkDeepMerge",
|
||||||
|
Duration: 2611 * time.Nanosecond,
|
||||||
|
Bytes: 1110,
|
||||||
|
Allocs: 16,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNext",
|
||||||
|
Duration: 100 * time.Nanosecond,
|
||||||
|
Bytes: 100,
|
||||||
|
Allocs: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "25-benchcount.txt",
|
||||||
|
reportName: "25-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "pkg/count",
|
||||||
|
Duration: 14211 * time.Millisecond,
|
||||||
|
Time: 14211,
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNew",
|
||||||
|
Duration: 350 * time.Nanosecond,
|
||||||
|
Bytes: 80,
|
||||||
|
Allocs: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNew",
|
||||||
|
Duration: 357 * time.Nanosecond,
|
||||||
|
Bytes: 80,
|
||||||
|
Allocs: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNew",
|
||||||
|
Duration: 354 * time.Nanosecond,
|
||||||
|
Bytes: 80,
|
||||||
|
Allocs: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNew",
|
||||||
|
Duration: 358 * time.Nanosecond,
|
||||||
|
Bytes: 80,
|
||||||
|
Allocs: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNew",
|
||||||
|
Duration: 345 * time.Nanosecond,
|
||||||
|
Bytes: 80,
|
||||||
|
Allocs: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFew",
|
||||||
|
Duration: 100 * time.Nanosecond,
|
||||||
|
Bytes: 20,
|
||||||
|
Allocs: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFew",
|
||||||
|
Duration: 105 * time.Nanosecond,
|
||||||
|
Bytes: 20,
|
||||||
|
Allocs: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFew",
|
||||||
|
Duration: 102 * time.Nanosecond,
|
||||||
|
Bytes: 20,
|
||||||
|
Allocs: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFew",
|
||||||
|
Duration: 102 * time.Nanosecond,
|
||||||
|
Bytes: 20,
|
||||||
|
Allocs: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFew",
|
||||||
|
Duration: 102 * time.Nanosecond,
|
||||||
|
Bytes: 20,
|
||||||
|
Allocs: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "26-testbenchmultiple.txt",
|
||||||
|
reportName: "26-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "mycode/common",
|
||||||
|
Duration: 7267 * time.Millisecond,
|
||||||
|
Time: 7267,
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkParse",
|
||||||
|
Duration: 1591 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkNewTask",
|
||||||
|
Duration: 391 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "mycode/benchmarks/channels",
|
||||||
|
Duration: 47084 * time.Millisecond,
|
||||||
|
Time: 47084,
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFanout/Channel/10",
|
||||||
|
Duration: 4673 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFanout/Channel/100",
|
||||||
|
Duration: 24965 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFanout/Channel/1000",
|
||||||
|
Duration: 195672 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkFanout/Channel/10000",
|
||||||
|
Duration: 2410200 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "27-benchdecimal.txt",
|
||||||
|
reportName: "27-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "really/small",
|
||||||
|
Duration: 4344 * time.Millisecond,
|
||||||
|
Time: 4344,
|
||||||
|
Benchmarks: []*parser.Benchmark{
|
||||||
|
{
|
||||||
|
Name: "BenchmarkItsy",
|
||||||
|
Duration: 45 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkTeeny",
|
||||||
|
Duration: 2 * time.Nanosecond,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "BenchmarkWeeny",
|
||||||
|
Duration: 0 * time.Second,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParser(t *testing.T) {
|
func TestParser(t *testing.T) {
|
||||||
@ -994,6 +1249,31 @@ func TestParser(t *testing.T) {
|
|||||||
t.Errorf("Test.Output (%s) ==\n%s\n, want\n%s", test.Name, testOutput, expTestOutput)
|
t.Errorf("Test.Output (%s) ==\n%s\n, want\n%s", test.Name, testOutput, expTestOutput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(pkg.Benchmarks) != len(expPkg.Benchmarks) {
|
||||||
|
t.Fatalf("Package Benchmarks == %d, want %d", len(pkg.Benchmarks), len(expPkg.Benchmarks))
|
||||||
|
}
|
||||||
|
|
||||||
|
for j, benchmark := range pkg.Benchmarks {
|
||||||
|
expBenchmark := expPkg.Benchmarks[j]
|
||||||
|
|
||||||
|
if benchmark.Name != expBenchmark.Name {
|
||||||
|
t.Errorf("Test.Name == %s, want %s", benchmark.Name, expBenchmark.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if benchmark.Duration != expBenchmark.Duration {
|
||||||
|
t.Errorf("benchmark.Duration == %s, want %s", benchmark.Duration, expBenchmark.Duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
if benchmark.Bytes != expBenchmark.Bytes {
|
||||||
|
t.Errorf("benchmark.Bytes == %d, want %d", benchmark.Bytes, expBenchmark.Bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if benchmark.Allocs != expBenchmark.Allocs {
|
||||||
|
t.Errorf("benchmark.Allocs == %d, want %d", benchmark.Allocs, expBenchmark.Allocs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if pkg.CoveragePct != expPkg.CoveragePct {
|
if pkg.CoveragePct != expPkg.CoveragePct {
|
||||||
t.Errorf("Package.CoveragePct == %s, want %s", pkg.CoveragePct, expPkg.CoveragePct)
|
t.Errorf("Package.CoveragePct == %s, want %s", pkg.CoveragePct, expPkg.CoveragePct)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -28,6 +29,7 @@ type Package struct {
|
|||||||
Name string
|
Name string
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
Tests []*Test
|
Tests []*Test
|
||||||
|
Benchmarks []*Benchmark
|
||||||
CoveragePct string
|
CoveragePct string
|
||||||
|
|
||||||
// Time is deprecated, use Duration instead.
|
// Time is deprecated, use Duration instead.
|
||||||
@ -45,12 +47,24 @@ type Test struct {
|
|||||||
Time int // in milliseconds
|
Time int // in milliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Benchmark contains the results of a single benchmark.
|
||||||
|
type Benchmark struct {
|
||||||
|
Name string
|
||||||
|
Duration time.Duration
|
||||||
|
// number of B/op
|
||||||
|
Bytes int
|
||||||
|
// number of allocs/op
|
||||||
|
Allocs int
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
regexStatus = regexp.MustCompile(`--- (PASS|FAIL|SKIP): (.+) \((\d+\.\d+)(?: seconds|s)\)`)
|
regexStatus = regexp.MustCompile(`--- (PASS|FAIL|SKIP): (.+) \((\d+\.\d+)(?: seconds|s)\)`)
|
||||||
regexCoverage = regexp.MustCompile(`^coverage:\s+(\d+\.\d+)%\s+of\s+statements(?:\sin\s.+)?$`)
|
regexCoverage = regexp.MustCompile(`^coverage:\s+(\d+\.\d+)%\s+of\s+statements(?:\sin\s.+)?$`)
|
||||||
regexResult = regexp.MustCompile(`^(ok|FAIL)\s+([^ ]+)\s+(?:(\d+\.\d+)s|\(cached\)|(\[\w+ failed]))(?:\s+coverage:\s+(\d+\.\d+)%\sof\sstatements(?:\sin\s.+)?)?$`)
|
regexResult = regexp.MustCompile(`^(ok|FAIL)\s+([^ ]+)\s+(?:(\d+\.\d+)s|\(cached\)|(\[\w+ failed]))(?:\s+coverage:\s+(\d+\.\d+)%\sof\sstatements(?:\sin\s.+)?)?$`)
|
||||||
regexOutput = regexp.MustCompile(`( )*\t(.*)`)
|
// regexBenchmark captures 3-5 groups: benchmark name, number of times ran, ns/op (with or without decimal), B/op (optional), and allocs/op (optional).
|
||||||
regexSummary = regexp.MustCompile(`^(PASS|FAIL|SKIP)$`)
|
regexBenchmark = regexp.MustCompile(`^(Benchmark[^ ]+)-\d\s+(\d+)\s+(\d+|\d+\.\d+)\sns/op(?:\s+(\d+)\sB/op)?(?:\s+(\d+)\sallocs/op)?`)
|
||||||
|
regexOutput = regexp.MustCompile(`( )*\t(.*)`)
|
||||||
|
regexSummary = regexp.MustCompile(`^(PASS|FAIL|SKIP)$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse parses go test output from reader r and returns a report with the
|
// Parse parses go test output from reader r and returns a report with the
|
||||||
@ -64,10 +78,13 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
// keep track of tests we find
|
// keep track of tests we find
|
||||||
var tests []*Test
|
var tests []*Test
|
||||||
|
|
||||||
|
// keep track of benchmarks we find
|
||||||
|
var benchmarks []*Benchmark
|
||||||
|
|
||||||
// sum of tests' time, use this if current test has no result line (when it is compiled test)
|
// sum of tests' time, use this if current test has no result line (when it is compiled test)
|
||||||
var testsTime time.Duration
|
var testsTime time.Duration
|
||||||
|
|
||||||
// current test
|
// current test or benchmark
|
||||||
var cur string
|
var cur string
|
||||||
|
|
||||||
// keep track if we've already seen a summary for the current test
|
// keep track if we've already seen a summary for the current test
|
||||||
@ -108,6 +125,16 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
// clear the current build package, so output lines won't be added to that build
|
// clear the current build package, so output lines won't be added to that build
|
||||||
capturedPackage = ""
|
capturedPackage = ""
|
||||||
seenSummary = false
|
seenSummary = false
|
||||||
|
} else if matches := regexBenchmark.FindStringSubmatch(line); len(matches) == 6 {
|
||||||
|
bytes, _ := strconv.Atoi(matches[4])
|
||||||
|
allocs, _ := strconv.Atoi(matches[5])
|
||||||
|
|
||||||
|
benchmarks = append(benchmarks, &Benchmark{
|
||||||
|
Name: matches[1],
|
||||||
|
Duration: parseNanoseconds(matches[3]),
|
||||||
|
Bytes: bytes,
|
||||||
|
Allocs: allocs,
|
||||||
|
})
|
||||||
} else if strings.HasPrefix(line, "=== PAUSE ") {
|
} else if strings.HasPrefix(line, "=== PAUSE ") {
|
||||||
continue
|
continue
|
||||||
} else if strings.HasPrefix(line, "=== CONT ") {
|
} else if strings.HasPrefix(line, "=== CONT ") {
|
||||||
@ -137,10 +164,12 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// all tests in this package are finished
|
// all tests in this package are finished
|
||||||
|
|
||||||
report.Packages = append(report.Packages, Package{
|
report.Packages = append(report.Packages, Package{
|
||||||
Name: matches[2],
|
Name: matches[2],
|
||||||
Duration: parseSeconds(matches[3]),
|
Duration: parseSeconds(matches[3]),
|
||||||
Tests: tests,
|
Tests: tests,
|
||||||
|
Benchmarks: benchmarks,
|
||||||
CoveragePct: coveragePct,
|
CoveragePct: coveragePct,
|
||||||
|
|
||||||
Time: int(parseSeconds(matches[3]) / time.Millisecond), // deprecated
|
Time: int(parseSeconds(matches[3]) / time.Millisecond), // deprecated
|
||||||
@ -148,6 +177,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
|
|
||||||
buffers[cur] = buffers[cur][0:0]
|
buffers[cur] = buffers[cur][0:0]
|
||||||
tests = make([]*Test, 0)
|
tests = make([]*Test, 0)
|
||||||
|
benchmarks = make([]*Benchmark, 0)
|
||||||
coveragePct = ""
|
coveragePct = ""
|
||||||
cur = ""
|
cur = ""
|
||||||
testsTime = 0
|
testsTime = 0
|
||||||
@ -206,6 +236,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
Duration: testsTime,
|
Duration: testsTime,
|
||||||
Time: int(testsTime / time.Millisecond),
|
Time: int(testsTime / time.Millisecond),
|
||||||
Tests: tests,
|
Tests: tests,
|
||||||
|
Benchmarks: benchmarks,
|
||||||
CoveragePct: coveragePct,
|
CoveragePct: coveragePct,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -222,6 +253,16 @@ func parseSeconds(t string) time.Duration {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseNanoseconds(t string) time.Duration {
|
||||||
|
// note: if input < 1 ns precision, result will be 0s.
|
||||||
|
if t == "" {
|
||||||
|
return time.Duration(0)
|
||||||
|
}
|
||||||
|
// ignore error
|
||||||
|
d, _ := time.ParseDuration(t + "ns")
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
func findTest(tests []*Test, name string) *Test {
|
func findTest(tests []*Test, name string) *Test {
|
||||||
for i := len(tests) - 1; i >= 0; i-- {
|
for i := len(tests) - 1; i >= 0; i-- {
|
||||||
if tests[i].Name == name {
|
if tests[i].Name == name {
|
||||||
|
@ -24,3 +24,24 @@ func TestParseSeconds(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseNanoseconds(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
in string
|
||||||
|
d time.Duration
|
||||||
|
}{
|
||||||
|
{"", 0},
|
||||||
|
{"0.1", 0 * time.Nanosecond},
|
||||||
|
{"0.9", 0 * time.Nanosecond},
|
||||||
|
{"4", 4 * time.Nanosecond},
|
||||||
|
{"5000", 5 * time.Microsecond},
|
||||||
|
{"2000003", 2*time.Millisecond + 3*time.Nanosecond},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
d := parseNanoseconds(test.in)
|
||||||
|
if d != test.d {
|
||||||
|
t.Errorf("parseSeconds(%q) == %v, want %v\n", test.in, d, test.d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
7
testdata/22-bench.txt
vendored
Normal file
7
testdata/22-bench.txt
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
pkg: code.internal/state
|
||||||
|
BenchmarkParse-8 2000000 604 ns/op
|
||||||
|
BenchmarkReadingList-8 1000000 1425 ns/op
|
||||||
|
PASS
|
||||||
|
ok package/basic 3.212s
|
10
testdata/22-report.xml
vendored
Normal file
10
testdata/22-report.xml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="2" failures="0" time="3.212" name="package/basic">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="basic" name="BenchmarkParse" time="0.000000604"></testcase>
|
||||||
|
<testcase classname="basic" name="BenchmarkReadingList" time="0.000001425"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
7
testdata/23-benchmem.txt
vendored
Normal file
7
testdata/23-benchmem.txt
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
pkg: code.internal/state
|
||||||
|
BenchmarkIpsHistoryInsert-8 30000 52568 ns/op 24879 B/op 494 allocs/op
|
||||||
|
BenchmarkIpsHistoryLookup-8 100000 15208 ns/op 7369 B/op 143 allocs/op
|
||||||
|
PASS
|
||||||
|
ok package/one 9.415s
|
10
testdata/23-report.xml
vendored
Normal file
10
testdata/23-report.xml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="2" failures="0" time="9.415" name="package/one">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="one" name="BenchmarkIpsHistoryInsert" time="0.000052568"></testcase>
|
||||||
|
<testcase classname="one" name="BenchmarkIpsHistoryLookup" time="0.000015208"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
15
testdata/24-benchtests.txt
vendored
Normal file
15
testdata/24-benchtests.txt
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
=== RUN TestNew
|
||||||
|
=== RUN TestNew/no
|
||||||
|
=== RUN TestNew/normal
|
||||||
|
--- PASS: TestNew (0.00s)
|
||||||
|
--- PASS: TestNew/no (0.00s)
|
||||||
|
--- PASS: TestNew/normal (0.00s)
|
||||||
|
=== RUN TestWriteThis
|
||||||
|
--- PASS: TestWriteThis (0.00s)
|
||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
pkg: package3/baz
|
||||||
|
BenchmarkDeepMerge-8 500000 2611 ns/op 1110 B/op 16 allocs/op
|
||||||
|
BenchmarkNext-8 500000 100 ns/op 100 B/op 1 allocs/op
|
||||||
|
PASS
|
||||||
|
ok package3/baz 1.382s
|
14
testdata/24-report.xml
vendored
Normal file
14
testdata/24-report.xml
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="6" failures="0" time="1.382" name="package3/baz">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="baz" name="TestNew" time="0.000"></testcase>
|
||||||
|
<testcase classname="baz" name="TestNew/no" time="0.000"></testcase>
|
||||||
|
<testcase classname="baz" name="TestNew/normal" time="0.000"></testcase>
|
||||||
|
<testcase classname="baz" name="TestWriteThis" time="0.000"></testcase>
|
||||||
|
<testcase classname="baz" name="BenchmarkDeepMerge" time="0.000002611"></testcase>
|
||||||
|
<testcase classname="baz" name="BenchmarkNext" time="0.000000100"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
12
testdata/25-benchcount.txt
vendored
Normal file
12
testdata/25-benchcount.txt
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
BenchmarkNew-8 5000000 350 ns/op 80 B/op 3 allocs/op
|
||||||
|
BenchmarkNew-8 5000000 357 ns/op 80 B/op 3 allocs/op
|
||||||
|
BenchmarkNew-8 5000000 354 ns/op 80 B/op 3 allocs/op
|
||||||
|
BenchmarkNew-8 5000000 358 ns/op 80 B/op 3 allocs/op
|
||||||
|
BenchmarkNew-8 5000000 345 ns/op 80 B/op 3 allocs/op
|
||||||
|
BenchmarkFew-8 5000000 100 ns/op 20 B/op 1 allocs/op
|
||||||
|
BenchmarkFew-8 5000000 105 ns/op 20 B/op 1 allocs/op
|
||||||
|
BenchmarkFew-8 5000000 102 ns/op 20 B/op 1 allocs/op
|
||||||
|
BenchmarkFew-8 5000000 102 ns/op 20 B/op 1 allocs/op
|
||||||
|
BenchmarkFew-8 5000000 102 ns/op 20 B/op 1 allocs/op
|
||||||
|
PASS
|
||||||
|
ok pkg/count 14.211s
|
10
testdata/25-report.xml
vendored
Normal file
10
testdata/25-report.xml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="2" failures="0" time="14.211" name="pkg/count">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="count" name="BenchmarkNew" time="0.000000352"></testcase>
|
||||||
|
<testcase classname="count" name="BenchmarkFew" time="0.000000102"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
19
testdata/26-report.xml
vendored
Normal file
19
testdata/26-report.xml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="2" failures="0" time="7.267" name="mycode/common">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="common" name="BenchmarkParse" time="0.000001591"></testcase>
|
||||||
|
<testcase classname="common" name="BenchmarkNewTask" time="0.000000391"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite tests="4" failures="0" time="47.084" name="mycode/benchmarks/channels">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="channels" name="BenchmarkFanout/Channel/10" time="0.000004673"></testcase>
|
||||||
|
<testcase classname="channels" name="BenchmarkFanout/Channel/100" time="0.000024965"></testcase>
|
||||||
|
<testcase classname="channels" name="BenchmarkFanout/Channel/1000" time="0.000195672"></testcase>
|
||||||
|
<testcase classname="channels" name="BenchmarkFanout/Channel/10000" time="0.002410200"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
12
testdata/26-testbenchmultiple.txt
vendored
Normal file
12
testdata/26-testbenchmultiple.txt
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
pkg: mycode/common
|
||||||
|
BenchmarkParse-8 1000000 1591 ns/op
|
||||||
|
BenchmarkNewTask-8 3000000 391 ns/op
|
||||||
|
PASS
|
||||||
|
ok mycode/common 7.267s
|
||||||
|
pkg: mycode/benchmarks/channels
|
||||||
|
BenchmarkFanout/Channel/10-8 500000 4673 ns/op
|
||||||
|
BenchmarkFanout/Channel/100-8 50000 24965 ns/op
|
||||||
|
BenchmarkFanout/Channel/1000-8 10000 195672 ns/op
|
||||||
|
BenchmarkFanout/Channel/10000-8 500 2410200 ns/op
|
||||||
|
PASS
|
||||||
|
ok mycode/benchmarks/channels 47.084s
|
8
testdata/27-benchdecimal.txt
vendored
Normal file
8
testdata/27-benchdecimal.txt
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
pkg: really/small
|
||||||
|
BenchmarkItsy-8 30000000 45.7 ns/op
|
||||||
|
BenchmarkTeeny-8 1000000000 2.12 ns/op
|
||||||
|
BenchmarkWeeny-8 2000000000 0.26 ns/op
|
||||||
|
PASS
|
||||||
|
ok really/small 4.344s
|
11
testdata/27-report.xml
vendored
Normal file
11
testdata/27-report.xml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="3" failures="0" time="4.344" name="really/small">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="small" name="BenchmarkItsy" time="0.000000045"></testcase>
|
||||||
|
<testcase classname="small" name="BenchmarkTeeny" time="0.000000002"></testcase>
|
||||||
|
<testcase classname="small" name="BenchmarkWeeny" time="0.000000000"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
Loading…
x
Reference in New Issue
Block a user