Skip to content

Commit 72b4c87

Browse files
committed
Add wall-time to testname format
1 parent 1940329 commit 72b4c87

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

testjson/format.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ func standardJSONFormat(out io.Writer) EventFormatter {
6464
})
6565
}
6666

67-
func testNameFormat(out io.Writer) EventFormatter {
67+
func testNameFormat(out io.Writer, opts FormatOptions) EventFormatter {
6868
buf := bufio.NewWriter(out)
6969
// nolint:errcheck
7070
return eventFormatterFunc(func(event TestEvent, exec *Execution) error {
7171
formatTest := func() error {
7272
pkgPath := RelativePackagePath(event.Package)
7373

74+
if opts.OutputWallTime {
75+
buf.WriteString(fmtElapsed(exec.Elapsed(), false)) // nolint:errcheck
76+
}
7477
fmt.Fprintf(buf, "%s %s%s %s\n",
7578
colorEvent(event)(strings.ToUpper(string(event.Action))),
7679
joinPkgToTestName(pkgPath, event.Test),
@@ -95,6 +98,9 @@ func testNameFormat(out io.Writer) EventFormatter {
9598
result = colorEvent(event)("EMPTY")
9699
}
97100

101+
if opts.OutputWallTime {
102+
buf.WriteString(fmtElapsed(exec.Elapsed(), false)) // nolint:errcheck
103+
}
98104
event.Elapsed = 0 // hide elapsed for now, for backwards compat
99105
buf.WriteString(result)
100106
buf.WriteRune(' ')
@@ -293,7 +299,7 @@ func NewEventFormatter(out io.Writer, format string, formatOpts FormatOptions) E
293299
case "dots-v2":
294300
return newDotFormatter(out, formatOpts)
295301
case "testname", "short-verbose":
296-
return testNameFormat(out)
302+
return testNameFormat(out, formatOpts)
297303
case "pkgname", "short":
298304
return pkgNameFormat(out, formatOpts)
299305
case "pkgname-and-test-fails", "short-with-failures":

testjson/format_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ func TestFormats_DefaultGoTestJson(t *testing.T) {
8787

8888
testCases := []testCase{
8989
{
90-
name: "testname",
91-
format: testNameFormat,
90+
name: "testname",
91+
format: func(out io.Writer) EventFormatter {
92+
return testNameFormat(out, FormatOptions{})
93+
},
9294
expectedOut: "format/testname.out",
9395
},
9496
{
@@ -167,8 +169,10 @@ func TestFormats_Coverage(t *testing.T) {
167169

168170
testCases := []testCase{
169171
{
170-
name: "testname",
171-
format: testNameFormat,
172+
name: "testname",
173+
format: func(out io.Writer) EventFormatter {
174+
return testNameFormat(out, FormatOptions{})
175+
},
172176
expectedOut: "format/testname-coverage.out",
173177
},
174178
{
@@ -221,8 +225,10 @@ func TestFormats_Shuffle(t *testing.T) {
221225

222226
testCases := []testCase{
223227
{
224-
name: "testname",
225-
format: testNameFormat,
228+
name: "testname",
229+
format: func(out io.Writer) EventFormatter {
230+
return testNameFormat(out, FormatOptions{})
231+
},
226232
expectedOut: "format/testname-shuffle.out",
227233
},
228234
{

0 commit comments

Comments
 (0)