mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-07-04 05:02:47 -05:00
gtr: Handle end_test events without corresponding run_test event
When running `go test` without the `-v` flag, the output may not contain everything that we expect. For example, no output is generated for passing tests. Even for a failing test the output does not contain a `=== RUN` line. Currently, this resulted in us ignoring the test result since we couldn't find an existing test to assign this result to. We should however handle this situation gracefully, and just assume a test exists when only encountering a test result line. References #109
This commit is contained in:
@ -68,14 +68,19 @@ func (b *ReportBuilder) ContinueTest(name string) {
|
||||
}
|
||||
|
||||
func (b *ReportBuilder) EndTest(name, result string, duration time.Duration, level int) {
|
||||
id := b.findTest(name)
|
||||
b.lastId = id
|
||||
b.lastId = b.findTest(name)
|
||||
if b.lastId < 0 {
|
||||
// test did not exist, create one
|
||||
// TODO: Likely reason is that the user ran go test without the -v
|
||||
// flag, should we report this somewhere?
|
||||
b.CreateTest(name)
|
||||
}
|
||||
|
||||
t := b.tests[id]
|
||||
t := b.tests[b.lastId]
|
||||
t.Result = parseResult(result)
|
||||
t.Duration = duration
|
||||
t.Level = level
|
||||
b.tests[id] = t
|
||||
b.tests[b.lastId] = t
|
||||
}
|
||||
|
||||
func (b *ReportBuilder) End() {
|
||||
@ -229,7 +234,7 @@ func (b *ReportBuilder) findBenchmark(name string) int {
|
||||
|
||||
func (b *ReportBuilder) containsFailingTest() bool {
|
||||
for _, test := range b.tests {
|
||||
if test.Result == Fail {
|
||||
if test.Result == Fail || test.Result == Unknown {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +143,11 @@ func JUnit(report Report, hostname string, now time.Time) junit.Testsuites {
|
||||
tc.Skipped = &junit.Result{
|
||||
Message: formatOutput(test.Output, test.Level),
|
||||
}
|
||||
} else if test.Result == Unknown {
|
||||
tc.Error = &junit.Result{
|
||||
Message: "No test result found",
|
||||
Data: formatOutput(test.Output, test.Level),
|
||||
}
|
||||
}
|
||||
|
||||
suite.AddTestcase(tc)
|
||||
@ -172,8 +177,8 @@ func JUnit(report Report, hostname string, now time.Time) junit.Testsuites {
|
||||
Classname: pkg.BuildError.Name,
|
||||
Name: pkg.BuildError.Cause,
|
||||
Time: junit.FormatDuration(0),
|
||||
Failure: &junit.Result{
|
||||
Message: "Failed",
|
||||
Error: &junit.Result{
|
||||
Message: "Build error",
|
||||
Data: strings.Join(pkg.BuildError.Output, "\n"),
|
||||
},
|
||||
}
|
||||
@ -185,8 +190,8 @@ func JUnit(report Report, hostname string, now time.Time) junit.Testsuites {
|
||||
Classname: pkg.RunError.Name,
|
||||
Name: "Failure",
|
||||
Time: junit.FormatDuration(0),
|
||||
Failure: &junit.Result{
|
||||
Message: "Failed",
|
||||
Error: &junit.Result{
|
||||
Message: "Run error",
|
||||
Data: strings.Join(pkg.RunError.Output, "\n"),
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user