test_all: make ignored tests also ignore their subtests

Previously ignoring a test with subtests had no effect, as the failures
are reported against the subtests.
This commit is contained in:
Nick Craig-Wood committed 2026-10-28 15:04:56 +00:00
1 parent 4db2817932
commit f45e78e294
2 files changed
+56 -6

No files matched your search

+13 -6
View File
@@ -180,17 +180,24 @@ func (r *Run) findFailures() {
ignored := 0
for _, matches := range failRe.FindAllSubmatch(r.output, -1) {
failedTest := string(matches[1])
// Skip any ignored failures
if _, found := r.Ignore[failedTest]; found {
ignored++
} else {
r.FailedTests = append(r.FailedTests, failedTest)
}
// Find all the parents of this test
parts := strings.Split(failedTest, "/")
for i := len(parts) - 1; i >= 1; i-- {
excludeParents[strings.Join(parts[:i], "/")] = struct{}{}
}
// Skip any ignored failures, including subtests of ignored tests
isIgnored := false
for i := len(parts); i >= 1; i-- {
if _, found := r.Ignore[strings.Join(parts[:i], "/")]; found {
isIgnored = true
break
}
}
if isIgnored {
ignored++
} else {
r.FailedTests = append(r.FailedTests, failedTest)
}
}
// Exclude the parents
newTests := r.FailedTests[:0]
+43
View File
@@ -1,6 +1,7 @@
package runs
import (
"errors"
"fmt"
"os/exec"
"regexp"
@@ -177,3 +178,45 @@ func TestTests(t *testing.T) {
})
})
}
func TestFindFailuresIgnore(t *testing.T) {
output := []byte(`--- FAIL: TestOne (0.00s)
--- FAIL: TestOne/Sub1 (0.00s)
--- FAIL: TestOne/Sub2 (0.00s)
--- FAIL: TestTwo (0.00s)
--- FAIL: TestTwo/Sub1 (0.00s)
--- FAIL: TestThree (0.00s)
`)
for _, test := range []struct {
ignore []string
want []string
}{
{
ignore: nil,
want: []string{"TestOne/Sub1", "TestOne/Sub2", "TestTwo/Sub1", "TestThree"},
},
{
ignore: []string{"TestOne"},
want: []string{"TestTwo/Sub1", "TestThree"},
},
{
ignore: []string{"TestOne/Sub1"},
want: []string{"TestOne/Sub2", "TestTwo/Sub1", "TestThree"},
},
{
ignore: []string{"TestOne", "TestTwo", "TestThree"},
want: nil,
},
} {
r := &Run{
Ignore: map[string]struct{}{},
err: errors.New("failed"),
output: output,
}
for _, name := range test.ignore {
r.Ignore[name] = struct{}{}
}
r.findFailures()
assert.Equal(t, test.want, r.FailedTests, fmt.Sprintf("ignore=%v", test.ignore))
}
}