From 3f30451b10e74b043687492477d3c665045ff39e Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Fri, 28 Jun 2024 13:49:45 +0200 Subject: [PATCH] feat: populate skipped message with last line of test output (#13) Co-authored-by: Marcus Caisey --- junit/junit.go | 13 ++++++++++-- junit/junit_test.go | 2 +- testdata/001-report.xml | 4 ++-- testdata/012-report.xml | 2 +- testdata/036-report.xml | 2 +- testdata/107-report.xml | 18 +++++++++++------ testdata/107-skip.gojson.txt | 36 ++++++++++++++++++++++------------ testdata/110-report.xml | 2 +- testdata/src/skip/skip_test.go | 9 +++++++++ 9 files changed, 61 insertions(+), 27 deletions(-) diff --git a/junit/junit.go b/junit/junit.go index fee43206..e7a8b971 100644 --- a/junit/junit.go +++ b/junit/junit.go @@ -230,9 +230,18 @@ func createTestcaseForTest(pkgName string, test gtr.Test) Testcase { Data: formatOutput(test.Output), } } else if test.Result == gtr.Skip { + message := "" + data := "" + if len(test.Output) > 0 { + lastIdx := len(test.Output) - 1 + message = strings.TrimSpace(test.Output[lastIdx]) + if len(test.Output) > 1 { + data = formatOutput(test.Output[:lastIdx]) + } + } tc.Skipped = &Result{ - Message: "Skipped", - Data: formatOutput(test.Output), + Message: message, + Data: data, } } else if test.Result == gtr.Unknown { tc.Error = &Result{ diff --git a/junit/junit_test.go b/junit/junit_test.go index 83b8ffe5..96cf06df 100644 --- a/junit/junit_test.go +++ b/junit/junit_test.go @@ -105,7 +105,7 @@ func TestCreateFromReport(t *testing.T) { Name: "TestSkip", Classname: "package/name", Time: "0.000", - Skipped: &Result{Message: "Skipped"}, + Skipped: &Result{}, }, { Name: "TestIncomplete", diff --git a/testdata/001-report.xml b/testdata/001-report.xml index 27f43556..595cf6ef 100644 --- a/testdata/001-report.xml +++ b/testdata/001-report.xml @@ -28,10 +28,10 @@ - + - + diff --git a/testdata/012-report.xml b/testdata/012-report.xml index 4306c58c..35ee7cc4 100644 --- a/testdata/012-report.xml +++ b/testdata/012-report.xml @@ -14,7 +14,7 @@ - + diff --git a/testdata/036-report.xml b/testdata/036-report.xml index 06cd1160..b17955eb 100644 --- a/testdata/036-report.xml +++ b/testdata/036-report.xml @@ -11,7 +11,7 @@ - + - - + + - - + + - - + + + + + + + + diff --git a/testdata/107-skip.gojson.txt b/testdata/107-skip.gojson.txt index a5e435de..800084df 100644 --- a/testdata/107-skip.gojson.txt +++ b/testdata/107-skip.gojson.txt @@ -1,13 +1,23 @@ -{"Time":"2019-10-09T00:00:00.329193863+00:00","Action":"run","Package":"package/name/skip","Test":"TestSkip"} -{"Time":"2019-10-09T00:00:00.329288607+00:00","Action":"output","Package":"package/name/skip","Test":"TestSkip","Output":"=== RUN TestSkip\n"} -{"Time":"2019-10-09T00:00:00.32929713+00:00","Action":"output","Package":"package/name/skip","Test":"TestSkip","Output":" skip_test.go:6: skip message\n"} -{"Time":"2019-10-09T00:00:00.329302577+00:00","Action":"output","Package":"package/name/skip","Test":"TestSkip","Output":"--- SKIP: TestSkip (0.00s)\n"} -{"Time":"2019-10-09T00:00:00.329305698+00:00","Action":"skip","Package":"package/name/skip","Test":"TestSkip","Elapsed":0} -{"Time":"2019-10-09T00:00:00.329309504+00:00","Action":"run","Package":"package/name/skip","Test":"TestSkipNow"} -{"Time":"2019-10-09T00:00:00.329312988+00:00","Action":"output","Package":"package/name/skip","Test":"TestSkipNow","Output":"=== RUN TestSkipNow\n"} -{"Time":"2019-10-09T00:00:00.329315853+00:00","Action":"output","Package":"package/name/skip","Test":"TestSkipNow","Output":" skip_test.go:10: log message\n"} -{"Time":"2019-10-09T00:00:00.329319388+00:00","Action":"output","Package":"package/name/skip","Test":"TestSkipNow","Output":"--- SKIP: TestSkipNow (0.00s)\n"} -{"Time":"2019-10-09T00:00:00.329322008+00:00","Action":"skip","Package":"package/name/skip","Test":"TestSkipNow","Elapsed":0} -{"Time":"2019-10-09T00:00:00.329324691+00:00","Action":"output","Package":"package/name/skip","Output":"PASS\n"} -{"Time":"2019-10-09T00:00:00.329392899+00:00","Action":"output","Package":"package/name/skip","Output":"ok \tpackage/name/skip\t0.001s\n"} -{"Time":"2019-10-09T00:00:00.329615729+00:00","Action":"pass","Package":"package/name/skip","Elapsed":0.001} +{"Time":"2023-02-19T23:15:21.674171Z","Action":"run","Package":"package/skip","Test":"TestSkip"} +{"Time":"2023-02-19T23:15:21.674342Z","Action":"output","Package":"package/skip","Test":"TestSkip","Output":"=== RUN TestSkip\n"} +{"Time":"2023-02-19T23:15:21.674352Z","Action":"output","Package":"package/skip","Test":"TestSkip","Output":" skip_test.go:6: skip message\n"} +{"Time":"2023-02-19T23:15:21.674371Z","Action":"output","Package":"package/skip","Test":"TestSkip","Output":"--- SKIP: TestSkip (0.00s)\n"} +{"Time":"2023-02-19T23:15:21.674374Z","Action":"skip","Package":"package/skip","Test":"TestSkip","Elapsed":0} +{"Time":"2023-02-19T23:15:21.674382Z","Action":"run","Package":"package/skip","Test":"TestSkipNow"} +{"Time":"2023-02-19T23:15:21.674386Z","Action":"output","Package":"package/skip","Test":"TestSkipNow","Output":"=== RUN TestSkipNow\n"} +{"Time":"2023-02-19T23:15:21.674388Z","Action":"output","Package":"package/skip","Test":"TestSkipNow","Output":" skip_test.go:10: log message\n"} +{"Time":"2023-02-19T23:15:21.674391Z","Action":"output","Package":"package/skip","Test":"TestSkipNow","Output":"--- SKIP: TestSkipNow (0.00s)\n"} +{"Time":"2023-02-19T23:15:21.674394Z","Action":"skip","Package":"package/skip","Test":"TestSkipNow","Elapsed":0} +{"Time":"2023-02-19T23:15:21.6744Z","Action":"run","Package":"package/skip","Test":"TestSkipNoMessage"} +{"Time":"2023-02-19T23:15:21.674402Z","Action":"output","Package":"package/skip","Test":"TestSkipNoMessage","Output":"=== RUN TestSkipNoMessage\n"} +{"Time":"2023-02-19T23:15:21.674405Z","Action":"output","Package":"package/skip","Test":"TestSkipNoMessage","Output":"--- SKIP: TestSkipNoMessage (0.00s)\n"} +{"Time":"2023-02-19T23:15:21.674407Z","Action":"skip","Package":"package/skip","Test":"TestSkipNoMessage","Elapsed":0} +{"Time":"2023-02-19T23:15:21.674409Z","Action":"run","Package":"package/skip","Test":"TestSkipLogMessage"} +{"Time":"2023-02-19T23:15:21.674411Z","Action":"output","Package":"package/skip","Test":"TestSkipLogMessage","Output":"=== RUN TestSkipLogMessage\n"} +{"Time":"2023-02-19T23:15:21.67442Z","Action":"output","Package":"package/skip","Test":"TestSkipLogMessage","Output":" skip_test.go:19: log message\n"} +{"Time":"2023-02-19T23:15:21.674426Z","Action":"output","Package":"package/skip","Test":"TestSkipLogMessage","Output":" skip_test.go:20: skip message\n"} +{"Time":"2023-02-19T23:15:21.674432Z","Action":"output","Package":"package/skip","Test":"TestSkipLogMessage","Output":"--- SKIP: TestSkipLogMessage (0.00s)\n"} +{"Time":"2023-02-19T23:15:21.674434Z","Action":"skip","Package":"package/skip","Test":"TestSkipLogMessage","Elapsed":0} +{"Time":"2023-02-19T23:15:21.674439Z","Action":"output","Package":"package/skip","Output":"PASS\n"} +{"Time":"2023-02-19T23:15:21.674441Z","Action":"output","Package":"package/skip","Output":"ok \tpackage/skip\n"} +{"Time":"2023-02-19T23:15:21.674448Z","Action":"pass","Package":"package/skip","Elapsed":0} diff --git a/testdata/110-report.xml b/testdata/110-report.xml index 06cd1160..b17955eb 100644 --- a/testdata/110-report.xml +++ b/testdata/110-report.xml @@ -11,7 +11,7 @@ - +