Skip to content

Commit 5583d1e

Browse files
Add missing attributes and expose system outputs (#254)
* fix: add missing attributes to parsed model * fix: extend test_report models * feat: expose system-out and system-err and append them to message contents * test: fix tests * feat: separate Failure, Error, system-out and system-err
1 parent 01bd718 commit 5583d1e

File tree

8 files changed

+603
-316
lines changed

8 files changed

+603
-316
lines changed

test/converters/converters_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestXCresult3Converters(t *testing.T) {
2626
Name: "rtgtrghtrgTests",
2727
Tests: 2,
2828
Failures: 0,
29+
Errors: 0,
2930
Time: 0.26063,
3031
TestCases: []testreport.TestCase{
3132
{ // plain test case
@@ -44,6 +45,7 @@ func TestXCresult3Converters(t *testing.T) {
4445
Name: "rtgtrghtrgUITests",
4546
Tests: 15,
4647
Failures: 3,
48+
Errors: 0,
4749
Time: 0.759,
4850
TestCases: []testreport.TestCase{
4951
// class rtgtrghtrg3UITests: XCTestCase inside rtgtrghtrgUITests class

test/converters/junitxml/junitxml.go

Lines changed: 100 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66

77
"github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/testreport"
8-
"github.com/pkg/errors"
8+
errorPkg "github.com/pkg/errors"
99
)
1010

1111
func (c *Converter) Setup(_ bool) {}
@@ -54,13 +54,9 @@ func parseTestReport(result resultReader) (TestReport, error) {
5454
return TestReport{TestSuites: []TestSuite{testSuite}}, nil
5555
}
5656

57-
return TestReport{}, errors.Wrap(errors.Wrap(testSuiteErr, string(data)), testReportErr.Error())
57+
return TestReport{}, errorPkg.Wrap(errorPkg.Wrap(testSuiteErr, string(data)), testReportErr.Error())
5858
}
5959

60-
// merges Suites->Cases->Error and Suites->Cases->SystemErr field values into Suites->Cases->Failure field
61-
// with 2 newlines and error category prefix
62-
// the two newlines applied only if there is a failure message already
63-
// this is required because our testing service currently handles failure field properly
6460
func convertTestReport(report TestReport) testreport.TestReport {
6561
convertedReport := testreport.TestReport{
6662
XMLName: report.XMLName,
@@ -76,13 +72,17 @@ func convertTestReport(report TestReport) testreport.TestReport {
7672

7773
func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
7874
convertedTestSuite := testreport.TestSuite{
79-
XMLName: testSuite.XMLName,
80-
Name: testSuite.Name,
81-
Time: testSuite.Time,
75+
XMLName: testSuite.XMLName,
76+
Name: testSuite.Name,
77+
Time: testSuite.Time,
78+
Assertions: testSuite.Assertions,
79+
Timestamp: testSuite.Timestamp,
80+
File: testSuite.File,
8281
}
8382

8483
tests := 0
8584
failures := 0
85+
errors := 0
8686
skipped := 0
8787

8888
flattenedTestCases := flattenGroupedTestCases(testSuite.TestCases)
@@ -93,6 +93,9 @@ func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
9393
if convertedTestCase.Failure != nil {
9494
failures++
9595
}
96+
if convertedTestCase.Error != nil {
97+
errors++
98+
}
9699
if convertedTestCase.Skipped != nil {
97100
skipped++
98101
}
@@ -101,12 +104,12 @@ func convertTestSuite(testSuite TestSuite) testreport.TestSuite {
101104

102105
for _, childSuite := range testSuite.TestSuites {
103106
convertedChildSuite := convertTestSuite(childSuite)
104-
105107
convertedTestSuite.TestSuites = append(convertedTestSuite.TestSuites, convertedChildSuite)
106108
}
107109

108110
convertedTestSuite.Tests = tests
109111
convertedTestSuite.Failures = failures
112+
convertedTestSuite.Errors = errors
110113
convertedTestSuite.Skipped = skipped
111114

112115
return convertedTestSuite
@@ -130,74 +133,74 @@ func flattenGroupedTestCases(testCases []TestCase) []TestCase {
130133
}
131134

132135
for _, flakyFailure := range testCase.FlakyFailures {
133-
flattenedTestCase.Failure = convertToFailure(flakyFailure.Type, flakyFailure.Message, flakyFailure.SystemErr)
136+
flattenedTestCase.Failure = &Failure{
137+
Type: flakyFailure.Type,
138+
Message: flakyFailure.Message,
139+
Value: flakyFailure.Value,
140+
}
141+
flattenedTestCase.SystemErr = flakyFailure.SystemErr
142+
flattenedTestCase.SystemOut = flakyFailure.SystemOut
134143
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
135144
}
136145

146+
flattenedTestCase.Failure = nil
137147
for _, flakyError := range testCase.FlakyErrors {
138-
flattenedTestCase.Failure = convertToFailure(flakyError.Type, flakyError.Message, flakyError.SystemErr)
148+
flattenedTestCase.Error = &Error{
149+
Type: flakyError.Type,
150+
Message: flakyError.Message,
151+
Value: flakyError.Value,
152+
}
153+
flattenedTestCase.SystemErr = flakyError.SystemErr
154+
flattenedTestCase.SystemOut = flakyError.SystemOut
139155
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
140156
}
141157

158+
flattenedTestCase.Error = nil
142159
for _, rerunfailure := range testCase.RerunFailures {
143-
flattenedTestCase.Failure = convertToFailure(rerunfailure.Type, rerunfailure.Message, rerunfailure.SystemErr)
160+
flattenedTestCase.Failure = &Failure{
161+
Type: rerunfailure.Type,
162+
Message: rerunfailure.Message,
163+
Value: rerunfailure.Value,
164+
}
165+
flattenedTestCase.SystemErr = rerunfailure.SystemErr
166+
flattenedTestCase.SystemOut = rerunfailure.SystemOut
144167
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
145168
}
146169

170+
flattenedTestCase.Failure = nil
147171
for _, rerunError := range testCase.RerunErrors {
148-
flattenedTestCase.Failure = convertToFailure(rerunError.Type, rerunError.Message, rerunError.SystemErr)
172+
flattenedTestCase.Error = &Error{
173+
Type: rerunError.Type,
174+
Message: rerunError.Message,
175+
Value: rerunError.Value,
176+
}
177+
flattenedTestCase.SystemErr = rerunError.SystemErr
178+
flattenedTestCase.SystemOut = rerunError.SystemOut
149179
flattenedTestCases = append(flattenedTestCases, flattenedTestCase)
150180
}
151181

152182
}
153183
return flattenedTestCases
154184
}
155185

156-
func convertToFailure(itemType, failureMessage, systemErr string) *Failure {
157-
var message string
158-
if len(strings.TrimSpace(itemType)) > 0 {
159-
message = itemType
160-
}
161-
if len(strings.TrimSpace(failureMessage)) > 0 {
162-
if len(message) > 0 {
163-
message += ": "
164-
}
165-
message += failureMessage
166-
}
167-
168-
if len(strings.TrimSpace(systemErr)) > 0 {
169-
if len(message) > 0 {
170-
message += "\n\n"
171-
}
172-
message += "System error:\n" + systemErr
173-
}
174-
175-
if len(message) > 0 {
176-
return &Failure{
177-
Value: message,
178-
}
179-
}
180-
return nil
181-
}
182-
183186
func convertTestCase(testCase TestCase) testreport.TestCase {
184187
convertedTestCase := testreport.TestCase{
185188
XMLName: testCase.XMLName,
186189
ConfigurationHash: testCase.ConfigurationHash,
187190
Name: testCase.Name,
188191
ClassName: testCase.ClassName,
189192
Time: testCase.Time,
193+
Assertions: testCase.Assertions,
194+
File: testCase.File,
195+
Line: testCase.Line,
196+
Failure: convertFailure(testCase.Failure),
197+
Error: convertError(testCase.Error),
198+
Skipped: convertSkipped(testCase.Skipped),
190199
Properties: convertProperties(testCase.Properties),
200+
SystemOut: convertSystemOut(testCase.SystemOut),
201+
SystemErr: convertSystemErr(testCase.SystemErr),
191202
}
192203

193-
if testCase.Skipped != nil {
194-
convertedTestCase.Skipped = &testreport.Skipped{
195-
XMLName: testCase.Skipped.XMLName,
196-
}
197-
}
198-
199-
convertedTestCase.Failure = convertErrorsToFailure(testCase.Failure, testCase.Error, testCase.SystemErr)
200-
201204
return convertedTestCase
202205
}
203206

@@ -218,38 +221,62 @@ func convertProperties(properties *Properties) *testreport.Properties {
218221
return convertedProperties
219222
}
220223

221-
func convertErrorsToFailure(failure *Failure, error *Error, systemErr string) *testreport.Failure {
222-
var messages []string
224+
func convertSystemOut(systemOut string) *testreport.SystemOut {
225+
if len(strings.TrimSpace(systemOut)) == 0 {
226+
return nil
227+
}
228+
229+
return &testreport.SystemOut{
230+
XMLName: xml.Name{Local: "system-out"},
231+
Value: strings.TrimSpace(systemOut),
232+
}
233+
}
234+
235+
func convertSystemErr(systemErr string) *testreport.SystemErr {
236+
if len(strings.TrimSpace(systemErr)) == 0 {
237+
return nil
238+
}
223239

224-
if failure != nil {
225-
if len(strings.TrimSpace(failure.Message)) > 0 {
226-
messages = append(messages, failure.Message)
227-
}
240+
return &testreport.SystemErr{
241+
XMLName: xml.Name{Local: "system-err"},
242+
Value: strings.TrimSpace(systemErr),
243+
}
244+
}
228245

229-
if len(strings.TrimSpace(failure.Value)) > 0 {
230-
messages = append(messages, failure.Value)
231-
}
246+
func convertSkipped(skipped *Skipped) *testreport.Skipped {
247+
if skipped == nil {
248+
return nil
232249
}
233250

234-
if error != nil {
235-
if len(strings.TrimSpace(error.Message)) > 0 {
236-
messages = append(messages, "Error message:\n"+error.Message)
237-
}
251+
return &testreport.Skipped{
252+
XMLName: xml.Name{Local: "skipped"},
253+
Message: skipped.Message,
254+
Value: strings.TrimSpace(skipped.Value),
255+
}
256+
}
238257

239-
if len(strings.TrimSpace(error.Value)) > 0 {
240-
messages = append(messages, "Error value:\n"+error.Value)
241-
}
258+
func convertFailure(failure *Failure) *testreport.Failure {
259+
if failure == nil {
260+
return nil
242261
}
243262

244-
if len(systemErr) > 0 {
245-
messages = append(messages, "System error:\n"+systemErr)
263+
return &testreport.Failure{
264+
XMLName: xml.Name{Local: "failure"},
265+
Type: failure.Type,
266+
Message: failure.Message,
267+
Value: strings.TrimSpace(failure.Value),
246268
}
269+
}
247270

248-
if len(messages) > 0 {
249-
return &testreport.Failure{
250-
XMLName: xml.Name{Local: "failure"},
251-
Value: strings.Join(messages, "\n\n"),
252-
}
271+
func convertError(error *Error) *testreport.Error {
272+
if error == nil {
273+
return nil
274+
}
275+
276+
return &testreport.Error{
277+
XMLName: xml.Name{Local: "error"},
278+
Type: error.Type,
279+
Message: error.Message,
280+
Value: strings.TrimSpace(error.Value),
253281
}
254-
return nil
255282
}

0 commit comments

Comments
 (0)