Skip to content

Commit 92b3f4e

Browse files
authored
[CI-5443] fix test plan configs failure message (#247)
* [CI-5443] Display Test Plan Configuration failure messages * test: add tests
1 parent 009ec83 commit 92b3f4e

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ _tmp
55
steps-deploy-to-bitrise-io
66
/.idea/
77
.env
8+
.DS_Store

test/converters/xcresult3/converter_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,30 @@ func TestConverter_XML(t *testing.T) {
204204
},
205205
}, junitXML.TestSuites)
206206
})
207+
208+
t.Run("xcresult3-multiple-test-plan-configurations.xcresult", func(t *testing.T) {
209+
fileName := "xcresult3-multiple-test-plan-configurations.xcresult"
210+
rootDir, xcresultPath, err := setupTestData(fileName)
211+
require.NoError(t, err)
212+
require.NotEmpty(t, rootDir)
213+
require.NotEmpty(t, xcresultPath)
214+
215+
t.Log("tempTestdataDir: ", rootDir)
216+
217+
c := Converter{xcresultPth: xcresultPath}
218+
junitXML, err := c.Convert()
219+
require.NoError(t, err)
220+
require.NotNil(t, junitXML)
221+
222+
require.EqualValues(
223+
t,
224+
junitXML.TestSuites[0].TestCases[0].Failure.Value,
225+
`English: swift_testingTests.swift:20: Expectation failed: true == false - // This test is intended to fail to demonstrate test failure reporting.
226+
German: swift_testingTests.swift:20: Expectation failed: true == false - // This test is intended to fail to demonstrate test failure reporting.
227+
`,
228+
)
229+
230+
})
207231
}
208232

209233
func BenchmarkConverter_XML(b *testing.B) {

test/converters/xcresult3/model3/conversion.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,35 @@ func extractDuration(text string) time.Duration {
112112
return duration
113113
}
114114

115+
func extractFailureMessageFromTestPlanConfigs(testPlanConfigNodes []TestNode) (string, []string) {
116+
var warnings []string
117+
failureMessage := ""
118+
119+
for _, testPlanConfigNode := range testPlanConfigNodes {
120+
msg, wrns := extractFailureMessage(testPlanConfigNode)
121+
if msg != "" {
122+
failureMessage += fmt.Sprintf("%s: %s\n", testPlanConfigNode.Name, msg)
123+
}
124+
if wrns != nil {
125+
warnings = append(warnings, wrns...)
126+
}
127+
}
128+
129+
return failureMessage, warnings
130+
}
131+
115132
func extractFailureMessage(testNode TestNode) (string, []string) {
116133
childrenCount := len(testNode.Children)
117134
if childrenCount == 0 {
118135
return "", nil
119136
}
120137

121-
lastNode := testNode.Children[childrenCount-1]
122-
if lastNode.Type == TestNodeTypeRepetition {
123-
return extractFailureMessage(lastNode)
138+
lastChild := testNode.Children[childrenCount-1]
139+
if lastChild.Type == TestNodeTypeRepetition {
140+
return extractFailureMessage(lastChild)
141+
}
142+
if lastChild.Type == TestNodeTypeTestPlanConfig {
143+
return extractFailureMessageFromTestPlanConfigs(testNode.Children)
124144
}
125145

126146
var warnings []string

0 commit comments

Comments
 (0)