Skip to content

Commit b6ada0f

Browse files
authored
feat: add include-timestamp flag (#148)
1 parent 2e77a24 commit b6ada0f

4 files changed

Lines changed: 43 additions & 24 deletions

File tree

internal/app/app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type Options struct {
4848

4949
// Compare includes a diff of a previous test output file in the summary table.
5050
Compare string
51+
52+
// Used with FollowOutput, when enabled it would include timestamp with log lines
53+
IncludeTimestamp bool
5154
}
5255

5356
func Run(option Options) (int, error) {
@@ -76,6 +79,7 @@ func Run(option Options) (int, error) {
7679
parse.WithWriter(option.FollowOutputWriter),
7780
parse.WithProgress(option.Progress),
7881
parse.WithProgressOutput(progressWriter),
82+
parse.WithIncludeTimestamp(option.IncludeTimestamp),
7983
)
8084
if err != nil {
8185
return 1, err

main.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
trimPathPtr = flag.String("trimpath", "", "")
3838
// Undocumented flags
3939
followVerbosePtr = flag.Bool("follow-verbose", false, "")
40+
includeTimestamp = flag.Bool("include-timestamp", false, "include timestamps in follow output")
4041

4142
// Legacy flags
4243
noBordersPtr = flag.Bool("noborders", false, "")
@@ -48,23 +49,24 @@ var usage = `Usage:
4849
go test [packages...] -json > pkgs.out ; tparse [options...] -file pkgs.out
4950
5051
Options:
51-
-h Show help.
52-
-v Show version.
53-
-all Display table event for pass and skip. (Failed items always displayed)
54-
-pass Display table for passed tests.
55-
-skip Display table for skipped tests.
56-
-notests Display packages containing no test files or empty test files.
57-
-smallscreen Split subtest names vertically to fit on smaller screens.
58-
-slow Number of slowest tests to display. Default is 0, display all.
59-
-sort Sort table output by attribute [name, elapsed, cover]. Default is name.
60-
-nocolor Disable all colors. (NO_COLOR also supported)
61-
-format The output format for tables [basic, plain, markdown]. Default is basic.
62-
-file Read test output from a file.
63-
-follow Follow raw output from go test to stdout.
64-
-follow-output Write raw output from go test to a file (takes precedence over -follow).
65-
-progress Print a single summary line for each package. Useful for long running test suites.
66-
-compare Compare against a previous test output file. (experimental)
67-
-trimpath Remove path prefix from package names in output, simplifying their display.
52+
-h Show help.
53+
-v Show version.
54+
-all Display table event for pass and skip. (Failed items always displayed)
55+
-pass Display table for passed tests.
56+
-skip Display table for skipped tests.
57+
-notests Display packages containing no test files or empty test files.
58+
-smallscreen Split subtest names vertically to fit on smaller screens.
59+
-slow Number of slowest tests to display. Default is 0, display all.
60+
-sort Sort table output by attribute [name, elapsed, cover]. Default is name.
61+
-nocolor Disable all colors. (NO_COLOR also supported)
62+
-format The output format for tables [basic, plain, markdown]. Default is basic.
63+
-file Read test output from a file.
64+
-follow Follow raw output from go test to stdout.
65+
-follow-output Write raw output from go test to a file (takes precedence over -follow).
66+
-include-timestamp Include timestamps in follow output.
67+
-progress Print a single summary line for each package. Useful for long running test suites.
68+
-compare Compare against a previous test output file. (experimental)
69+
-trimpath Remove path prefix from package names in output, simplifying their display.
6870
`
6971

7072
var version string
@@ -163,12 +165,13 @@ func main() {
163165
Trim: *smallScreenPtr,
164166
TrimPath: *trimPathPtr,
165167
},
166-
Format: format,
167-
Sorter: sorter,
168-
ShowNoTests: *showNoTestsPtr,
169-
Progress: *progressPtr,
170-
ProgressOutput: os.Stdout,
171-
Compare: *comparePtr,
168+
Format: format,
169+
Sorter: sorter,
170+
ShowNoTests: *showNoTestsPtr,
171+
Progress: *progressPtr,
172+
ProgressOutput: os.Stdout,
173+
Compare: *comparePtr,
174+
IncludeTimestamp: *includeTimestamp,
172175

173176
// Do not expose publicly.
174177
DisableTableOutput: false,

parse/process.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sort"
1111
"strconv"
1212
"strings"
13+
"time"
1314
)
1415

1516
// ErrNotParsable indicates the event line was not parsable.
@@ -104,7 +105,12 @@ func Process(r io.Reader, optionsFunc ...OptionsFunc) (*GoTestSummary, error) {
104105
if !option.followVerbose && isNoisy(e) {
105106
continue
106107
}
107-
fmt.Fprint(option.w, e.Output)
108+
if e.Output != "" && option.includeTimestamp {
109+
fmt.Fprint(option.w, e.Time.Format(time.RFC3339)+" "+e.Output)
110+
} else {
111+
fmt.Fprint(option.w, e.Output)
112+
}
113+
108114
}
109115
// Progress is a special case of follow, where we only print the
110116
// progress of the test suite, but not the output.

parse/process_options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type options struct {
1717

1818
progress bool
1919
progressOutput progressWriter
20+
21+
includeTimestamp bool
2022
}
2123

2224
type OptionsFunc func(o *options)
@@ -44,3 +46,7 @@ func WithProgress(b bool) OptionsFunc {
4446
func WithProgressOutput(w progressWriter) OptionsFunc {
4547
return func(o *options) { o.progressOutput = w }
4648
}
49+
50+
func WithIncludeTimestamp(b bool) OptionsFunc {
51+
return func(o *options) { o.includeTimestamp = b }
52+
}

0 commit comments

Comments
 (0)