mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-07-07 14:25:44 -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user