@@ -34,10 +34,11 @@ import (
34
34
*/
35
35
36
36
type TestSuites struct {
37
- XMLName string `xml:"testsuites"`
38
- TestSuite []TestSuite `xml:"testsuite"`
37
+ XMLName string `xml:"testsuites"`
38
+ TestSuites []TestSuite `xml:"testsuite"`
39
39
}
40
40
type TestSuite struct {
41
+ XMLName string `xml:"testsuite"`
41
42
TestCases []TestCase `xml:"testcase"`
42
43
}
43
44
@@ -71,13 +72,16 @@ func (s SkipReason) MarshalText() ([]byte, error) {
71
72
// MergeJUnit merges all junit xml files found in sourceDirectories into a single xml file at destination, using the filter.
72
73
// The merging removes duplicate skipped tests. The original files are deleted.
73
74
func MergeJUnit (testFilter string , sourceDirectories []string , destination string ) error {
74
- var junit TestSuite
75
+ var outputTestSuite TestSuite
75
76
var data []byte
76
77
77
78
re := regexp .MustCompile (testFilter )
78
79
79
80
var mergeErrors []string
80
81
var filesToDelete []string
82
+ var junit TestSuites
83
+ // Keep only matching testcases. Testcases skipped in all test runs are only stored once.
84
+ filtered := map [string ]TestCase {}
81
85
for _ , dir := range sourceDirectories {
82
86
files , err := os .ReadDir (dir )
83
87
if err != nil {
@@ -98,24 +102,24 @@ func MergeJUnit(testFilter string, sourceDirectories []string, destination strin
98
102
if err = xml .Unmarshal (data , & junit ); err != nil {
99
103
return err
100
104
}
101
- }
102
- }
103
105
104
- // Keep only matching testcases. Testcases skipped in all test runs are only stored once.
105
- filtered := map [string ]TestCase {}
106
- for _ , testcase := range junit .TestCases {
107
- if ! re .MatchString (testcase .Name ) {
108
- continue
109
- }
110
- entry , ok := filtered [testcase .Name ]
111
- if ! ok || // not present yet
112
- entry .Skipped != "" && testcase .Skipped == "" { // replaced skipped test with real test run
113
- filtered [testcase .Name ] = testcase
106
+ for _ , testsuite := range junit .TestSuites {
107
+ for _ , testcase := range testsuite .TestCases {
108
+ if ! re .MatchString (testcase .Name ) {
109
+ continue
110
+ }
111
+ entry , ok := filtered [testcase .Name ]
112
+ if ! ok || // not present yet
113
+ entry .Skipped != "" && testcase .Skipped == "" { // replaced skipped test with real test run
114
+ filtered [testcase .Name ] = testcase
115
+ }
116
+ }
117
+ }
114
118
}
115
119
}
116
- junit .TestCases = nil
120
+ outputTestSuite .TestCases = make ([] TestCase , 0 , len ( filtered ))
117
121
for _ , testcase := range filtered {
118
- junit .TestCases = append (junit .TestCases , testcase )
122
+ outputTestSuite .TestCases = append (outputTestSuite .TestCases , testcase )
119
123
}
120
124
121
125
// Re-encode.
0 commit comments