diff --git a/cmd/prune-junit-xml/prunexml.go b/cmd/prune-junit-xml/prunexml.go index 5da06e3b235..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) @@ -153,8 +159,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 +175,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..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 @@ -108,6 +111,24 @@ func TestPruneTESTS(t *testing.T) { FailureContentB + + + + + + 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 + + ` outputXML := ` @@ -131,7 +152,17 @@ func TestPruneTESTS(t *testing.T) { - FailureContentA; FailureContentB + FailureContentA FailureContentB + + + + + + + + RUNNING TestWatchRestartsIfTimeoutNotReached/group/InformerWatcher_survives_closed_watchesA expected foo, got bar sub-test failed + out A out B + err A err B `