Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
49 changes: 26 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion parse/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"
"strconv"
"strings"
"time"
)

// ErrNotParsable indicates the event line was not parsable.
Expand Down Expand Up @@ -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.RFC3339Nano)+" "+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.
Expand Down
6 changes: 6 additions & 0 deletions parse/process_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type options struct {

progress bool
progressOutput progressWriter

includeTimestamp bool
}

type OptionsFunc func(o *options)
Expand Down Expand Up @@ -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 }
}
Loading