Skip to content

Commit d963642

Browse files
committed
Handle test bundle level test cases
1 parent 9a1a296 commit d963642

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

test/converters/xcresult3/model3/conversion.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ func Convert(data *TestData) (*TestSummary, []string, error) {
2525
testBundle := TestBundle{Name: testBundleNode.Name}
2626

2727
for _, testSuiteNode := range testBundleNode.Children {
28-
if testSuiteNode.Type != TestNodeTypeTestSuite {
29-
return nil, warnings, fmt.Errorf("test suite expected but got: %s", testSuiteNode.Type)
28+
var name string
29+
var testNodes []TestNode
30+
31+
if testSuiteNode.Type == TestNodeTypeTestCase {
32+
name = testBundleNode.Name
33+
testNodes = []TestNode{testSuiteNode}
34+
} else if testSuiteNode.Type == TestNodeTypeTestSuite {
35+
name = testSuiteNode.Name
36+
testNodes = testSuiteNode.Children
37+
} else {
38+
return nil, warnings, fmt.Errorf("test suite or test case expected but got: %s", testSuiteNode.Type)
3039
}
3140

32-
testSuite := TestSuite{Name: testSuiteNode.Name}
41+
testSuite := TestSuite{Name: name}
3342

34-
testCases, testCaseWarnings, err := extractTestCases(testSuiteNode)
43+
testCases, testCaseWarnings, err := extractTestCases(testNodes, name)
3544
warnings = append(warnings, testCaseWarnings...)
3645

3746
if err != nil {
@@ -51,14 +60,14 @@ func Convert(data *TestData) (*TestSummary, []string, error) {
5160
return &summary, warnings, nil
5261
}
5362

54-
func extractTestCases(testSuiteNode TestNode) ([]TestCase, []string, error) {
63+
func extractTestCases(nodes []TestNode, fallbackName string) ([]TestCase, []string, error) {
5564
var testCases []TestCase
5665
var warnings []string
5766

58-
for _, testCaseNode := range testSuiteNode.Children {
67+
for _, testCaseNode := range nodes {
5968
// A customer's xcresult file contained this use case where a test suite is a child of a test suite.
6069
if testCaseNode.Type == TestNodeTypeTestSuite {
61-
nestedTestCases, nestedWarnings, err := extractTestCases(testCaseNode)
70+
nestedTestCases, nestedWarnings, err := extractTestCases(testCaseNode.Children, fallbackName)
6271
warnings = append(warnings, nestedWarnings...)
6372

6473
if err != nil {
@@ -78,7 +87,7 @@ func extractTestCases(testSuiteNode TestNode) ([]TestCase, []string, error) {
7887
if className == "" {
7988
// In rare cases the identifier is an empty string so we need to use the test suite name which is the
8089
// same as the first part of the identifier in normal cases.
81-
className = testSuiteNode.Name
90+
className = fallbackName
8291
}
8392

8493
message, failureMessageWarnings := extractFailureMessage(testCaseNode)

0 commit comments

Comments
 (0)