From 862454a821449afa2a601f6bb173feed2cddec0e Mon Sep 17 00:00:00 2001 From: Ingmar Stein Date: Wed, 26 Jul 2017 08:06:07 +0200 Subject: [PATCH] Add state to ignore trailing output --- go-junit-report_test.go | 17 ++++------------- parser/parser.go | 20 +++++++++++++------- tests/17-report.xml | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/go-junit-report_test.go b/go-junit-report_test.go index 9e71c11..308ef22 100644 --- a/go-junit-report_test.go +++ b/go-junit-report_test.go @@ -71,9 +71,7 @@ var testCases = []TestCase{ Name: "TestTwo", Time: 130, Result: parser.PASS, - Output: []string{ - "exit status 1", - }, + Output: []string{}, }, }, }, @@ -203,9 +201,7 @@ var testCases = []TestCase{ Name: "TestTwo", Time: 130, Result: parser.PASS, - Output: []string{ - "exit status 1", - }, + Output: []string{}, }, }, }, @@ -312,9 +308,7 @@ var testCases = []TestCase{ Name: "TestB", Time: 300, Result: parser.PASS, - Output: []string{ - "coverage: 10% of statements", - }, + Output: []string{}, }, }, CoveragePct: "10.0", @@ -697,7 +691,6 @@ var testCases = []TestCase{ " _test/_testmain.go:52 +0x20f", "==================", "testing.go:610: race detected during execution of test", - "exit status 1", }, }, }, @@ -724,9 +717,7 @@ var testCases = []TestCase{ Name: "TestB", Time: 300, Result: parser.PASS, - Output: []string{ - "coverage: 10% of statements in fmt, encoding/xml", - }, + Output: []string{}, }, }, CoveragePct: "10.0", diff --git a/parser/parser.go b/parser/parser.go index 9d05c05..f4feca6 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -64,6 +64,9 @@ func Parse(r io.Reader, pkgName string) (*Report, error) { // current test var cur string + // keep track if we've already seen a summary for the current test + var seenSummary bool + // coverage percentage report for current package var coveragePct string @@ -98,6 +101,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) { // clear the current build package, so output lines won't be added to that build capturedPackage = "" + seenSummary = false } else if matches := regexResult.FindStringSubmatch(line); len(matches) == 6 { if matches[5] != "" { coveragePct = matches[5] @@ -172,15 +176,17 @@ func Parse(r io.Reader, pkgName string) (*Report, error) { // current line is build failure capture for the current built package packageCaptures[capturedPackage] = append(packageCaptures[capturedPackage], line) } else if regexSummary.MatchString(line) { - // ignore + // don't store any output after the summary + seenSummary = true } else { - 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) + if !seenSummary { + if test := findTest(tests, cur); test != nil { + test.Output = append(test.Output, line) + continue + } } + // buffer anything else that we didn't recognize + buffer = append(buffer, line) } } diff --git a/tests/17-report.xml b/tests/17-report.xml index f7df04c..0fba42b 100644 --- a/tests/17-report.xml +++ b/tests/17-report.xml @@ -5,7 +5,7 @@ - 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 + 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