@@ -179,14 +179,29 @@ func AggregateTestResults(folderPath string) (*TestReport, error) {
179179
180180// PrintTests prints tests in a pretty format
181181func PrintTests (w io.Writer , tests []TestResult , maxPassRatio float64 ) (allRuns , passes , fails , skips , races , panics , flakes int ) {
182- fmt .Fprintln (w , "| Test Name | Test Package | Pass Ratio | Skipped | Runs | Successes | Failures | Panics | Races | Skips | Avg Duration |" )
183- fmt .Fprintln (w , "|-----------|--------------|------------|---------|------|-----------|----------|--------|-------|-------|--------------|" )
182+ headers := []string {
183+ "Test Name" , "Test Package" , "Pass Ratio" , "Skipped" , "Runs" , "Successes" , "Failures" , "Panics" , "Races" , "Skips" , "Avg Duration" ,
184+ }
185+ rows := [][]string {}
186+
184187 for _ , test := range tests {
185188 if test .PassRatio >= maxPassRatio {
186189 continue
187190 }
188- fmt .Fprintf (w , "| %s | %s | %.2f%% | %v | %d | %d | %d | %d | %d | %d | %s |\n " ,
189- test .TestName , test .TestPackage , test .PassRatio * 100 , test .Skipped , test .Runs , test .Successes , test .Failures , test .Panics , test .Races , test .Skips , avgDuration (test .Durations ).String ())
191+ rows = append (rows , []string {
192+ test .TestName ,
193+ test .TestPackage ,
194+ fmt .Sprintf ("%.2f%%" , test .PassRatio * 100 ),
195+ fmt .Sprintf ("%v" , test .Skipped ),
196+ fmt .Sprintf ("%d" , test .Runs ),
197+ fmt .Sprintf ("%d" , test .Successes ),
198+ fmt .Sprintf ("%d" , test .Failures ),
199+ fmt .Sprintf ("%d" , test .Panics ),
200+ fmt .Sprintf ("%d" , test .Races ),
201+ fmt .Sprintf ("%d" , test .Skips ),
202+ avgDuration (test .Durations ).String (),
203+ })
204+
190205 allRuns += test .Runs
191206 passes += test .Successes
192207 fails += test .Failures
@@ -195,11 +210,55 @@ func PrintTests(w io.Writer, tests []TestResult, maxPassRatio float64) (allRuns,
195210 panics += test .Panics
196211 flakes += fails + races + panics
197212 }
213+
214+ // Determine column widths
215+ colWidths := make ([]int , len (headers ))
216+ for i , header := range headers {
217+ colWidths [i ] = len (header )
218+ }
219+ for _ , row := range rows {
220+ for i , cell := range row {
221+ if len (cell ) > colWidths [i ] {
222+ colWidths [i ] = len (cell )
223+ }
224+ }
225+ }
226+
227+ // Helper function to print a row
228+ printRow := func (cells []string ) {
229+ var buffer bytes.Buffer
230+ for i , cell := range cells {
231+ buffer .WriteString (fmt .Sprintf (" %-*s |" , colWidths [i ], cell ))
232+ }
233+ fmt .Fprintln (w , "|" + buffer .String ())
234+ }
235+
236+ // Print header separator
237+ printSeparator := func () {
238+ var buffer bytes.Buffer
239+ for _ , width := range colWidths {
240+ buffer .WriteString (" " + strings .Repeat ("-" , width ) + " |" )
241+ }
242+ fmt .Fprintln (w , "|" + buffer .String ())
243+ }
244+
245+ // Print table
246+ printSeparator ()
247+ printRow (headers )
248+ printSeparator ()
249+ for _ , row := range rows {
250+ printRow (row )
251+ }
252+ printSeparator ()
253+
254+ // Print totals
255+ fmt .Fprintf (w , "\n Summary:\n " )
256+ fmt .Fprintf (w , "Total Runs: %d, Passes: %d, Failures: %d, Panics: %d, Races: %d, Skips: %d\n " , allRuns , passes , fails , panics , races , skips )
198257 return
199258}
200259
201- // TestsSummary builds a summary of test results in markdown format, handy for reporting in CI and Slack
202- func TestsSummary (w io.Writer , testReport * TestReport , maxPassRatio float64 ) {
260+ // MarkdownSummary builds a summary of test results in markdown format, handy for reporting in CI and Slack
261+ func MarkdownSummary (w io.Writer , testReport * TestReport , maxPassRatio float64 ) {
203262 tests := testReport .Results
204263 fmt .Fprintln (w , "# Flakeguard Summary" )
205264 fmt .Fprintln (w , "| **Setting** | **Value** |" )
@@ -224,7 +283,7 @@ func TestsSummary(w io.Writer, testReport *TestReport, maxPassRatio float64) {
224283 test .Failures , test .Panics , test .Races , test .Skips , avgDuration (test .Durations ).String (),
225284 )
226285 }
227- allRuns , passes , fails , skips , races , panics , flakes := PrintTests (testsData , tests , maxPassRatio )
286+ allRuns , passes , _ , _ , _ , _ , flakes := PrintTests (testsData , tests , maxPassRatio )
228287 if allRuns > 0 {
229288 avgPassRatio = float64 (passes ) / float64 (allRuns )
230289 }
@@ -235,18 +294,9 @@ func TestsSummary(w io.Writer, testReport *TestReport, maxPassRatio float64) {
235294 }
236295 fmt .Fprintf (w , "Ran `%d` tests `%d` times with a `%.2f%%` pass ratio and found `%d` flaky tests\n " , len (tests ), allRuns , avgPassRatio * 100 , flakes )
237296 fmt .Fprintf (w , "### Results" )
238- separator := "|----------------|------------------|--------------------|------------------|-----------------|-----------------|"
239- fmt .Fprintln (w , "| **Total Runs** | **Total Passes** | **Total Failures** | **Total Panics** | **Total Races** | **Total Skips** |" )
240- fmt .Fprintln (w , separator )
241- fmt .Fprintf (w , "| %d | %d | %d | %d | %d | %d |\n " , allRuns , passes , fails , panics , races , skips )
242- fmt .Fprintln (w , separator )
243297 if avgPassRatio < maxPassRatio {
244298 fmt .Fprintln (w , "### Flakes" )
245- separator = "|---------------|------------------|----------------|-------------|----------|---------------|--------------|------------|-----------|-----------|------------------|"
246- fmt .Fprintln (w , "| **Test Name** | **Test Package** | **Pass Ratio** | **Skipped** | **Runs** | **Successes** | **Failures** | **Panics** | **Races** | **Skips** | **Avg Duration** |" )
247- fmt .Fprintln (w , separator )
248299 fmt .Fprint (w , testsData .String ())
249- fmt .Fprintln (w , separator )
250300 }
251301}
252302
@@ -266,7 +316,7 @@ func SaveFilteredResultsAndLogs(outputResultsPath, outputLogsPath string, report
266316 return fmt .Errorf ("error opening markdown file: %w" , err )
267317 }
268318 defer summaryFile .Close ()
269- TestsSummary (summaryFile , report , 1.0 )
319+ MarkdownSummary (summaryFile , report , 1.0 )
270320 fmt .Printf ("Test results saved to %s and summary to %s\n " , jsonFileName , mdFileName )
271321 } else {
272322 fmt .Println ("No failed tests found based on the specified threshold and min pass ratio." )
0 commit comments