Skip to content

Commit

Permalink
Merge pull request #363 from afbjorklund/elapsed-sec
Browse files Browse the repository at this point in the history
Add the time unit to elapsed time duration
  • Loading branch information
dnephin authored Aug 26, 2023
2 parents 73827dd + 0d4e428 commit f3d79ea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ test run has completed. The binary will be run with the following environment
variables set:

```
GOTESTSUM_ELAPSED # test time elapsed, in seconds
GOTESTSUM_FORMAT # gotestsum format (ex: short)
GOTESTSUM_ELAPSED # test run time in seconds (ex: 2.45s)
GOTESTSUM_FORMAT # gotestsum format (ex: pkgname)
GOTESTSUM_JSONFILE # path to the jsonfile, empty if no file path was given
GOTESTSUM_JUNITFILE # path to the junit.xml file, empty if no file path was given
TESTS_ERRORS # number of errors
Expand Down
2 changes: 1 addition & 1 deletion cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func postRunHook(opts *options, execution *testjson.Execution) error {
"GOTESTSUM_JSONFILE="+opts.jsonFile,
"GOTESTSUM_JSONFILE_TIMING_EVENTS="+opts.jsonFileTimingEvents,
"GOTESTSUM_JUNITFILE="+opts.junitFile,
fmt.Sprintf("GOTESTSUM_ELAPSED=%.3f", execution.Elapsed().Seconds()),
fmt.Sprintf("GOTESTSUM_ELAPSED=%.3fs", execution.Elapsed().Seconds()),
fmt.Sprintf("TESTS_TOTAL=%d", execution.Total()),
fmt.Sprintf("TESTS_FAILED=%d", len(execution.Failed())),
fmt.Sprintf("TESTS_SKIPPED=%d", len(execution.Skipped())),
Expand Down
5 changes: 3 additions & 2 deletions cmd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func TestPostRunHook(t *testing.T) {
assert.NilError(t, err)

actual := text.ProcessLines(t, buf, func(line string) string {
if strings.HasPrefix(line, "GOTESTSUM_ELAPSED=0.0") {
if strings.HasPrefix(line, "GOTESTSUM_ELAPSED=0.0") &&
strings.HasSuffix(line, "s") {
i := strings.Index(line, "=")
return line[:i] + "=0.000"
return line[:i] + "=0.000s"
}
return line
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/testdata/post-run-hook-expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOTESTSUM_ELAPSED=0.000
GOTESTSUM_ELAPSED=0.000s
GOTESTSUM_FORMAT=short
GOTESTSUM_JSONFILE=events.json
GOTESTSUM_JSONFILE_TIMING_EVENTS=timing.json
Expand Down

0 comments on commit f3d79ea

Please sign in to comment.