mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-06 13:38:07 -05:00
Include failing packages without tests in report
If a package compiles correctly, but panics before it has a chance to run any tests it would previously be ignored. Any failing packages without tests but with some output will now be included in the report with a dummy test. Fixes #52
This commit is contained in:
parent
dd4990585e
commit
2a5fd0eeb0
@ -561,6 +561,55 @@ var testCases = []TestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "14-panic.txt",
|
||||||
|
reportName: "14-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "package/panic",
|
||||||
|
Time: 3,
|
||||||
|
Tests: []*parser.Test{
|
||||||
|
{
|
||||||
|
Name: "Failure",
|
||||||
|
Result: parser.FAIL,
|
||||||
|
Output: []string{
|
||||||
|
"panic: init",
|
||||||
|
"stacktrace",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "package/panic2",
|
||||||
|
Time: 3,
|
||||||
|
Tests: []*parser.Test{
|
||||||
|
{
|
||||||
|
Name: "Failure",
|
||||||
|
Result: parser.FAIL,
|
||||||
|
Output: []string{
|
||||||
|
"panic: init",
|
||||||
|
"stacktrace",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "15-empty.txt",
|
||||||
|
reportName: "15-report.xml",
|
||||||
|
report: &parser.Report{
|
||||||
|
Packages: []parser.Package{
|
||||||
|
{
|
||||||
|
Name: "package/empty",
|
||||||
|
Time: 1,
|
||||||
|
Tests: []*parser.Test{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParser(t *testing.T) {
|
func TestParser(t *testing.T) {
|
||||||
|
@ -72,6 +72,9 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
// the name of the package which it's build failure output is being captured
|
// the name of the package which it's build failure output is being captured
|
||||||
var capturedPackage string
|
var capturedPackage string
|
||||||
|
|
||||||
|
// capture any non-test output
|
||||||
|
var buffer []string
|
||||||
|
|
||||||
// parse lines
|
// parse lines
|
||||||
for {
|
for {
|
||||||
l, _, err := reader.ReadLine()
|
l, _, err := reader.ReadLine()
|
||||||
@ -106,6 +109,15 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
Result: FAIL,
|
Result: FAIL,
|
||||||
Output: packageCaptures[matches[2]],
|
Output: packageCaptures[matches[2]],
|
||||||
})
|
})
|
||||||
|
} else if matches[1] == "FAIL" && len(tests) == 0 && len(buffer) > 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,
|
||||||
|
})
|
||||||
|
buffer = buffer[0:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// all tests in this package are finished
|
// all tests in this package are finished
|
||||||
@ -116,6 +128,7 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
CoveragePct: coveragePct,
|
CoveragePct: coveragePct,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
buffer = buffer[0:0]
|
||||||
tests = make([]*Test, 0)
|
tests = make([]*Test, 0)
|
||||||
coveragePct = ""
|
coveragePct = ""
|
||||||
cur = ""
|
cur = ""
|
||||||
@ -157,6 +170,9 @@ func Parse(r io.Reader, pkgName string) (*Report, error) {
|
|||||||
} else if capturedPackage != "" {
|
} else if capturedPackage != "" {
|
||||||
// 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 {
|
||||||
|
// buffer anything else that we didn't recognize
|
||||||
|
buffer = append(buffer, line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
tests/14-panic.txt
Normal file
6
tests/14-panic.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
panic: init
|
||||||
|
stacktrace
|
||||||
|
FAIL package/panic 0.003s
|
||||||
|
panic: init
|
||||||
|
stacktrace
|
||||||
|
FAIL package/panic2 0.003s
|
19
tests/14-report.xml
Normal file
19
tests/14-report.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="1" failures="1" time="0.003" name="package/panic">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="panic" name="Failure" time="0.000">
|
||||||
|
<failure message="Failed" type="">panic: init
stacktrace</failure>
|
||||||
|
</testcase>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite tests="1" failures="1" time="0.003" name="package/panic2">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="panic2" name="Failure" time="0.000">
|
||||||
|
<failure message="Failed" type="">panic: init
stacktrace</failure>
|
||||||
|
</testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
3
tests/15-empty.txt
Normal file
3
tests/15-empty.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
testing: warning: no tests to run
|
||||||
|
PASS
|
||||||
|
ok package/empty 0.001s
|
8
tests/15-report.xml
Normal file
8
tests/15-report.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="0" failures="0" time="0.001" name="package/empty">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
Loading…
x
Reference in New Issue
Block a user