From 01656fa7f4ac1dd1c81dad52af256a58cd074e03 Mon Sep 17 00:00:00 2001 From: Ingmar Stein Date: Thu, 22 Jun 2017 12:43:57 +0200 Subject: [PATCH] Capture more test output, e.g. race detection results --- go-junit-report_test.go | 65 +++++++++++++++++++++++++++++++++++++++-- parser/parser.go | 16 +++++++--- tests/17-race.txt | 40 +++++++++++++++++++++++++ tests/17-report.xml | 11 +++++++ 4 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 tests/17-race.txt create mode 100644 tests/17-report.xml diff --git a/go-junit-report_test.go b/go-junit-report_test.go index be0e416..bbac68d 100644 --- a/go-junit-report_test.go +++ b/go-junit-report_test.go @@ -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", diff --git a/parser/parser.go b/parser/parser.go index 5fe7a37..50dcac5 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -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) + } } } diff --git a/tests/17-race.txt b/tests/17-race.txt new file mode 100644 index 0000000..42b9728 --- /dev/null +++ b/tests/17-race.txt @@ -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 \ No newline at end of file diff --git a/tests/17-report.xml b/tests/17-report.xml new file mode 100644 index 0000000..f7df04c --- /dev/null +++ b/tests/17-report.xml @@ -0,0 +1,11 @@ + + + + + + + + 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 + + +