@@ -72,13 +72,15 @@ func (s SkipReason) MarshalText() ([]byte, error) {
72
72
// MergeJUnit merges all junit xml files found in sourceDirectories into a single xml file at destination, using the filter.
73
73
// The merging removes duplicate skipped tests. The original files are deleted.
74
74
func MergeJUnit (testFilter string , sourceDirectories []string , destination string ) error {
75
- var junit TestSuite
76
75
var data []byte
77
76
78
77
re := regexp .MustCompile (testFilter )
79
78
80
79
var mergeErrors []string
81
80
var filesToDelete []string
81
+
82
+ // Keep only matching testcases. Testcases skipped in all test runs are only stored once.
83
+ filtered := map [string ]TestCase {}
82
84
for _ , dir := range sourceDirectories {
83
85
files , err := os .ReadDir (dir )
84
86
if err != nil {
@@ -96,24 +98,26 @@ func MergeJUnit(testFilter string, sourceDirectories []string, destination strin
96
98
if err != nil {
97
99
return err
98
100
}
99
- if err = xml .Unmarshal (data , & junit ); err != nil {
100
- return err
101
+ var testSuiteData TestSuite
102
+ if err = xml .Unmarshal (data , & testSuiteData ); err != nil {
103
+ return fmt .Errorf ("failed to unmarshal XML file %v: %w" , fullFilename , err )
104
+ }
105
+
106
+ for _ , testcase := range testSuiteData .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
114
+ }
101
115
}
102
116
}
103
117
}
104
118
105
119
// Keep only matching testcases. Testcases skipped in all test runs are only stored once.
106
- filtered := map [string ]TestCase {}
107
- for _ , testcase := range junit .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
- }
120
+ var junit TestSuite
117
121
junit .TestCases = nil
118
122
for _ , testcase := range filtered {
119
123
junit .TestCases = append (junit .TestCases , testcase )
@@ -122,7 +126,7 @@ func MergeJUnit(testFilter string, sourceDirectories []string, destination strin
122
126
// Re-encode.
123
127
data , err := xml .MarshalIndent (junit , "" , " " )
124
128
if err != nil {
125
- return err
129
+ return fmt . Errorf ( "failed to marshal junit data: %w" , err )
126
130
}
127
131
128
132
if err = os .WriteFile (destination , data , 0644 ); err != nil {
0 commit comments