Go 1.15 Release Notes > Minor changes to the testing The testing.T type now has a Deadline method ... A TestMain function is no longer required to call os.Exit. ... The new methods T.TempDir and B.TempDir ... go test -v now groups output by test name, ... https://golang.org/doc/go1.15#testing
Go 1.15 Release Notes > Minor changes to the testing The testing.T type now has a Deadline method ... A TestMain function is no longer required to call os.Exit. ... The new methods T.TempDir and B.TempDir ... go test -v now groups output by test name, ... https://golang.org/doc/go1.15#testing Talk contents
Go 1.15 Release Notes > Minor changes to the library > testing A TestMain function is no longer required to call os.Exit. If a TestMain function returns, the test binary will call os.Exit with the value returned by m.Run. https://golang.org/doc/go1.15#testing
Common TestMain() mistakes $ go test -v ./... === RUN TestHoge --- FAIL: TestHoge (0.00s) FAIL ok github.com/hgsgtk/go-snippets/testing -115/mistake 0.079s defer os.Exit()
Issue #34129 testing: TestMain should not require os.Exit https://github.com/golang/go/issues/34129 “This mistake does happen a lot, and the testing package that called TestMain and prepared the m can certainly record the result of m.Run for use in its own outer os.Exit.” (@rsc Russ Cox)
https://go-review.googlesource.com/c/go/+/219639 219639: testing: do not require os.Exit in TestMain Major change files ... src/testing/testing.go src/cmd/go/internal/load/ test.go
src/testing/testing.go https://go-review.googlesource.com/c/go/+/219639/10/src/testing/testing.go m.Run records its own result in an unexported field of m.
src/cmd/go/internal/load/test.go https://go-review.googlesource.com/c/go/+/219639/10/src/cmd/go/internal/load/test.go if TestMain(m) returns, the outer test func main harness calls os.Exit with that code.
A TestMain function is no longer required to call os.Exit ● A TestMain function is no longer required to call os.Exit ● testing.M の内部変更及び、 go test で生成される main 関 数のテンプレート修正によって実現されている
Go 1.15 Release Notes > Minor changes to the library > testing The testing.T type now has a Deadline method that reports the time at which the test binary will have exceeded its timeout. https://golang.org/doc/go1.15#testing
t.Deadline() https://godoc.org/testing#T.Deadline Deadline reports the time at which the test binary will have exceeded the timeout specified by the -timeout flag. The ok result is false if the -timeout flag indicates “no timeout” (0). % go test -v -timeout=5s -run=TestDeadlineConfirm t.Deadline() = 2020-08-31 18:37:39.502862 +0900 JST m=+5.000488349, timeout set = true $ go test -v -timeout=0 -run=TestDeadlineConfirm t.Deadline() = 0001-01-01 00:00:00 +0000 UTC, timeout set = false
https://go-review.googlesource.com/c/go/+/202758/ 202758: testing: testing: add (*T).Deadline method for test timeout Major change files ... src/testing/testing.go
src/testing/testing.go https://golang.org/src/testing/testing.go#L630 New field ‘deadline’ in testContext New method T.Deadline() testing.T has *testContext
src/testing/testing.go https://go-review.googlesource.com/c/go/+/202758/8/src/testing/testing.go t.Deadline() added in testing.go m.Run() call it. Pass arg to runTests()