1
0
mirror of https://github.com/jstemmer/go-junit-report.git synced 2025-04-10 15:48:08 -05:00

Capture more test output, e.g. race detection results

This commit is contained in:
Ingmar Stein 2017-06-22 12:43:57 +02:00
parent 15422cf504
commit 01656fa7f4
4 changed files with 126 additions and 6 deletions

@ -71,7 +71,9 @@ var testCases = []TestCase{
Name: "TestTwo",
Time: 130,
Result: parser.PASS,
Output: []string{},
Output: []string{
"exit status 1",
},
},
},
},
@ -201,7 +203,9 @@ var testCases = []TestCase{
Name: "TestTwo",
Time: 130,
Result: parser.PASS,
Output: []string{},
Output: []string{
"exit status 1",
},
},
},
},
@ -642,6 +646,63 @@ var testCases = []TestCase{
},
},
},
{
name: "17-race.txt",
reportName: "17-report.xml",
report: &parser.Report{
Packages: []parser.Package{
{
Name: "race_test",
Time: 15,
Tests: []*parser.Test{
{
Name: "TestRace",
Time: 0,
Result: parser.FAIL,
Output: []string{
"test output",
"2 0xc4200153d0",
"==================",
"WARNING: DATA RACE",
"Write at 0x00c4200153d0 by goroutine 7:",
" race_test.TestRace.func1()",
" race_test.go:13 +0x3b",
"",
"Previous write at 0x00c4200153d0 by goroutine 6:",
" race_test.TestRace()",
" race_test.go:15 +0x136",
" testing.tRunner()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107",
"",
"Goroutine 7 (running) created at:",
" race_test.TestRace()",
" race_test.go:14 +0x125",
" testing.tRunner()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107",
"",
"Goroutine 6 (running) created at:",
" testing.(*T).Run()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:697 +0x543",
" testing.runTests.func1()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:882 +0xaa",
" testing.tRunner()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107",
" testing.runTests()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:888 +0x4e0",
" testing.(*M).Run()",
" /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:822 +0x1c3",
" main.main()",
" _test/_testmain.go:52 +0x20f",
"==================",
"testing.go:610: race detected during execution of test",
"exit status 1",
},
},
},
},
},
},
},
{
name: "18-coverpkg.txt",
reportName: "18-report.xml",

@ -41,9 +41,10 @@ type Test struct {
var (
regexStatus = regexp.MustCompile(`^\s*--- (PASS|FAIL|SKIP): (.+) \((\d+\.\d+)(?: seconds|s)\)$`)
regexCoverage = regexp.MustCompile(`^coverage:\s+(\d+\.\d+)%\s+of\s+statements(?:\sin\s.+)?$`)
regexResult = regexp.MustCompile(`^(ok|FAIL)\s+([^ ]+)\s+(?:(\d+\.\d+)s|(\[\w+ failed]))(?:\s+coverage:\s+(\d+\.\d+)%\sof\sstatements(?:\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|(\[\w+ failed]))(?:\s+coverage:\s+(\d+(?:\.\d+))%\sof\sstatements(?:\sin\s.+)?)?$`)
regexOutput = regexp.MustCompile(`( )*\t(.*)`)
regexSummary = regexp.MustCompile(`^(PASS|FAIL|SKIP)$`)
)
// Parse parses go test output from reader r and returns a report with the
@ -170,9 +171,16 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
} else if capturedPackage != "" {
// current line is build failure capture for the current built package
packageCaptures[capturedPackage] = append(packageCaptures[capturedPackage], line)
} else if regexSummary.MatchString(line) {
// ignore
} else {
// buffer anything else that we didn't recognize
buffer = append(buffer, line)
test := findTest(tests, cur)
if test == nil {
// buffer anything else that we didn't recognize
buffer = append(buffer, line)
} else {
test.Output = append(test.Output, line)
}
}
}

40
tests/17-race.txt Normal file

@ -0,0 +1,40 @@
=== RUN TestRace
test output
2 0xc4200153d0
==================
WARNING: DATA RACE
Write at 0x00c4200153d0 by goroutine 7:
race_test.TestRace.func1()
race_test.go:13 +0x3b
Previous write at 0x00c4200153d0 by goroutine 6:
race_test.TestRace()
race_test.go:15 +0x136
testing.tRunner()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107
Goroutine 7 (running) created at:
race_test.TestRace()
race_test.go:14 +0x125
testing.tRunner()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107
Goroutine 6 (running) created at:
testing.(*T).Run()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:697 +0x543
testing.runTests.func1()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:882 +0xaa
testing.tRunner()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107
testing.runTests()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:888 +0x4e0
testing.(*M).Run()
/usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:822 +0x1c3
main.main()
_test/_testmain.go:52 +0x20f
==================
--- FAIL: TestRace (0.00s)
testing.go:610: race detected during execution of test
FAIL
exit status 1
FAIL race_test 0.015s

11
tests/17-report.xml Normal file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite tests="1" failures="1" time="0.015" name="race_test">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="race_test" name="TestRace" time="0.000">
<failure message="Failed" type="">test output&#xA;2 0xc4200153d0&#xA;==================&#xA;WARNING: DATA RACE&#xA;Write at 0x00c4200153d0 by goroutine 7:&#xA; race_test.TestRace.func1()&#xA; race_test.go:13 +0x3b&#xA;&#xA;Previous write at 0x00c4200153d0 by goroutine 6:&#xA; race_test.TestRace()&#xA; race_test.go:15 +0x136&#xA; testing.tRunner()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107&#xA;&#xA;Goroutine 7 (running) created at:&#xA; race_test.TestRace()&#xA; race_test.go:14 +0x125&#xA; testing.tRunner()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107&#xA;&#xA;Goroutine 6 (running) created at:&#xA; testing.(*T).Run()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:697 +0x543&#xA; testing.runTests.func1()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:882 +0xaa&#xA; testing.tRunner()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:657 +0x107&#xA; testing.runTests()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:888 +0x4e0&#xA; testing.(*M).Run()&#xA; /usr/local/Cellar/go/1.8.3/libexec/src/testing/testing.go:822 +0x1c3&#xA; main.main()&#xA; _test/_testmain.go:52 +0x20f&#xA;==================&#xA;testing.go:610: race detected during execution of test&#xA;exit status 1</failure>
</testcase>
</testsuite>
</testsuites>