Add state to ignore trailing output

This commit is contained in:
Ingmar Stein 2017-07-26 08:06:07 +02:00
parent 0f1caf6c3e
commit 862454a821
3 changed files with 18 additions and 21 deletions

View File

@ -71,9 +71,7 @@ var testCases = []TestCase{
Name: "TestTwo", Name: "TestTwo",
Time: 130, Time: 130,
Result: parser.PASS, Result: parser.PASS,
Output: []string{ Output: []string{},
"exit status 1",
},
}, },
}, },
}, },
@ -203,9 +201,7 @@ var testCases = []TestCase{
Name: "TestTwo", Name: "TestTwo",
Time: 130, Time: 130,
Result: parser.PASS, Result: parser.PASS,
Output: []string{ Output: []string{},
"exit status 1",
},
}, },
}, },
}, },
@ -312,9 +308,7 @@ var testCases = []TestCase{
Name: "TestB", Name: "TestB",
Time: 300, Time: 300,
Result: parser.PASS, Result: parser.PASS,
Output: []string{ Output: []string{},
"coverage: 10% of statements",
},
}, },
}, },
CoveragePct: "10.0", CoveragePct: "10.0",
@ -697,7 +691,6 @@ var testCases = []TestCase{
" _test/_testmain.go:52 +0x20f", " _test/_testmain.go:52 +0x20f",
"==================", "==================",
"testing.go:610: race detected during execution of test", "testing.go:610: race detected during execution of test",
"exit status 1",
}, },
}, },
}, },
@ -724,9 +717,7 @@ var testCases = []TestCase{
Name: "TestB", Name: "TestB",
Time: 300, Time: 300,
Result: parser.PASS, Result: parser.PASS,
Output: []string{ Output: []string{},
"coverage: 10% of statements in fmt, encoding/xml",
},
}, },
}, },
CoveragePct: "10.0", CoveragePct: "10.0",

View File

@ -64,6 +64,9 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
// current test // current test
var cur string 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 // coverage percentage report for current package
var coveragePct string 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 // clear the current build package, so output lines won't be added to that build
capturedPackage = "" capturedPackage = ""
seenSummary = false
} else if matches := regexResult.FindStringSubmatch(line); len(matches) == 6 { } else if matches := regexResult.FindStringSubmatch(line); len(matches) == 6 {
if matches[5] != "" { if matches[5] != "" {
coveragePct = 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 // current line is build failure capture for the current built package
packageCaptures[capturedPackage] = append(packageCaptures[capturedPackage], line) packageCaptures[capturedPackage] = append(packageCaptures[capturedPackage], line)
} else if regexSummary.MatchString(line) { } else if regexSummary.MatchString(line) {
// ignore // don't store any output after the summary
seenSummary = true
} else { } else {
test := findTest(tests, cur) if !seenSummary {
if test == nil { if test := findTest(tests, cur); test != nil {
// buffer anything else that we didn't recognize test.Output = append(test.Output, line)
buffer = append(buffer, line) continue
} else { }
test.Output = append(test.Output, line)
} }
// buffer anything else that we didn't recognize
buffer = append(buffer, line)
} }
} }

View File

@ -5,7 +5,7 @@
<property name="go.version" value="1.0"></property> <property name="go.version" value="1.0"></property>
</properties> </properties>
<testcase classname="race_test" name="TestRace" time="0.000"> <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> <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</failure>
</testcase> </testcase>
</testsuite> </testsuite>
</testsuites> </testsuites>