Skip to content

Commit

Permalink
make sure progress writes to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Nov 2, 2024
1 parent f1d3a68 commit 21f393c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ type Options struct {

// Progress will print a single summary line for each package once the package has completed.
// Useful for long running test suites. Maybe used with FollowOutput or on its own.
Progress bool
//
// This will output to stdout.
Progress bool
ProgressOutput io.Writer

// DisableTableOutput will disable all table output. This is used for testing.
DisableTableOutput bool
Expand Down Expand Up @@ -71,6 +74,7 @@ func Run(option Options) (int, error) {
parse.WithFollowVersboseOutput(option.FollowOutputVerbose),
parse.WithWriter(option.FollowOutputWriter),
parse.WithProgress(option.Progress),
parse.WithProgressOutput(option.ProgressOutput),
)
if err != nil {
return 1, err
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ func main() {
Trim: *smallScreenPtr,
TrimPath: *trimPathPtr,
},
Format: format,
Sorter: sorter,
ShowNoTests: *showNoTestsPtr,
Progress: *progressPtr,
Compare: *comparePtr,
Format: format,
Sorter: sorter,
ShowNoTests: *showNoTestsPtr,
Progress: *progressPtr,
ProgressOutput: os.Stdout,
Compare: *comparePtr,

// Do not expose publicly.
DisableTableOutput: false,
Expand Down
2 changes: 1 addition & 1 deletion parse/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) {
// Progress is a special case of follow, where we only print the
// progress of the test suite, but not the output.
if option.progress && option.w != nil {
printProgress(option.w, e, summary.Packages)
printProgress(option.progressOutput, e, summary.Packages)
}

summary.AddEvent(e)
Expand Down
8 changes: 7 additions & 1 deletion parse/process_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ type options struct {
follow bool
followVerbose bool
debug bool
progress bool

progress bool
progressOutput io.Writer
}

type OptionsFunc func(o *options)
Expand All @@ -33,3 +35,7 @@ func WithDebug() OptionsFunc {
func WithProgress(b bool) OptionsFunc {
return func(o *options) { o.progress = b }
}

func WithProgressOutput(w io.Writer) OptionsFunc {
return func(o *options) { o.progressOutput = w }
}

0 comments on commit 21f393c

Please sign in to comment.