Skip to content

Commit 6bf9fa8

Browse files
committed
flakeguard: Pretty print failed tests
1 parent c53b6e0 commit 6bf9fa8

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ var RunTestsCmd = &cobra.Command{
5555
skippedTests := reports.FilterSkippedTests(testResults)
5656

5757
if len(failedTests) > 0 {
58-
jsonData, err := json.MarshalIndent(failedTests, "", " ")
59-
if err != nil {
60-
log.Fatalf("Error marshaling test results to JSON: %v", err)
61-
}
62-
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n%d failed tests:\n%s\n", threshold, len(failedTests), string(jsonData))
58+
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n", threshold)
59+
fmt.Printf("%d failed tests:\n", len(failedTests))
60+
reports.PrintTests(failedTests)
6361
}
6462

6563
fmt.Printf("Summary: %d passed, %d skipped, %d failed\n", len(passedTests), len(skippedTests), len(failedTests))

tools/flakeguard/reports/reports.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package reports
22

3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
38
type TestResult struct {
49
TestName string
510
TestPackage string
@@ -42,3 +47,21 @@ func FilterSkippedTests(results []TestResult) []TestResult {
4247
}
4348
return skippedTests
4449
}
50+
51+
// PrintTests prints tests in a pretty format
52+
func PrintTests(tests []TestResult) {
53+
for i, test := range tests {
54+
fmt.Printf("\n--- Test %d ---\n", i+1)
55+
fmt.Printf("TestName: %s\n", test.TestName)
56+
fmt.Printf("TestPackage: %s\n", test.TestPackage)
57+
fmt.Printf("PassRatio: %.2f\n", test.PassRatio)
58+
fmt.Printf("Skipped: %v\n", test.Skipped)
59+
fmt.Printf("Runs: %d\n", test.Runs)
60+
durationsStr := make([]string, len(test.Durations))
61+
for i, duration := range test.Durations {
62+
durationsStr[i] = fmt.Sprintf("%.2fs", duration)
63+
}
64+
fmt.Printf("Durations: %s\n", strings.Join(durationsStr, ", "))
65+
fmt.Printf("Outputs:\n%s\n", strings.Join(test.Outputs, ""))
66+
}
67+
}

0 commit comments

Comments
 (0)