From f95382de92f874706e19ef939e5c90f2609e6106 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 22 Oct 2023 16:46:03 -0700 Subject: [PATCH 1/2] Update gotestsum retries to properly filter out parents when there is a missing gap in the parent tree --- testjson/execution.go | 11 +++++++++-- testjson/execution_test.go | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/testjson/execution.go b/testjson/execution.go index 27e041c8..9bed8eed 100644 --- a/testjson/execution.go +++ b/testjson/execution.go @@ -563,8 +563,15 @@ func FilterFailedUnique(tcs []TestCase) []TestCase { if _, exists := parents[tc.Package]; !exists { parents[tc.Package] = make(map[string]bool) } - if parent := tc.Test.Parent(); parent != "" { - parents[tc.Package][parent] = true + currentTest := tc.Test + for { + parent := currentTest.Parent() + if parent == "" { + break + } else { + parents[tc.Package][parent] = true + currentTest = TestName(parent) + } } if _, exists := parents[tc.Package][tc.Test.Name()]; exists { continue // tc is a parent of a failing subtest diff --git a/testjson/execution_test.go b/testjson/execution_test.go index 2d348244..80e62562 100644 --- a/testjson/execution_test.go +++ b/testjson/execution_test.go @@ -298,3 +298,17 @@ func TestFilterFailedUnique_MultipleNested(t *testing.T) { cmpTestCase := cmp.AllowUnexported(TestCase{}) assert.DeepEqual(t, expected, actual, cmpTestCase) } + +func TestFilterFailedUnique_NestedWithGaps(t *testing.T) { + input := []TestCase{ + {ID: 2, Package: "pkg", Test: "TestParent/foo/bar/baz"}, + {ID: 1, Package: "pkg", Test: "TestParent"}, + } + actual := FilterFailedUnique(input) + + expected := []TestCase{ + {ID: 2, Package: "pkg", Test: "TestParent/foo/bar/baz"}, + } + cmpTestCase := cmp.AllowUnexported(TestCase{}) + assert.DeepEqual(t, expected, actual, cmpTestCase) +} From bfb4889c4ae47f5485121fd3543703fc03f6bd7f Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 23 Oct 2023 22:13:38 -0400 Subject: [PATCH 2/2] Fold for loop clauses into the statement --- testjson/execution.go | 12 +++--------- testjson/execution_test.go | 9 ++++++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/testjson/execution.go b/testjson/execution.go index 9bed8eed..25d4be08 100644 --- a/testjson/execution.go +++ b/testjson/execution.go @@ -563,15 +563,9 @@ func FilterFailedUnique(tcs []TestCase) []TestCase { if _, exists := parents[tc.Package]; !exists { parents[tc.Package] = make(map[string]bool) } - currentTest := tc.Test - for { - parent := currentTest.Parent() - if parent == "" { - break - } else { - parents[tc.Package][parent] = true - currentTest = TestName(parent) - } + + for p := tc.Test.Parent(); p != ""; p = TestName(p).Parent() { + parents[tc.Package][p] = true } if _, exists := parents[tc.Package][tc.Test.Name()]; exists { continue // tc is a parent of a failing subtest diff --git a/testjson/execution_test.go b/testjson/execution_test.go index 80e62562..81f809dc 100644 --- a/testjson/execution_test.go +++ b/testjson/execution_test.go @@ -301,13 +301,16 @@ func TestFilterFailedUnique_MultipleNested(t *testing.T) { func TestFilterFailedUnique_NestedWithGaps(t *testing.T) { input := []TestCase{ - {ID: 2, Package: "pkg", Test: "TestParent/foo/bar/baz"}, - {ID: 1, Package: "pkg", Test: "TestParent"}, + {ID: 1, Package: "pkg", Test: "TestParent/foo/bar/baz"}, + {ID: 2, Package: "pkg", Test: "TestParent"}, + {ID: 3, Package: "pkg", Test: "TestParent1/foo/bar"}, + {ID: 4, Package: "pkg", Test: "TestParent1"}, } actual := FilterFailedUnique(input) expected := []TestCase{ - {ID: 2, Package: "pkg", Test: "TestParent/foo/bar/baz"}, + {ID: 1, Package: "pkg", Test: "TestParent/foo/bar/baz"}, + {ID: 3, Package: "pkg", Test: "TestParent1/foo/bar"}, } cmpTestCase := cmp.AllowUnexported(TestCase{}) assert.DeepEqual(t, expected, actual, cmpTestCase)