From e0e4af8a58bb6943130be01ee722b9fea1af1e3c Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 2 Dec 2024 09:29:11 +0100 Subject: [PATCH] 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 `