Skip to content

Commit

Permalink
Merge pull request #360 from afbjorklund/elapsed
Browse files Browse the repository at this point in the history
Export elapsed time to the post-run environment
  • Loading branch information
dnephin committed Aug 20, 2023
2 parents b637c82 + 7128d8d commit c5c76fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ TESTS_ERRORS # number of errors
TESTS_FAILED # number of failed tests
TESTS_SKIPPED # number of skipped tests
TESTS_TOTAL # number of tests run
TESTS_ELAPSED # test time elapsed, in seconds
```

To get more details about the test run, such as failure messages or the full list of failed
Expand Down
1 change: 1 addition & 0 deletions cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func postRunHook(opts *options, execution *testjson.Execution) error {
fmt.Sprintf("TESTS_FAILED=%d", len(execution.Failed())),
fmt.Sprintf("TESTS_SKIPPED=%d", len(execution.Skipped())),
fmt.Sprintf("TESTS_ERRORS=%d", len(execution.Errors())),
fmt.Sprintf("TESTS_ELAPSED=%.3f", execution.Elapsed().Seconds()),
)
return cmd.Run()
}
11 changes: 10 additions & 1 deletion cmd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"testing"

"gotest.tools/gotestsum/internal/text"
"gotest.tools/gotestsum/testjson"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
Expand All @@ -34,7 +35,15 @@ func TestPostRunHook(t *testing.T) {
exec := newExecFromTestData(t)
err = postRunHook(opts, exec)
assert.NilError(t, err)
golden.Assert(t, buf.String(), "post-run-hook-expected")

actual := text.ProcessLines(t, buf, func(line string) string {
if strings.HasPrefix(line, "TESTS_ELAPSED=0.0") {
i := strings.Index(line, "=")
return line[:i] + "=0.000"
}
return line
})
golden.Assert(t, actual, "post-run-hook-expected")
}

func newExecFromTestData(t *testing.T) *testjson.Execution {
Expand Down
1 change: 1 addition & 0 deletions cmd/testdata/post-run-hook-expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GOTESTSUM_FORMAT=short
GOTESTSUM_JSONFILE=events.json
GOTESTSUM_JSONFILE_TIMING_EVENTS=timing.json
GOTESTSUM_JUNITFILE=junit.xml
TESTS_ELAPSED=0.000
TESTS_ERRORS=0
TESTS_FAILED=13
TESTS_SKIPPED=5
Expand Down

0 comments on commit c5c76fb

Please sign in to comment.