aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
AgeCommit message (Collapse)Author
2021-07-27testing: clarify T.Name returns a distinct name of the running testChangkun Ou
According to the discussion, it is clear that T.Name returns a distinct name among all tests. However, there is no specification of how sub-tests with the same specified test name are constructed. This change only clarifies the uniqueness and the components of the name without suggesting any explicit format of the returned name. Fixes #46488 Change-Id: I6cebd419b69fb08d8646cb744a129548452042ef Reviewed-on: https://go-review.googlesource.com/c/go/+/337392 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-07-15testing: clarify in docs that TestMain is advancedMatt T. Proud
Beginner and intermediate Go users periodically use TestMain when requirements do not necessitate TestMain (exceeding least-mechanism design). This commit expands package testing's documentation to convey that the TestMain feature itself is somewhat low-level and potentially unsuitable for casual testing where ordinary test functions would suffice. Fixes #42161 Updates #44200 Change-Id: I91ba0b048c3d6f79110fe8f0fbb58d896edca366 Reviewed-on: https://go-review.googlesource.com/c/go/+/334649 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2021-07-01testing: add TB.SetenvRuss Cox
For #41260 and #46688. Change-Id: I6f42742cc3234a90003136ae8798a6b0e1291788 Reviewed-on: https://go-review.googlesource.com/c/go/+/326790 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-06-17testing: drop unusual characters from TempDir directory nameTobias Klauser
Only use safe characters of the test name for the os.MkdirTemp pattern. This currently includes the alphanumeric characters and ASCII punctuation characters known not to interact with globs. Fixes #46624 Change-Id: I402c34775b943fed9b97963c52f79245cc16dc1d Reviewed-on: https://go-review.googlesource.com/c/go/+/326010 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-04-28testing: add -shuffle=off|on|N to alter the execution order of tests and ↵Paschalis Tsilias
benchmarks This CL adds a new flag to the testing package and the go test command which randomizes the execution order for tests and benchmarks. This can be useful for identifying unwanted dependencies between test or benchmark functions. The flag is off by default. If `-shuffle` is set to `on` then the system clock will be used as the seed value. If `-shuffle` is set to an integer N, then N will be used as the seed value. In both cases, the seed will be reported for failed runs so that they can reproduced later on. Fixes #28592 Change-Id: I62e7dfae5f63f97a0cbd7830ea844d9f7beac335 Reviewed-on: https://go-review.googlesource.com/c/go/+/310033 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Bryan C. Mills <bcmills@google.com>
2021-04-27testing: document that TestMain can be used with benchmarksJulien Tant
Fixes #45764 Change-Id: Ie6c18bb5c20721c2ffa8b4a9cf9f97cdc665a450 GitHub-Last-Rev: 8bcea7e0ff60227c05437b372c0a3546e151af31 GitHub-Pull-Request: golang/go#45808 Reviewed-on: https://go-review.googlesource.com/c/go/+/314349 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Bryan C. Mills <bcmills@google.com>
2021-04-19testing: remove data races so that parallel benchmarks can safely call ↵Michael Fraenkel
.Fatal* and .Skip* Protects the usages of (*common).finished with locks to prevent data races, thus allowing benchmarks to safely invoke .Fatal* and .Skip* concurrently. Fixes #45526 Change-Id: I2b4846f525c426d6c7d3418f8f6c86446adbf986 Reviewed-on: https://go-review.googlesource.com/c/go/+/309572 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Tobias Klauser <tobias.klauser@gmail.com>
2021-04-02testing: clarify when Cleanup is calledCarlo Alberto Ferraris
Change-Id: I2ed394fccec83aac09a49673554cbf504787965b Reviewed-on: https://go-review.googlesource.com/c/go/+/306810 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-03-24testing: update permitted number of -race goroutinesIan Lance Taylor
The value 8128 appears to be correct as of 2021-03-23. The value is determined by the value of kMaxTid currently at https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/tsan/rtl/tsan_defs.h#L68 Fixes #45193 Change-Id: If4a30d7dbebd6775bede42f565dc8a741b8b036c Reviewed-on: https://go-review.googlesource.com/c/go/+/304254 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2021-03-19testing: allow parallel-subtest goroutines to exit when the subtest is completeBryan C. Mills
Fixes #45127 Updates #38768 Change-Id: I7f41901d5bcc07741ac9f5f2a24d2b07ef633cb1 Reviewed-on: https://go-review.googlesource.com/c/go/+/303330 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-19testing: update helperNames just before checking itTao Qingyun
parent's helperNames has not been set when frameSkip called, moving helperNames initilazing to frameSkip. Fixes #44887 Change-Id: I5107c5951033e5e47d1ac441eac3ba5344a7bdc0 GitHub-Last-Rev: 44b90b2e2eeca8e2bb4a2084ec6fdd279c88f76d GitHub-Pull-Request: golang/go#45071 Reviewed-on: https://go-review.googlesource.com/c/go/+/302469 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-03-10testing: fix typo in a commentfanzha02
Change-Id: I781808327be84113cd55c52bc214b821cd166114 Reviewed-on: https://go-review.googlesource.com/c/go/+/300269 Trust: fannie zhang <Fannie.Zhang@arm.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-05testing: add TB.SetenvAlexey Vilenski
Add a new method TB.Setenv that'll set environment variables only for the isolated lifetime of the test, and will clean up and unset these variables when the test ends. This method disables the test or benchmark from running in parallel. Fixes #41260 Change-Id: I0a18f094ec1c6ec3157b4b12993ea3075e2e9867 GitHub-Last-Rev: 0ca12fa565318f350b927e2ef94f3b4f792c75c2 GitHub-Pull-Request: golang/go#41857 Reviewed-on: https://go-review.googlesource.com/c/go/+/260577 Trust: Daniel Martí <mvdan@mvdan.cc> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: roger peppe <rogpeppe@gmail.com>
2021-02-24testing: print late arriving log line in panicJosh Bleecher Snyder
When you log after a test has completed, the testing package panics. Print the logged line as part of that panic, to aid in debugging. Change-Id: I3d6689d1eed57c03e300afe37db0c15b2f4acda4 Reviewed-on: https://go-review.googlesource.com/c/go/+/283972 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-11testing: reduce memory allocation in HelperBryan Boreham
Store the PC instead of the string name of the function, and defer that conversion until we need it. Helper is still relatively expensive in CPU time (few hundred ns), but memory allocation is now constant for a test rather than linear in the number of times Helper is called. benchstat: name old time/op new time/op delta TBHelper-4 1.30µs ±27% 0.53µs ± 1% -59.03% (p=0.008 n=5+5) name old alloc/op new alloc/op delta TBHelper-4 216B ± 0% 0B -100.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta TBHelper-4 2.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5) Change-Id: I6565feb491513815e1058637d086b0374fa94e19 GitHub-Last-Rev: c2329cf225dab6de7309af3583daa011bafb9a62 GitHub-Pull-Request: golang/go#38834 Reviewed-on: https://go-review.googlesource.com/c/go/+/231717 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-09-24testing: send t.signal only if there is no panicChangkun Ou
If a signal is sent to t.signal before the panic is triggered, a panicking test may end up with "warning: no tests to run" because the tRunner that invokes the test in t.Run calls runtime.Goexit on panic, which causes the panicking test not be recorded in runTests. Send the signal if and only if there is no panic. Fixes #41479 Change-Id: I812f1303bfe02c443a1902732e68d21620d6672e Reviewed-on: https://go-review.googlesource.com/c/go/+/256098 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Bryan C. Mills <bcmills@google.com>
2020-09-14testing: fix panicking tests hang if Cleanup calls FailNowChangkun Ou
Previously, it was impossible to call FailNow in a Cleanup. Because it can terminate a panicking goroutine and cause its parent hangs on t.signal channel. This CL sends the signal in a deferred call to prevent the hang. Fixes #41355 Change-Id: I4552d3a7ea763ef86817bf9b50c0e37fb34bf20f Reviewed-on: https://go-review.googlesource.com/c/go/+/254637 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com>
2020-09-05testing: make TempDir idempotent for both Cleanup and BenchmarkChangkun Ou
Ensures that calling TempDir() in either of Cleanup or Benchmark doesn't cause test failures which were previously caused by the created directory having been deleted after the first run, yet we prevented the recreation of the directory due to our selection of concurrency primitive sync.Once. This change recreates the temporary directory if it doesn't exist, regardless of how many times Cleanup and Benchmark are invoked. Fixes #41062 Change-Id: I925d9f7207d7c369a193d1e17da7a59a586244a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/251297 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-02testing: flush test summaries to stdout atomically when streaming outputBryan C. Mills
While debugging #40771, I realized that the chatty printer should only ever print to a single io.Writer (normally os.Stdout). The other Writer implementations in the chain write to local buffers, but if we wrote a test's output to a local buffer, then we did *not* write it to stdout and we should not store it as the most recently logged test. Because the chatty printer should only ever print to one place, it shouldn't receive an io.Writer as an argument — rather, it shouldn't be used at all for destinations other than the main output stream. On the other hand, when we flush the output buffer to stdout in the top-level flushToParent call, it is important that we not allow some other test's output to intrude between the test summary header and the remainder of the test's output. cmd/test2json doesn't know how to parse such an intrusion, and it's confusing to humans too. No test because I couldn't reproduce the user-reported error without modifying the testing package. (This behavior seems to be very sensitive to output size and/or goroutine scheduling.) Fixes #40771 Updates #38458 Change-Id: Ic19bf1d535672b096ba1c8583a3b74aab6d6d766 Reviewed-on: https://go-review.googlesource.com/c/go/+/249026 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-28testing: run a Cleanup registered by a CleanupIan Lance Taylor
Fixes #41085 Change-Id: Ieafc60cbc8e09f1935d38b1767b084d78dae5cb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/251457 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-28testing: restore os.Exit(0) after every call to (*M).RunBryan C. Mills
cmd/go.TestScript/test_main_twice demonstrates a program that invokes (*M).Run twice in a row. If we only restore os.Exit(0) in m.afterOnce, we will fail to restore it after the second run and fail the test process despite both runs passing. Updates #29062 Updates #23129 Change-Id: Id22ec68f1708e4583c8dda14a8ba0efae7178b85 Reviewed-on: https://go-review.googlesource.com/c/go/+/251262 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-27cmd/go, testing, os: fail test that calls os.Exit(0)Ian Lance Taylor
This catches cases where a test calls code that calls os.Exit(0), thereby skipping all subsequent tests. Fixes #29062 Change-Id: If9478972f40189e27623557e7141469ca4234d89 Reviewed-on: https://go-review.googlesource.com/c/go/+/250977 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-08-25testing: fix Cleanup race with Logf and ErrorfMichał Łowicki
Fixes #40908 Change-Id: I25561a3f18e730a50e6fbf85aa7bd85bf1b73b6e Reviewed-on: https://go-review.googlesource.com/c/go/+/250078 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-18testing: treat PAUSE lines as changing the active test nameBryan C. Mills
We could instead fix cmd/test2json to treat PAUSE lines as *not* changing the active test name, but that seems like it would be more confusing to humans, and also wouldn't fix tools that parse output using existing builds of cmd/test2json. Fixes #40657 Change-Id: I937611778f5b1e7dd1d6e9f44424d7e725a589ed Reviewed-on: https://go-review.googlesource.com/c/go/+/248727 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jean de Klerk <deklerk@google.com>
2020-07-30testing: fix quotation marksKatie Hockman
Change-Id: I4b816e26718ef5521afba2b200a6333373b09c58 Reviewed-on: https://go-review.googlesource.com/c/go/+/245136 Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-02testing: capture testname on --- PASS and --- FAIL linesJean de Klerk
This fixes an issue raised at https://github.com/golang/go/issues/38458#issuecomment-635617670 in which --- PASS and --- FAIL lines would not trigger --- CONT lines of other tests. Change-Id: I0d8cc54d682a370d0a6ea6816a11b2e462a92efe Reviewed-on: https://go-review.googlesource.com/c/go/+/235997 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-05-21testing: reformat test chatty outputJean de Klerk
In #24929, we decided to stream chatty test output. It looks like, foo_test.go:138: TestFoo/sub-1: hello from subtest 1 foo_test.go:138: TestFoo/sub-2: hello from subtest 2 In this CL, we refactor the output to be grouped by === CONT lines, preserving the old test-file-before-log-line behavior: === CONT TestFoo/sub-1 foo_test.go:138 hello from subtest 1 === CONT TestFoo/sub-2 foo_test.go:138 hello from subtest 2 This should remove a layer of verbosity from tests, and make it easier to group together related lines. It also returns to a more familiar format (the pre-streaming format), whilst still preserving the streaming feature. Fixes #38458 Change-Id: Iaef94c580d69cdd541b2ef055aa004f50d72d078 Reviewed-on: https://go-review.googlesource.com/c/go/+/229085 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Andrew Bonventre <andybons@golang.org>
2020-05-19testing: clean up remaining TempDir issues from CL 231958Bryan C. Mills
Updates #38850 Change-Id: I33f48762f5520eb0c0a841d8ca1ccdd65ecc20c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/234583 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-19testing: return unique directory inside same base root for TempDirRoger Peppe
We use a single parent directory for all temporary directories created by a test so they're all kept together. Fixes #38850 Change-Id: If8edae10c5136efcbcf6fd632487d198b9e3a868 Reviewed-on: https://go-review.googlesource.com/c/go/+/231958 Reviewed-by: Russ Cox <rsc@golang.org>
2020-05-08testing: tests and benchmarks can assume flag.ParsedDaniel Martí
testing.M.Run has this bit of code: if !flag.Parsed() { flag.Parse() } It makes sense, and it's common knowledge for many Go developers that test flags are automatically parsed by the time tests and benchmarks are run. However, the docs didn't clarify that. The previous wording only mentioned that flag.Parse isn't run before TestMain, which doesn't necessarily mean that it's run afterwards. Fixes #38952. Change-Id: I85f7a9dce637a23c5cb9abc485d47415c1a1ca27 Reviewed-on: https://go-review.googlesource.com/c/go/+/232806 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-05-05testing: fix reported caller name for funcs passed to CleanupMichał Łowicki
Record the caller when Cleanup is called to report it with t.Log instead of unhelpful line in testing.go. Fixes #38800 Change-Id: I3136f5d92a0e5a48f8b32a2e13b2521bc91d72d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/232237 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-25testing: give short package variable a longer nameBrad Fitzpatrick
(Update to CL 229837) Change-Id: Ieab46bd384f76f678ef0d6a38dc043bc4b0c458a Reviewed-on: https://go-review.googlesource.com/c/go/+/230157 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-25testing: replace all GOOS-specific path separators in TempDirTobias Klauser
For GOOS=windows the path separator characters '\' and ':' also need be replaced. Updates #38465 Change-Id: If7c8cf93058c87d7df6cda140e82fd76578fe699 Reviewed-on: https://go-review.googlesource.com/c/go/+/229837 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-23testing: make TempDir work for subtestsAndrei Tudor Călin
ioutil.TempDir doesn't like path separators in its pattern. Modify (*common).TempDir to replace path separators with underscores before using the test name as a pattern for ioutil.TempDir. Fixes #38465. Change-Id: I9e8ae48b99648b2bf9f561762e845165aff01972 Reviewed-on: https://go-review.googlesource.com/c/go/+/229399 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-02testing: add TB.TempDirBrad Fitzpatrick
Fixes #35998 Change-Id: I87c6bf4e34e832be68862ca16ecfa6ea12048d31 Reviewed-on: https://go-review.googlesource.com/c/go/+/226877 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-19testing: fix data race between parallel subtestsChangkun Ou
This CL fixes a race condition if there are two subtests, and one finishing but the other is panicking. Fixes #37551 Change-Id: Ic33963eb338aec228964b95f7c34a0d207b91e00 Reviewed-on: https://go-review.googlesource.com/c/go/+/221322 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-17testing: use "exit code" in documentation consistentlyRodolfo Carvalho
The documentation for m.Run says it returns an "exit code" to pass to os.Exit. The argument to os.Exit is named "code". While "exit code", "exit status" and "exit status code" are all valid ways to refer to the same concept, prefer to stick to one form for consistency and to avoid confusing users. Change-Id: If76ee3fab5cc99c79e05ac1a4e413790a9c93d60 GitHub-Last-Rev: 85a081d2f03c2cf9e8e519916986c59c86aebf57 GitHub-Pull-Request: golang/go#37899 Reviewed-on: https://go-review.googlesource.com/c/go/+/223778 Reviewed-by: Gabriel Aszalos <gabriel.aszalos@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Gabriel Aszalos <gabriel.aszalos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-17testing: do not require os.Exit in TestMainChangkun Ou
If TestMain reports a wrong exit code to os.Exit, the test will be exited with exist code inconsist with test results. This CL eliminates the requirement of calling os.Exit in TestMain. Now, m.Run records the execution status of its test, the outer main func will call os.Exit with that exit code if TestMain does not call os.Exit. If TestMain does not call m.Run, the outer main func remain calls os.Exit(0) as before. Fixes #34129 Change-Id: I9598023e03b0a6260f0217f34df41c231c7d6489 Reviewed-on: https://go-review.googlesource.com/c/go/+/219639 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-24testing: change benchmark example functionMasahiro Furudate
Change to rand.Int, a function that the compiler cannot reliably eliminate. Fix output to actual benchmark values. Fixes #37341 Change-Id: Ifb5bf49b826ae0bdb4bf9de5a472ad0eaa54569c Reviewed-on: https://go-review.googlesource.com/c/go/+/220397 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-21testing: testing: add (*T).Deadline method for test timeoutBryan C. Mills
Fixes #28135 Change-Id: I62818595eaf4a59d8b5c26cd6848c08fec795ad1 Reviewed-on: https://go-review.googlesource.com/c/go/+/202758 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-15testing: remove obsolete comment in testing.(*T) docsIan Lance Taylor
We now only accumulate logs when not using -v. Just drop the sentence entirely rather than try to describe the current situation. Updates #24929 Updates #37203 Change-Id: Ie3bf37894ab68b5b129eff54637893c7a129da03 Reviewed-on: https://go-review.googlesource.com/c/go/+/219540 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-01-18testing: clarify that Cleanup is run after subtests complete.Roger Peppe
It's good to be explicit, as it's not necessarily obvious (and indeed the behavior has changed recently with https://go-review.googlesource.com/c/go/+/214822) without an associated doc comment change). Change-Id: I99d6398bf15b404b1b1b196e712e926e363251e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/215217 Reviewed-by: Paul Jolly <paul@myitcv.org.uk> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-01-16testing: don't run Cleanup functions until parallel subtests completeIan Lance Taylor
Fixes #31651 Change-Id: Idbab0c4355fcc58520e210126795223435cf0078 Reviewed-on: https://go-review.googlesource.com/c/go/+/214822 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-12-10testing: use conventional comments for exported internal funcs & structsvovapi
Change-Id: I2dd5ddc22bfff143b81d5945992d8c5fccf387f4 GitHub-Last-Rev: aa637756e772f5ee9094b802df3be9945c8466c4 GitHub-Pull-Request: golang/go#36054 Reviewed-on: https://go-review.googlesource.com/c/go/+/210497 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-12-05testing: fix testing docstaisa
The Perm function return 0 or 1 or 2 or 3. 4 is not returned, so that changed the argument to 5. Change-Id: Ic980c71a9f29f522bdeef4fce70a6c2dd136d791 Reviewed-on: https://go-review.googlesource.com/c/go/+/209777 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-04testing: implement Cleanup methodRoger Peppe
Fixes #32111 Change-Id: I7078947889d1e126d9679fb28f27b3fa6ce133ef Reviewed-on: https://go-review.googlesource.com/c/go/+/201359 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-30testing: provide additional information when test funcs panicDamien Neil
Flush the output log up to the root when a test panics. Prior to this change, only the current test's output log was flushed to its parent, resulting in no output when a subtest panics. For the following test function: func Test(t *testing.T) { for i, test := range []int{1, 0, 2} { t.Run(fmt.Sprintf("%v/%v", i, test), func(t *testing.T) { _ = 1 / test }) } } Output before this change: panic: runtime error: integer divide by zero [recovered] panic: runtime error: integer divide by zero (stack trace follows) Output after this change: --- FAIL: Test (0.00s) --- FAIL: Test/1/0 (0.00s) panic: runtime error: integer divide by zero [recovered] (stack trace follows) Fixes #32121 Change-Id: Ifee07ccc005f0493a902190a8be734943123b6b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/179599 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-22testing: stream log output in verbose modeJean de Klerk
Fixes #24929 Change-Id: Icc426068cd73b75b78001f55e1e5d81ccebbe854 Reviewed-on: https://go-review.googlesource.com/c/go/+/127120 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-07-22Revert "cmd/go: move automatic testing.Init call into generated test code"Bryan C. Mills
This reverts CL 176098. Reason for revert: added complexity, but did not completely fix the underlying problem. A complete solution would not be worth the complexity, and as a partial solution this is probably not worth the complexity either. Updates #31859 Change-Id: Ifd34c292fd1b811c60afe3c339e5edd3f37190c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/186817 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Caleb Spare <cespare@gmail.com>