@@ -25,13 +25,22 @@ func Convert(data *TestData) (*TestSummary, []string, error) {
25
25
testBundle := TestBundle {Name : testBundleNode .Name }
26
26
27
27
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 )
30
39
}
31
40
32
- testSuite := TestSuite {Name : testSuiteNode . Name }
41
+ testSuite := TestSuite {Name : name }
33
42
34
- testCases , testCaseWarnings , err := extractTestCases (testSuiteNode )
43
+ testCases , testCaseWarnings , err := extractTestCases (testNodes , name )
35
44
warnings = append (warnings , testCaseWarnings ... )
36
45
37
46
if err != nil {
@@ -51,14 +60,14 @@ func Convert(data *TestData) (*TestSummary, []string, error) {
51
60
return & summary , warnings , nil
52
61
}
53
62
54
- func extractTestCases (testSuiteNode TestNode ) ([]TestCase , []string , error ) {
63
+ func extractTestCases (nodes [] TestNode , fallbackName string ) ([]TestCase , []string , error ) {
55
64
var testCases []TestCase
56
65
var warnings []string
57
66
58
- for _ , testCaseNode := range testSuiteNode . Children {
67
+ for _ , testCaseNode := range nodes {
59
68
// A customer's xcresult file contained this use case where a test suite is a child of a test suite.
60
69
if testCaseNode .Type == TestNodeTypeTestSuite {
61
- nestedTestCases , nestedWarnings , err := extractTestCases (testCaseNode )
70
+ nestedTestCases , nestedWarnings , err := extractTestCases (testCaseNode . Children , fallbackName )
62
71
warnings = append (warnings , nestedWarnings ... )
63
72
64
73
if err != nil {
@@ -78,7 +87,7 @@ func extractTestCases(testSuiteNode TestNode) ([]TestCase, []string, error) {
78
87
if className == "" {
79
88
// In rare cases the identifier is an empty string so we need to use the test suite name which is the
80
89
// same as the first part of the identifier in normal cases.
81
- className = testSuiteNode . Name
90
+ className = fallbackName
82
91
}
83
92
84
93
message , failureMessageWarnings := extractFailureMessage (testCaseNode )
0 commit comments