@@ -83,6 +83,7 @@ func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
8383
8484 tests := 0
8585 failures := 0
86+ errors := 0
8687 skipped := 0
8788
8889 flattenedTestCases := flattenGroupedTestCases (testSuite .TestCases )
@@ -101,12 +102,12 @@ func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
101102
102103 for _ , childSuite := range testSuite .TestSuites {
103104 convertedChildSuite := convertTestSuite (childSuite )
104-
105105 convertedTestSuite .TestSuites = append (convertedTestSuite .TestSuites , convertedChildSuite )
106106 }
107107
108108 convertedTestSuite .Tests = tests
109109 convertedTestSuite .Failures = failures
110+ convertedTestSuite .Errors = errors
110111 convertedTestSuite .Skipped = skipped
111112
112113 return convertedTestSuite
@@ -187,16 +188,20 @@ func convertTestCase(testCase TestCase) testreport.TestCase {
187188 Name : testCase .Name ,
188189 ClassName : testCase .ClassName ,
189190 Time : testCase .Time ,
191+ Failure : convertFailure (testCase .Failure ),
192+ Error : convertError (testCase .Error ),
193+ Skipped : convertSkipped (testCase .Skipped ),
194+ SystemOut : convertSystemOut (testCase .SystemOut ),
195+ SystemErr : convertSystemErr (testCase .SystemErr ),
190196 Properties : convertProperties (testCase .Properties ),
191197 }
192198
193- if testCase .Skipped != nil {
194- convertedTestCase .Skipped = & testreport.Skipped {
195- XMLName : testCase .Skipped .XMLName ,
196- }
199+ if convertedTestCase .Error != nil {
200+ convertedTestCase .Failure = convertErrorToFailure (convertedTestCase .Error )
201+ convertedTestCase .Error = nil
197202 }
198203
199- convertedTestCase . Failure = convertErrorsToFailure ( testCase . Failure , testCase .Error , testCase .SystemErr )
204+ enrichWithSystemOutputs ( & convertedTestCase , testCase .SystemOut , testCase .SystemErr )
200205
201206 return convertedTestCase
202207}
@@ -218,38 +223,146 @@ func convertProperties(properties *Properties) *testreport.Properties {
218223 return convertedProperties
219224}
220225
221- func convertErrorsToFailure (failure * Failure , error * Error , systemErr string ) * testreport.Failure {
222- var messages []string
226+ func convertSystemOut (systemOut string ) * testreport.SystemOut {
227+ if systemOut == "" {
228+ return nil
229+ }
223230
224- if failure != nil {
225- if len (strings .TrimSpace (failure .Message )) > 0 {
226- messages = append (messages , failure .Message )
227- }
231+ return & testreport.SystemOut {
232+ XMLName : xml.Name {Local : "system-out" },
233+ Value : systemOut ,
234+ }
235+ }
228236
229- if len ( strings . TrimSpace ( failure . Value )) > 0 {
230- messages = append ( messages , failure . Value )
231- }
237+ func convertSystemErr ( systemErr string ) * testreport. SystemErr {
238+ if systemErr == "" {
239+ return nil
232240 }
233241
234- if error != nil {
235- if len (strings .TrimSpace (error .Message )) > 0 {
236- messages = append (messages , "Error message:\n " + error .Message )
237- }
242+ return & testreport.SystemErr {
243+ XMLName : xml.Name {Local : "system-err" },
244+ Value : systemErr ,
245+ }
246+ }
238247
239- if len (strings .TrimSpace (error .Value )) > 0 {
240- messages = append (messages , "Error value:\n " + error .Value )
241- }
248+ func convertSkipped (skipped * Skipped ) * testreport.Skipped {
249+ if skipped == nil {
250+ return nil
251+ }
252+
253+ var parts []string
254+
255+ if len (strings .TrimSpace (skipped .Message )) > 0 {
256+ parts = append (parts , strings .TrimSpace (skipped .Message ))
257+ }
258+
259+ return & testreport.Skipped {
260+ XMLName : xml.Name {Local : "skipped" },
261+ Value : strings .Join (parts , "\n \n " ),
262+ }
263+ }
264+
265+ func convertFailure (failure * Failure ) * testreport.Failure {
266+ if failure == nil {
267+ return nil
268+ }
269+
270+ var parts []string
271+
272+ var attributes []string
273+ if len (strings .TrimSpace (failure .Type )) > 0 {
274+ attributes = append (attributes , failure .Type )
242275 }
276+ if len (strings .TrimSpace (failure .Message )) > 0 {
277+ attributes = append (attributes , failure .Message )
278+ }
279+ if len (attributes ) > 0 {
280+ parts = append (parts , strings .Join (attributes , ": " ))
281+ }
282+
283+ if len (strings .TrimSpace (failure .Value )) > 0 {
284+ parts = append (parts , failure .Value )
285+ }
286+
287+ return & testreport.Failure {
288+ XMLName : xml.Name {Local : "failure" },
289+ Value : strings .Join (parts , "\n \n " ),
290+ }
291+ }
243292
244- if len (systemErr ) > 0 {
245- messages = append (messages , "System error:\n " + systemErr )
293+ func convertError (error * Error ) * testreport.Error {
294+ if error == nil {
295+ return nil
246296 }
247297
248- if len (messages ) > 0 {
249- return & testreport.Failure {
250- XMLName : xml.Name {Local : "failure" },
251- Value : strings .Join (messages , "\n \n " ),
298+ var parts []string
299+
300+ var attributes []string
301+ if len (strings .TrimSpace (error .Type )) > 0 {
302+ attributes = append (attributes , error .Type )
303+ }
304+ if len (strings .TrimSpace (error .Message )) > 0 {
305+ attributes = append (attributes , error .Message )
306+ }
307+ if len (attributes ) > 0 {
308+ parts = append (parts , strings .Join (attributes , ": " ))
309+ }
310+
311+ if len (strings .TrimSpace (error .Value )) > 0 {
312+ parts = append (parts , error .Value )
313+ }
314+
315+ return & testreport.Error {
316+ XMLName : xml.Name {Local : "error" },
317+ Value : strings .Join (parts , "\n \n " ),
318+ }
319+ }
320+
321+ func convertErrorToFailure (error * testreport.Error ) * testreport.Failure {
322+ if error == nil {
323+ return nil
324+ }
325+
326+ return & testreport.Failure {
327+ XMLName : xml.Name {Local : "failure" },
328+ Value : error .Value ,
329+ }
330+ }
331+
332+ func enrichWithSystemOutputs (testCase * testreport.TestCase , systemOut , systemErr string ) {
333+ var testOutputs []string = []string {}
334+
335+ if len (strings .TrimSpace (systemErr )) > 0 {
336+ testOutputs = append (testOutputs , "System error:\n " + systemErr )
337+ }
338+
339+ if len (strings .TrimSpace (systemOut )) > 0 {
340+ testOutputs = append (testOutputs , "System output:\n " + systemOut )
341+ }
342+
343+ if (len (testOutputs )) == 0 {
344+ return
345+ }
346+
347+ combinedOutput := strings .Join (testOutputs , "\n \n " )
348+
349+ if testCase .Error != nil {
350+ if len (strings .TrimSpace (testCase .Error .Value )) > 0 {
351+ testCase .Error .Value = testCase .Error .Value + "\n \n " + combinedOutput
352+ } else {
353+ testCase .Error .Value = combinedOutput
354+ }
355+ } else if testCase .Failure != nil {
356+ if len (strings .TrimSpace (testCase .Failure .Value )) > 0 {
357+ testCase .Failure .Value = testCase .Failure .Value + "\n \n " + combinedOutput
358+ } else {
359+ testCase .Failure .Value = combinedOutput
360+ }
361+ } else if testCase .Skipped != nil {
362+ if len (strings .TrimSpace (testCase .Skipped .Value )) > 0 {
363+ testCase .Skipped .Value = testCase .Skipped .Value + "\n \n " + combinedOutput
364+ } else {
365+ testCase .Skipped .Value = combinedOutput
252366 }
253367 }
254- return nil
255368}
0 commit comments