From e0e4af8a58bb6943130be01ee722b9fea1af1e3c Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 2 Dec 2024 09:29:11 +0100 Subject: [PATCH 1/2] prune-junit-xml: smarter concatenation when pruning tests Repeating the same "Failed" message text doesn't add any information. Separating with a blank line is more readable. Before: ... --- FAIL: TestFrontProxyConfig/WithoutUID (64.89s) ; === RUN TestFrontProxyConfig/WithUID After: ... --- FAIL: TestFrontProxyConfig/WithoutUID (64.89s) === RUN TestFrontProxyConfig/WithUID --- cmd/prune-junit-xml/prunexml.go | 18 ++++++++++++++++-- cmd/prune-junit-xml/prunexml_test.go | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/cmd/prune-junit-xml/prunexml.go b/cmd/prune-junit-xml/prunexml.go index 5da06e3b235..b6c07d4e134 100644 --- a/cmd/prune-junit-xml/prunexml.go +++ b/cmd/prune-junit-xml/prunexml.go @@ -153,8 +153,15 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) { suites.Suites = updatedTestsuites } -// joinTexts returns "; " if both are non-empty, +// joinTexts returns "" if both are non-empty, // otherwise just the non-empty string, if there is one. +// +// If is contained completely in , gets returned because repeating +// exactly the same string again doesn't add any information. Typically +// this occurs when joining the failure message because that is the fixed +// string "Failed" for all tests, regardless of what the test logged. +// The test log output is typically different because it cointains "=== RUN +// " and thus doesn't get dropped. func joinTexts(a, b string) string { if a == "" { return b @@ -162,7 +169,14 @@ func joinTexts(a, b string) string { if b == "" { return a } - return a + "; " + b + if strings.Contains(a, b) { + return a + } + sep := "\n" + if !strings.HasSuffix(a, "\n") { + sep = "\n\n" + } + return a + sep + b } func fetchXML(xmlReader io.Reader) (*junitxml.JUnitTestSuites, error) { diff --git a/cmd/prune-junit-xml/prunexml_test.go b/cmd/prune-junit-xml/prunexml_test.go index 6d40f5e8a9c..31f74ffaff6 100644 --- a/cmd/prune-junit-xml/prunexml_test.go +++ b/cmd/prune-junit-xml/prunexml_test.go @@ -108,6 +108,20 @@ func TestPruneTESTS(t *testing.T) { FailureContentB + + + + + + RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA expected foo, got bar + + + sub-test failed + + + sub-test failed + + ` outputXML := ` @@ -131,7 +145,15 @@ func TestPruneTESTS(t *testing.T) { - FailureContentA; FailureContentB + FailureContentA FailureContentB + + + + + + + + RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA expected foo, got bar sub-test failed ` From b330eeac2ff546a7eefed41eadbd92ac7f2636d8 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 2 Dec 2024 10:24:13 +0100 Subject: [PATCH 2/2] prune-junit-xml: preserve system out + err text during test pruning When stripping out log messages from the failure text, the original text gets stored as . That part then got lost when reducing tests. Instead of dropping it, it needs to be joined from all failed tests. Same for , although that isn't used yet. --- cmd/prune-junit-xml/prunexml.go | 6 ++++++ cmd/prune-junit-xml/prunexml_test.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/prune-junit-xml/prunexml.go b/cmd/prune-junit-xml/prunexml.go index b6c07d4e134..21d0b0fa312 100644 --- a/cmd/prune-junit-xml/prunexml.go +++ b/cmd/prune-junit-xml/prunexml.go @@ -135,6 +135,8 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) { updatedTestcase.Classname = match[1] updatedTestcase.Name = match[2] updatedTestcase.Time = suite.Time + updatedSystemOut := "" + updatedSystemErr := "" for _, testcase := range suite.TestCases { // The top level testcase element in a JUnit xml file does not have the / character. if testcase.Failure != nil { @@ -142,10 +144,14 @@ func pruneTESTS(suites *junitxml.JUnitTestSuites) { updatedTestcaseFailure.Message = joinTexts(updatedTestcaseFailure.Message, testcase.Failure.Message) updatedTestcaseFailure.Contents = joinTexts(updatedTestcaseFailure.Contents, testcase.Failure.Contents) updatedTestcaseFailure.Type = joinTexts(updatedTestcaseFailure.Type, testcase.Failure.Type) + updatedSystemOut = joinTexts(updatedSystemOut, testcase.SystemOut) + updatedSystemErr = joinTexts(updatedSystemErr, testcase.SystemErr) } } if failflag { updatedTestcase.Failure = &updatedTestcaseFailure + updatedTestcase.SystemOut = updatedSystemOut + updatedTestcase.SystemErr = updatedSystemErr } suite.TestCases = append(updatedTestcases, updatedTestcase) updatedTestsuites = append(updatedTestsuites, suite) diff --git a/cmd/prune-junit-xml/prunexml_test.go b/cmd/prune-junit-xml/prunexml_test.go index 31f74ffaff6..3dde79a0691 100644 --- a/cmd/prune-junit-xml/prunexml_test.go +++ b/cmd/prune-junit-xml/prunexml_test.go @@ -100,7 +100,10 @@ func TestPruneTESTS(t *testing.T) { - + + out A + err B + FailureContentA @@ -114,9 +117,13 @@ func TestPruneTESTS(t *testing.T) { RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA expected foo, got bar + out A + err A sub-test failed + out B + err B sub-test failed @@ -154,6 +161,8 @@ func TestPruneTESTS(t *testing.T) { RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA expected foo, got bar sub-test failed + out A out B + err A err B `