Merge pull request #67 from mattdelco/upstream

This commit is contained in:
Matt Delco 2018-03-14 16:03:42 -07:00 committed by Joël Stemmer
parent 2eb034df4e
commit 766f2ff9bb
4 changed files with 81 additions and 7 deletions

View File

@ -765,6 +765,45 @@ var testCases = []TestCase{
},
},
},
{
name: "20-trio.txt",
reportName: "20-report.xml",
report: &parser.Report{
Packages: []parser.Package{
{
Name: "",
Time: 3010,
Tests: []*parser.Test{
{
Name: "FirstTest",
Time: 2000,
Result: parser.FAIL,
Output: []string{
"Message from first",
"Supplemental from first",
},
},
{
Name: "SecondTest",
Time: 1000,
Result: parser.FAIL,
Output: []string{
"Message from second",
},
},
{
Name: "ThirdTest",
Time: 10,
Result: parser.FAIL,
Output: []string{
"Message from third",
},
},
},
},
},
},
},
}
func TestParser(t *testing.T) {

View File

@ -77,7 +77,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
var capturedPackage string
// capture any non-test output
var buffer []string
var buffers = map[string][]string{}
// parse lines
for {
@ -102,6 +102,11 @@ 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 strings.HasPrefix(line, "=== PAUSE ") {
continue
} else if strings.HasPrefix(line, "=== CONT ") {
cur = strings.TrimSpace(line[8:])
continue
} else if matches := regexResult.FindStringSubmatch(line); len(matches) == 6 {
if matches[5] != "" {
coveragePct = matches[5]
@ -114,15 +119,15 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
Result: FAIL,
Output: packageCaptures[matches[2]],
})
} else if matches[1] == "FAIL" && len(tests) == 0 && len(buffer) > 0 {
} else if matches[1] == "FAIL" && len(tests) == 0 && len(buffers[cur]) > 0 {
// This package didn't have any tests, but it failed with some
// output. Create a dummy test with the output.
tests = append(tests, &Test{
Name: "Failure",
Result: FAIL,
Output: buffer,
Output: buffers[cur],
})
buffer = buffer[0:0]
buffers[cur] = buffers[cur][0:0]
}
// all tests in this package are finished
@ -133,7 +138,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
CoveragePct: coveragePct,
})
buffer = buffer[0:0]
buffers[cur] = buffers[cur][0:0]
tests = make([]*Test, 0)
coveragePct = ""
cur = ""
@ -153,7 +158,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
} else {
test.Result = FAIL
}
test.Output = buffer
test.Output = buffers[cur]
test.Name = matches[2]
testTime := parseTime(matches[3]) * 10
@ -181,7 +186,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
seenSummary = true
} else if !seenSummary {
// buffer anything else that we didn't recognize
buffer = append(buffer, line)
buffers[cur] = append(buffers[cur], line)
}
}

17
tests/20-report.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite tests="3" failures="3" time="3.010" name="">
<properties>
<property name="go.version" value="1.0"></property>
</properties>
<testcase classname="" name="FirstTest" time="2.000">
<failure message="Failed" type="">Message from first&#xA;Supplemental from first</failure>
</testcase>
<testcase classname="" name="SecondTest" time="1.000">
<failure message="Failed" type="">Message from second</failure>
</testcase>
<testcase classname="" name="ThirdTest" time="0.010">
<failure message="Failed" type="">Message from third</failure>
</testcase>
</testsuite>
</testsuites>

13
tests/20-trio.txt Normal file
View File

@ -0,0 +1,13 @@
=== RUN FirstTest
Message from first
=== PAUSE FirstTest
=== RUN SecondTest
Message from second
=== PAUSE SecondTest
=== CONT FirstTest
Supplemental from first
=== RUN ThirdTest
Message from third
--- FAIL: ThirdTest (0.01s)
--- FAIL: FirstTest (2.00s)
--- FAIL: SecondTest (1.00s)