aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
AgeCommit message (Collapse)Author
2025-06-20testing, testing/synctest: handle T.Helper in synctest bubblesDamien Neil
Fixes #74199 Change-Id: I6a15fbd59a3a3f8c496440f56d09d695e1504e4e Reviewed-on: https://go-review.googlesource.com/c/go/+/682576 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-06-02testing: add Output method to TBMateusz Poliwczak
Updates #59928 Fixes #73937 Change-Id: Ibf7ec61758edccd245841c3acc9096563b44fcd2 Reviewed-on: https://go-review.googlesource.com/c/go/+/677875 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-05-30testing, testing/synctest: report correct duration after panicsDamien Neil
Report the correct wall-clock test duration after handling a panic in a synctest.Test bubble. Fixes #73852 Change-Id: I053262e5eac2dd9d5938b17c3093cbc3fa115a0d Reviewed-on: https://go-review.googlesource.com/c/go/+/676695 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-29testing, testing/synctest: write bubble errors to parent test logDamien Neil
Ensure that log messages written to the testing.T created by synctest.Test appear in the test output when a test fails. Fixes #73902 Change-Id: Ie97f5efe54eb003e6c0a5394c2def4cac1520ecb Reviewed-on: https://go-review.googlesource.com/c/go/+/676995 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-21testing: add AttrDamien Neil
Add a new Attr method to testing.TB that emits a test attribute. An attribute is an arbitrary key/value pair. Fixes #43936 Change-Id: I7ef299efae41f2cf39f2dc61ad4cdd4c3975cdb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/662437 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-05-20testing/synctest: add TestDamien Neil
Add a synctest.Test function, superseding the experimental synctest.Run function. Promote the testing/synctest package out of experimental status. For #67434 For #73567 Change-Id: I3c5ba030860d90fe2ddb517a2f3536efd60181a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/671961 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-05-15testing: fix panic in t.LogJonathan Amsterdam
If a testing.TB is no longer on the stack, t.Log would panic because its outputWriter is nil. Check for nil and drop the write, which is the previous behavior. Change-Id: Ifde97997a3aa26ae604ac9c218588c1980110cbf Reviewed-on: https://go-review.googlesource.com/c/go/+/673215 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
2025-05-13testing: add Outputsuntala
Output is a method on T, B and F. It provides an io.Writer that writes to the same test output stream as TB.Log. The new output writer is used to refactor the implementation of Log. It maintains the formatting provided by Log while making call site information optional. Additionally, it provides buffering of log messages. This fixes and expands on https://go-review.googlesource.com/c/go/+/646956. For #59928. Change-Id: I08179c35a681f601cf125c0f4aeb648bc10c7a9f GitHub-Last-Rev: e6e202793c9bc471493187e0556a3a1e7305ff82 GitHub-Pull-Request: golang/go#73703 Reviewed-on: https://go-review.googlesource.com/c/go/+/672395 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
2025-05-13Revert "testing: add Output"Jonathan Amsterdam
This reverts commit 8d189f188e225e4919b34c0c097e75dfda255949. Reason for revert: failing test Change-Id: I951087eaef7818697acf87e3206003bcc8a81ee2 Reviewed-on: https://go-review.googlesource.com/c/go/+/672335 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-13testing: add Outputsuntala
Output is a method on T, B and F. It provides an io.Writer that writes to the same test output stream as TB.Log. The new output writer is used to refactor the implementation of Log. It maintains the formatting provided by Log while making call site information optional. Additionally, it provides buffering of log messages. Co-authored-by: Aleks Fazlieva <britishrum@users.noreply.github.com> Fixes #59928. Change-Id: I29090b3d4f61f7334388b373ec18750d5637aafa GitHub-Last-Rev: 18af0e15262494f2074d545a6042b079d62301a2 GitHub-Pull-Request: golang/go#71575 Reviewed-on: https://go-review.googlesource.com/c/go/+/646956 Reviewed-by: Arati <artichaut2023@gmail.com> Auto-Submit: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-12testing: limit TempDir name lengthSean Liao
Fixes #71742 Change-Id: Ibef8f7f0a36b25f181062c4d2f84279a97e467a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/671577 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-04-30testing: use more doc linksSean Liao
Change-Id: Ide372735165b7510fd8d7588451a37fa743e59c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/668915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-03-25testing: document exit codesSean Liao
Fixes #25989 Change-Id: I2e2a2a17854034ff68e69b8973018b1b2e7d59f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/660076 Reviewed-by: Thanyalak Detkhong (Palm’my) <pmy4416@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-24testing: remove redundant variable capture from subtest exampleJake Bailey
Loop variable capturing hasn't been needed like this since Go 1.21; remove it from the example. Change-Id: I231dcfdb57832e32d524f156a605ba36d1c9d6d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/660176 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-03-10testing: warn against calling Log after a test completesSean Liao
Fixes #40343 Change-Id: Id266f4b57131e9e148e5aa2be86b67fe6d73b20a Reviewed-on: https://go-review.googlesource.com/c/go/+/656415 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-14testing: panic in AllocsPerRun if parallel tests are runningRuss Cox
If other tests are running, AllocsPerRun's result will be inherently flaky. Saw this with CL 630136 and #70327. Proposed in #70464. Fixes #70464. Change-Id: I190afdf26bc31299f6e5e8665b4fb420ffd554ee Reviewed-on: https://go-review.googlesource.com/c/go/+/630137 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-05testing: use strings.SplitSeq and bytes.SplitSeqapocelipes
To simplify the code. This is a follow-up for the CL 646216. Change-Id: Ib09d1074a783482fb293527e9f1abeb3c02137c3 GitHub-Last-Rev: 2e7a6ad40cc22ea855e4d703ff39db9cc2c8a58e GitHub-Pull-Request: golang/go#71568 Reviewed-on: https://go-review.googlesource.com/c/go/+/646755 Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Salah (Globlost) <globlost@gmail.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-02-03all: remove coverageredesign experimentIan Lance Taylor
The coverageredesign experiment was turned on by default by CL 436236 in September, 2022. We've documented it and people are using it. This CL removes the ability to turn off the experiment. This removes some old code that is no longer being executed. For #51430 Change-Id: I88d4998c8b5ea98eef8145d7ca6ebd96f64fbc2b Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-darwin-amd64-longtest,gotip-linux-arm64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/644997 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2025-01-21testing: fix reference to B.N in docstringKir Kolyshkin
Currently, a documentation reference to a struct member (such as [B.N]) does not result in it being rendered as a link, and thus the square brackets remain in the rendered documentation which is mildly confusing. The issue can be seen at https://pkg.go.dev/testing@master#hdr-b_N_style_benchmarks Remove the square brackets to fix. Change-Id: Id374fd2085bd511018220c5d663650f89672302e Reviewed-on: https://go-review.googlesource.com/c/go/+/643496 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2024-12-18testing: support B.Context and F.ContextIan Lance Taylor
CL 603959 added T.Context for #36532. The discussion on the proposal only mentions t.Context. However, the implementation of CL 603959 also added B.Context and F.Context. They were added to the API listing, and B.Context was mentioned in the release notes. Unfortunately, the new B.Context and F.Context methods always returned nil, rather than a context.Context value. This change adds a working implementation of B.Context and F.Context. For #36532 Fixes #70866 Change-Id: I8a44e6649fb658e4f641ffb7efd08b4374f578ef Reviewed-on: https://go-review.googlesource.com/c/go/+/637236 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-12-15testing: improve B.Loop docs, use B.Loop in examplesAustin Clements
This updates the testing documentation to frame B.Loop as the canonical way to write benchmarks. We retain documentation on b.N benchmarks because people will definitely continue to see them (and write them), but it's demoted to clearly second class. This also attempts to clarify and refine the B.Loop documentation itself. Updates #61515 Fixes #70787 Change-Id: If5123435bfe3a5883a753119ecdf7bbc41afd499 Reviewed-on: https://go-review.googlesource.com/c/go/+/635895 Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Caleb Spare <cespare@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Austin Clements <austin@google.com>
2024-08-21testing: rename testContext to testStateVladimir Varankin
Following up to CL 603959, update internals of testing package to reduce the confusion around "context". The changes rename testContext/benchContext/fuzzContext to testState/benchState/fuzzState. Change-Id: Ib8855dab456d41ab343488fcf5fefff2431f7b72 Reviewed-on: https://go-review.googlesource.com/c/go/+/607555 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-20testing: add ContextVladimir Varankin
Adds a new Context method to testing.T, that returns a context, that is canceled before the end of its test function. Fixes #36532. Change-Id: I9315ad4dad25529d0b5be809e2d9db4e7528b5f2 GitHub-Last-Rev: 1c3fd6c4d8a9cc68a61f2df284d04d3d080216be GitHub-Pull-Request: golang/go#68828 Reviewed-on: https://go-review.googlesource.com/c/go/+/603959 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-08-16testing: add ChdirKir Kolyshkin
Some tests need to use os.Chdir, but the use is complicated because - they must change back to the old working directory; - they must not use t.Parallel. Add Chdir that covers these cases, and sets PWD environment variable to the new directory for the duration of the test for Unix platforms. Unify the panic message when t.Parallel is used together with t.Setenv or t.Chdir. Add some tests. For #62516. Change-Id: Ib050d173b26eb28a27dba5a206b2d0d877d761c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/529895 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-07-08testing: remove call to os.Exit in documentation for TestMainJulian Dax
In the example for the TestMain function, os.Exit was called explicitly, which is no longer necessary since Go 1.15 (see change #219639). Updates #34129 Change-Id: Ia8021de0d5699742adbb7ab6d28b11c841e596dc Reviewed-on: https://go-review.googlesource.com/c/go/+/596977 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-23all: change from sort functions to slices functions where feasibleIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-05-21runtime/coverage: remove uses of //go:linknameRuss Cox
Move code to internal/coverage/cfile, making it possible to access directly from testing/internal/testdeps, so that we can avoid needing //go:linkname hacks. For #67401. Change-Id: I10b23a9970164afd2165e718ef3b2d9e86783883 Reviewed-on: https://go-review.googlesource.com/c/go/+/585820 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-02testing: improve the documentation around b.NJorropo
Fixes #67137 - Make it clear the benchmark function is called multiple times. - Demonstrate range over int. Change-Id: I7e993d938b0351012cdd4aed8528951e0ad406ae Reviewed-on: https://go-review.googlesource.com/c/go/+/582835 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-04-26testing: use QueryPerformanceCounter on WindowsEgon Elbre
Windows time.Now granularity is around 0.5ms on modern systems, which introduces a significant noise into benchmark results. Instead of relying time.Now use QueryPerformanceCounter, which has significantly better granularity compared to time.Now. │ TimeNow-32 │ HighPrecisionTimeNow-32 │ │ sec/op │ sec/op vs base │ 4.812n ± 0% 30.580n ± 0% +535.43% (p=0.000 n=20) Fixes #31160 Change-Id: Ib2a574d638c9c6762a2524212def02265574e267 Reviewed-on: https://go-review.googlesource.com/c/go/+/557315 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-03-26all: fix a large number of commentscui fliter
Partial typo corrections, following https://go.dev/wiki/Spelling Change-Id: I2357906ff2ea04305c6357418e4e9556e20375d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/573776 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-03-22Revert "testing: add TB.SetGOMAXPROCS function"Ian Lance Taylor
This reverts CL 519235. Reason for revert: Proposal is still in incoming. For #62020 Change-Id: Icccb930209f36097f5d930c01eda6b5042bdddc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/573516 Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-21testing: add TB.SetGOMAXPROCS functionsivchari
Add a new method TB.SetGOMAXPROCS which sets variable of GOMAXPROCS. This method aims to set a variable for the isolated lifetime of the test and cleans up. And unset this when the test ends. This method disables the test or benchmark from running in parallel. Fixes: #62020 Change-Id: Iae44109d0def35cc47049c3ca4cd5306173d52ee Signed-off-by: sivchari <shibuuuu5@gmail.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/519235 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-30testing: remove tests from the running log while they are waiting on ↵Bryan C. Mills
parallel subtests The parallel subtests are themselves removed from the running map while they are blocked on calls to t.Parallel, so it is misleading to log their parents as if they are running when we know they cannot be making any kind of meaningful progress. Fixes #64404. Change-Id: Iaad11d5d4f4c86d775d36e5285c49629dccddd74 Reviewed-on: https://go-review.googlesource.com/c/go/+/546018 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2023-11-27Revert "testing: simplify concurrency and cleanup logic"Lasse Folger
reverts CL 506755 Reason for revert: This leads to deadlocks of tests in Google internal testing For #64402 Change-Id: I78329fc9dcc2377e7e880b264ac1d18d577ef99a Reviewed-on: https://go-review.googlesource.com/c/go/+/544895 Auto-Submit: Bryan Mills <bcmills@google.com> Auto-Submit: Lasse Folger <lassefolger@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-11-21testing: simplify concurrency and cleanup logicBryan C. Mills
While investigating #60083, I found a couple of bugs (notably #61034) that had slipped through code review in part because the concurrency patterns used in the testing package were too complex for me to fully reason about. This change adjusts those patterns to be more in line with current idioms, and to reduce the number of special cases that depend on details that should be orthogonal. (For example: the details of how we invoke the Cleanup functions should not depend on whether the test happened to run any parallel subtests.) In the process, this change fixes a handful of bugs: - Concurrent calls to Run (explicitly allowed by TestParallelSub) could previously drive the testcontext.running count negative, causing the number of running parallel tests to exceed the -parallel flag. - The -failfast flag now takes effect immediately on failure. It no longer delays until the test finishes, and no longer misses failures during cleanup (fixing #61034). - If a Cleanup function calls runtime.Goexit (typically via t.FailNow) during a panic, Cleanup functions from its parent tests are no longer skipped and buffered logs from its parent tests are now flushed. - The time reported for a test with subtests now includes the time spent running those subtests, regardless of whether they are parallel. (Previously, non-parallel subtests were included but parallel subtests were not.) - Calls to (*B).Run in iterations after the first are now diagnosed with a panic. (This diagnoses badly-behaved benchmarks: if Run is called during the first iteration, no subsequent iterations are supposed to occur.) Fixes #61034. Change-Id: I3797f6ef5210a3d2d5d6c2710d3f35c0219b02ea Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-linux-amd64-longtest-race,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/506755 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-08testing: add available godoc linkcui fliter
Change-Id: I8f4d097601796f53176d490cddf8832b7caa4c05 Reviewed-on: https://go-review.googlesource.com/c/go/+/539836 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-06testing: correct comments on runCleanupEvan Jones
The comment on runCleanup states "If catchPanic is true ...", but there is no catchPanic argument or variable. This was introduced in CL 214822, which introduced the panicHandling type. The code was updated during code review, but the comment was missed. Change-Id: Id14c5397e7a026bfdf98ea10ecb1e4c61ce2f924 Reviewed-on: https://go-review.googlesource.com/c/go/+/538695 Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-10-25testing: use monotonic counts to attribute races in subtestsBryan C. Mills
This implements the approach I described in https://go-review.git.corp.google.com/c/go/+/494057/1#message-5c9773bded2f89b4058848cb036b860aa6716de3. Specifically: - Each level of test atomically records the cumulative number of races seen as of the last race-induced test failure. - When a subtest fails, it logs the race error, and then updates its parents' counters so that they will not log the same error. - We check each test or benchmark for races before it starts running each of its subtests or sub-benchmark, before unblocking parallel subtests, and after running any cleanup functions. With this implementation, it should be the case that every test that is running when a race is detected reports that race, and any race reported for a subtest is not redundantly reported for its parent. The regression tests are based on those added in CL 494057 and CL 501895, with a few additions based on my own review of the code. Fixes #60083. Change-Id: I578ae929f192a7a951b31b17ecb560cbbf1ef7a1 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-linux-amd64-longtest-race,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/506300 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-10testing: remove unnecessary TempDir implementation detail from its docVille Skyttä
The "by Cleanup" detail about the removal mechanism is not necessary for users. The previous wording could even cause confusion whether they should do something for Cleanup to occur. Change-Id: I617a7a4e118a70a3ad8a83a2d81cd911dde8ee08 GitHub-Last-Rev: fba4cde6362d1f0ea0c730d50fdd3fbaae4e17cf GitHub-Pull-Request: golang/go#63479 Reviewed-on: https://go-review.googlesource.com/c/go/+/534016 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-13testing: use strings.LastIndexAny in (*common).decorateTobias Klauser
Change-Id: I14c521f4e599e14c71a52342b0ead5d0d4007f1e Reviewed-on: https://go-review.googlesource.com/c/go/+/527655 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-05testing: add doc to not call Init concurrentlygo101
Change-Id: I2e218805fbe4858be125df97bdaf921799315799 GitHub-Last-Rev: 32b798d75f7ec0f72e18a65932ad93d8e5f1040a GitHub-Pull-Request: golang/go#62410 Reviewed-on: https://go-review.googlesource.com/c/go/+/525015 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-05-24Revert "testing: only report subtest races once"Bryan Mills
This reverts CL 494057. Reason for revert: test is failing on -race builders. Fixes #60393. Change-Id: If98238a12673aec597cf69aeead7bdf4782b4524 Reviewed-on: https://go-review.googlesource.com/c/go/+/497996 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-05-24testing: only report subtest races onceIan Lance Taylor
Before this CL the code would record the number of race detector errors seen before starting a test, and then report an error if there were more race detector errors after the test completed. That approach did not work well for subtests or parallel tests. Race detector errors could be reported multiple times at each level of subtest, and parallel tests could accidentally drop race detector errors. Instead, report each race detector error at most once, associated with whatever test noticed the new error. This is still imperfect, as it may report race detector errors for the wrong parallel test. But it shouldn't drop any errors entirely, and it shouldn't report any errors more than once. Fixes #60083 Change-Id: Ic9afea5c692b6553896757766f631cd0e86192ad Reviewed-on: https://go-review.googlesource.com/c/go/+/494057 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-04-25cmd/dist: actually only compile tests with -compile-onlyAustin Clements
Currently, "dist test -compile-only" still runs the test binaries, just with -run=^$ so no tests are run. It does this because, until recently, "go test -c" would fail if passed multiple test packages. But this has some unexpected consequences: init code still runs, TestMain still runs, and we generally can't test cross-compiling of tests. Now that #15513 is fixed, we can pass multiple packages to "go test -c". Hence, this CL make dist just use "go test -c" as one would expect. Found in the course of working on #37486, though it doesn't really affect that. Change-Id: If7d3c72c9e0f74d4ea0dd422411e5ee93b314be4 Reviewed-on: https://go-review.googlesource.com/c/go/+/488275 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Austin Clements <austin@google.com>
2023-03-13testing: add Testing functionIan Lance Taylor
The Testing function reports whether the program is a test created by "go test". Fixes #52600 Change-Id: Ie0fff7c7dfdfdf997c18b4b6112632600b327cc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/475496 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-02-22testing: add -fullpath to go testHossein Zolfi
When -test.fullpath flag is provided to go test, go test displays the full file names in error messages. Fixes #37708 Change-Id: I6096e75ed816fd42205810f20624e495047a73a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/463837 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2022-12-23testing: rephrase the sentence about naming test filesAndrey Bozhko
This updates the explanation about naming test files to be a little more clear. Fixes #57389 Change-Id: I9b3a8e2dae5e3ad398b55624e183809b7d90864c GitHub-Last-Rev: 9ff81b74b201ca032fd373424aa02a3fedaec008 GitHub-Pull-Request: golang/go#57399 Reviewed-on: https://go-review.googlesource.com/c/go/+/458435 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Fahad King <fahadking750@gmail.com> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>
2022-11-16testing: in TestRacyOutput, ensure that the Run calls complete before cleanupBryan C. Mills
Also tweak the failure message added in CL 352349. Updates #18741. Updates #48515. Change-Id: I46ed84c6f498d7a68414cc3dab3c1cd55da69aa9 Reviewed-on: https://go-review.googlesource.com/c/go/+/451215 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Changkun Ou <mail@changkun.de> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-16testing: reject calls to Run within Cleanup callbacksChangkun Ou
Calling t.Run inside t.Cleanup can mess up the execution order of registered Cleanup callbacks. Reject calls to Run within Cleanup callbacks. Fixes #48515 Change-Id: I61e4cb35253db1a8bbe3351d59055433030aa289 Reviewed-on: https://go-review.googlesource.com/c/go/+/352349 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org> Run-TryBot: Changkun Ou <mail@changkun.de> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-14testing: fix error message when a parallel Cleanup calls runtime.GoexitChangkun Ou
Fixes #48502 Change-Id: I6054b043ebd2237e19897fdf1234b311d19facc7 Reviewed-on: https://go-review.googlesource.com/c/go/+/352350 Reviewed-by: Joedian Reid <joedian@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Changkun Ou <mail@changkun.de> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>