gtr: Also look at failures in benchmarks when creating a package

When we encounter a failure but there was not failing test, we create a
failing dummy test in the report. This is to prevent the failure from
being overlooked.

The case where the output contained a failing benchmark was not handled
correctly, resulting in a dummy test failure being added to the report
unnecessarily.
This commit is contained in:
Joël Stemmer
2022-06-13 00:47:28 +01:00
parent d05abd4130
commit 46e0aed494
3 changed files with 17 additions and 16 deletions

View File

@ -236,7 +236,7 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
// If the summary result says we failed, but there were no failing tests
// then something else must have failed.
if parseResult(result) == gtr.Fail && (len(b.tests) > 0 || len(b.benchmarks) > 0) && !b.containsFailingTest() {
if parseResult(result) == gtr.Fail && (len(b.tests) > 0 || len(b.benchmarks) > 0) && !b.containsFailures() {
pkg.RunError = gtr.Error{
Name: name,
Output: b.output.Get(globalID),
@ -348,14 +348,19 @@ func (b *reportBuilder) findBenchmark(name string) (int, bool) {
return 0, false
}
// containsFailingTest return true if the current list of tests contains at
// least one failing test or an unknown result.
func (b *reportBuilder) containsFailingTest() bool {
// containsFailures return true if the current list of tests or benchmarks
// contains at least one failing test or an unknown result.
func (b *reportBuilder) containsFailures() bool {
for _, test := range b.tests {
if test.Result == gtr.Fail || test.Result == gtr.Unknown {
return true
}
}
for _, bm := range b.benchmarks {
if bm.Result == gtr.Fail || bm.Result == gtr.Unknown {
return true
}
}
return false
}