Skip to content

Commit a482c47

Browse files
committed
Omit test outputs and package outputs for tests that pass
1 parent a08fcaf commit a482c47

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var RunTestsCmd = &cobra.Command{
3131
selectTests, _ := cmd.Flags().GetStringSlice("select-tests")
3232
useShuffle, _ := cmd.Flags().GetBool("shuffle")
3333
shuffleSeed, _ := cmd.Flags().GetString("shuffle-seed")
34+
omitOutputsOnSuccess, _ := cmd.Flags().GetBool("omit-test-outputs-on-success")
3435

3536
// Check if project dependencies are correctly set up
3637
if err := checkDependencies(projectPath); err != nil {
@@ -62,6 +63,7 @@ var RunTestsCmd = &cobra.Command{
6263
SelectedTestPackages: testPackages,
6364
UseShuffle: useShuffle,
6465
ShuffleSeed: shuffleSeed,
66+
OmitOutputsOnSuccess: omitOutputsOnSuccess,
6567
}
6668

6769
// Run the tests
@@ -119,6 +121,7 @@ func init() {
119121
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")
120122
RunTestsCmd.Flags().StringSlice("select-tests", nil, "Comma-separated list of test names to specifically run")
121123
RunTestsCmd.Flags().Float64("max-pass-ratio", 1.0, "The maximum pass ratio threshold for a test to be considered flaky. Any tests below this pass rate will be considered flaky.")
124+
RunTestsCmd.Flags().Bool("omit-test-outputs-on-success", true, "Omit test outputs and package outputs for tests that pass")
122125
}
123126

124127
func checkDependencies(projectPath string) error {

tools/flakeguard/runner/runner.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Runner struct {
3939
SelectTests []string // Test names to include.
4040
SelectedTestPackages []string // Explicitly selected packages to run.
4141
CollectRawOutput bool // Set to true to collect test output for later inspection.
42+
OmitOutputsOnSuccess bool // Set to true to omit test outputs on success.
4243
rawOutputs map[string]*bytes.Buffer
4344
}
4445

@@ -69,7 +70,7 @@ func (r *Runner) RunTests() (*reports.TestReport, error) {
6970
}
7071
}
7172

72-
results, err := parseTestResults(r.RunCount, jsonFilePaths)
73+
results, err := r.parseTestResults(jsonFilePaths)
7374
if err != nil {
7475
return nil, fmt.Errorf("failed to parse test results: %w", err)
7576
}
@@ -182,7 +183,7 @@ func (e entry) String() string {
182183
// panics and failures at that point.
183184
// Subtests add more complexity, as panics in subtests are only reported in their parent's output,
184185
// and cannot be accurately attributed to the subtest that caused them.
185-
func parseTestResults(expectedRuns int, filePaths []string) ([]reports.TestResult, error) {
186+
func (r *Runner) parseTestResults(filePaths []string) ([]reports.TestResult, error) {
186187
var (
187188
testDetails = make(map[string]*reports.TestResult) // Holds run, pass counts, and other details for each test
188189
panickedPackages = map[string]struct{}{} // Packages with tests that panicked
@@ -192,6 +193,7 @@ func parseTestResults(expectedRuns int, filePaths []string) ([]reports.TestResul
192193
panicDetectionMode = false
193194
raceDetectionMode = false
194195
detectedEntries = []entry{} // race or panic entries
196+
expectedRuns = r.RunCount
195197
)
196198

197199
// Process each file
@@ -357,6 +359,10 @@ func parseTestResults(expectedRuns int, filePaths []string) ([]reports.TestResul
357359
}
358360
result.Durations = append(result.Durations, duration)
359361
result.Successes++
362+
if r.OmitOutputsOnSuccess {
363+
// Clear outputs for passing tests
364+
result.Outputs = nil
365+
}
360366
}
361367
case "fail":
362368
if entryLine.Test != "" {

0 commit comments

Comments
 (0)