@@ -119,64 +119,83 @@ func parseTestResults(filePaths []string) ([]reports.TestResult, error) {
119119 return nil , fmt .Errorf ("failed to parse json test output: %s, err: %w" , scanner .Text (), err )
120120 }
121121
122- // Determine the key based on whether Test is empty
123- var key string
122+ // Only create TestResult for test-level entries
123+ var result * reports. TestResult
124124 if entry .Test != "" {
125- key = entry .Package + "/" + entry .Test
126- } else {
127- key = entry .Package // Package-level key
128- }
129-
130- if _ , exists := testDetails [key ]; ! exists {
131- testName := entry .Test
132- if testName == "" {
133- testName = "Package Level"
134- }
135- testDetails [key ] = & reports.TestResult {
136- TestName : testName ,
137- TestPackage : entry .Package ,
138- Runs : 0 ,
139- PassRatio : 0 ,
140- Outputs : []string {},
125+ // Determine the key
126+ key := entry .Package + "/" + entry .Test
127+
128+ if _ , exists := testDetails [key ]; ! exists {
129+ testDetails [key ] = & reports.TestResult {
130+ TestName : entry .Test ,
131+ TestPackage : entry .Package ,
132+ Runs : 0 ,
133+ PassRatio : 0 ,
134+ Outputs : []string {},
135+ PackageOutputs : []string {},
136+ }
141137 }
138+ result = testDetails [key ]
142139 }
143140
144- result := testDetails [key ]
145-
146- // Collect test outputs
141+ // Collect outputs
147142 if entry .Output != "" {
148- result .Outputs = append (result .Outputs , entry .Output )
143+ if entry .Test != "" {
144+ // Test-level output
145+ result .Outputs = append (result .Outputs , entry .Output )
146+ } else {
147+ // Package-level output
148+ // Append to PackageOutputs of all TestResults in the same package
149+ for _ , res := range testDetails {
150+ if res .TestPackage == entry .Package {
151+ res .PackageOutputs = append (res .PackageOutputs , entry .Output )
152+ }
153+ }
154+ }
149155 }
150156
151157 switch entry .Action {
152158 case "run" :
153- result .Runs ++
159+ if entry .Test != "" {
160+ result .Runs ++
161+ }
154162 case "pass" :
155- result .PassRatio = (result .PassRatio * float64 (result .Runs - 1 ) + 1 ) / float64 (result .Runs )
156- result .PassRatioPercentage = fmt .Sprintf ("%.0f%%" , result .PassRatio * 100 )
157- result .Durations = append (result .Durations , entry .Elapsed )
163+ if entry .Test != "" {
164+ result .PassRatio = (result .PassRatio * float64 (result .Runs - 1 ) + 1 ) / float64 (result .Runs )
165+ result .PassRatioPercentage = fmt .Sprintf ("%.0f%%" , result .PassRatio * 100 )
166+ result .Durations = append (result .Durations , entry .Elapsed )
167+ }
158168 case "fail" :
159- result .PassRatio = (result .PassRatio * float64 (result .Runs - 1 )) / float64 (result .Runs )
160- result .PassRatioPercentage = fmt .Sprintf ("%.0f%%" , result .PassRatio * 100 )
161- result .Durations = append (result .Durations , entry .Elapsed )
169+ if entry .Test != "" {
170+ result .PassRatio = (result .PassRatio * float64 (result .Runs - 1 )) / float64 (result .Runs )
171+ result .PassRatioPercentage = fmt .Sprintf ("%.0f%%" , result .PassRatio * 100 )
172+ result .Durations = append (result .Durations , entry .Elapsed )
173+ }
162174 case "output" :
163175 // Output already handled above
164176 if panicRe .MatchString (entry .Output ) {
165177 if entry .Test != "" {
166178 // Test-level panic
167179 result .Panicked = true
180+ result .PassRatio = (result .PassRatio * float64 (result .Runs - 1 )) / float64 (result .Runs )
181+ result .PassRatioPercentage = fmt .Sprintf ("%.0f%%" , result .PassRatio * 100 )
182+ result .Durations = append (result .Durations , entry .Elapsed )
168183 } else {
169184 // Package-level panic
170- result .PackagePanicked = true
185+ // Mark PackagePanicked for all TestResults in the package
186+ for _ , res := range testDetails {
187+ if res .TestPackage == entry .Package {
188+ res .PackagePanicked = true
189+ }
190+ }
171191 }
172- result .PassRatio = (result .PassRatio * float64 (result .Runs - 1 )) / float64 (result .Runs )
173- result .PassRatioPercentage = fmt .Sprintf ("%.0f%%" , result .PassRatio * 100 )
174- result .Durations = append (result .Durations , entry .Elapsed )
175192 }
176193 case "skip" :
177- result .Skipped = true
178- result .Runs ++
179- result .Durations = append (result .Durations , entry .Elapsed )
194+ if entry .Test != "" {
195+ result .Skipped = true
196+ result .Runs ++
197+ result .Durations = append (result .Durations , entry .Elapsed )
198+ }
180199 }
181200 }
182201
0 commit comments