diff --git a/internal/app/app.go b/internal/app/app.go index 6303ecc..852d077 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -48,6 +48,9 @@ type Options struct { // Compare includes a diff of a previous test output file in the summary table. Compare string + + // Used with FollowOutput, when enabled it would include timestamp with log lines + IncludeTimestamp bool } func Run(option Options) (int, error) { @@ -76,6 +79,7 @@ func Run(option Options) (int, error) { parse.WithWriter(option.FollowOutputWriter), parse.WithProgress(option.Progress), parse.WithProgressOutput(progressWriter), + parse.WithIncludeTimestamp(option.IncludeTimestamp), ) if err != nil { return 1, err diff --git a/main.go b/main.go index d9fe66a..fc3aad4 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ var ( trimPathPtr = flag.String("trimpath", "", "") // Undocumented flags followVerbosePtr = flag.Bool("follow-verbose", false, "") + includeTimestamp = flag.Bool("include-timestamp", false, "include timestamps in follow output") // Legacy flags noBordersPtr = flag.Bool("noborders", false, "") @@ -48,23 +49,24 @@ var usage = `Usage: go test [packages...] -json > pkgs.out ; tparse [options...] -file pkgs.out Options: - -h Show help. - -v Show version. - -all Display table event for pass and skip. (Failed items always displayed) - -pass Display table for passed tests. - -skip Display table for skipped tests. - -notests Display packages containing no test files or empty test files. - -smallscreen Split subtest names vertically to fit on smaller screens. - -slow Number of slowest tests to display. Default is 0, display all. - -sort Sort table output by attribute [name, elapsed, cover]. Default is name. - -nocolor Disable all colors. (NO_COLOR also supported) - -format The output format for tables [basic, plain, markdown]. Default is basic. - -file Read test output from a file. - -follow Follow raw output from go test to stdout. - -follow-output Write raw output from go test to a file (takes precedence over -follow). - -progress Print a single summary line for each package. Useful for long running test suites. - -compare Compare against a previous test output file. (experimental) - -trimpath Remove path prefix from package names in output, simplifying their display. + -h Show help. + -v Show version. + -all Display table event for pass and skip. (Failed items always displayed) + -pass Display table for passed tests. + -skip Display table for skipped tests. + -notests Display packages containing no test files or empty test files. + -smallscreen Split subtest names vertically to fit on smaller screens. + -slow Number of slowest tests to display. Default is 0, display all. + -sort Sort table output by attribute [name, elapsed, cover]. Default is name. + -nocolor Disable all colors. (NO_COLOR also supported) + -format The output format for tables [basic, plain, markdown]. Default is basic. + -file Read test output from a file. + -follow Follow raw output from go test to stdout. + -follow-output Write raw output from go test to a file (takes precedence over -follow). + -include-timestamp Include timestamps in follow output. + -progress Print a single summary line for each package. Useful for long running test suites. + -compare Compare against a previous test output file. (experimental) + -trimpath Remove path prefix from package names in output, simplifying their display. ` var version string @@ -163,12 +165,13 @@ func main() { Trim: *smallScreenPtr, TrimPath: *trimPathPtr, }, - Format: format, - Sorter: sorter, - ShowNoTests: *showNoTestsPtr, - Progress: *progressPtr, - ProgressOutput: os.Stdout, - Compare: *comparePtr, + Format: format, + Sorter: sorter, + ShowNoTests: *showNoTestsPtr, + Progress: *progressPtr, + ProgressOutput: os.Stdout, + Compare: *comparePtr, + IncludeTimestamp: *includeTimestamp, // Do not expose publicly. DisableTableOutput: false, diff --git a/parse/process.go b/parse/process.go index 3535b72..baeaabb 100644 --- a/parse/process.go +++ b/parse/process.go @@ -10,6 +10,7 @@ import ( "sort" "strconv" "strings" + "time" ) // ErrNotParsable indicates the event line was not parsable. @@ -104,7 +105,12 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) { if !option.followVerbose && isNoisy(e) { continue } - fmt.Fprint(option.w, e.Output) + if e.Output != "" && option.includeTimestamp { + fmt.Fprint(option.w, e.Time.Format(time.RFC3339)+" "+e.Output) + } else { + fmt.Fprint(option.w, e.Output) + } + } // Progress is a special case of follow, where we only print the // progress of the test suite, but not the output. diff --git a/parse/process_options.go b/parse/process_options.go index 1dab626..03c0280 100644 --- a/parse/process_options.go +++ b/parse/process_options.go @@ -17,6 +17,8 @@ type options struct { progress bool progressOutput progressWriter + + includeTimestamp bool } type OptionsFunc func(o *options) @@ -44,3 +46,7 @@ func WithProgress(b bool) OptionsFunc { func WithProgressOutput(w progressWriter) OptionsFunc { return func(o *options) { o.progressOutput = w } } + +func WithIncludeTimestamp(b bool) OptionsFunc { + return func(o *options) { o.includeTimestamp = b } +}