summaryrefslogtreecommitdiff
path: root/src/testing
Commit message (Collapse)AuthorAgeFilesLines
* log/slog: built-in handler constructors take options as a second argJonathan Amsterdam2023-05-041-1/+1
| | | | | | | | | | | | | | | There is now one constructor function for each built-in handler, with signature NewXXXHandler(io.Writer, *HandlerOptions) *XXXHandler Fixes #59339. Change-Id: Ia02183c5ce0dc15c64e33ad05fd69bca09df2d2d Reviewed-on: https://go-review.googlesource.com/c/go/+/486415 Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com>
* all: add String for fs.{FileInfo,DirEntry} implementationsIan Lance Taylor2023-05-041-0/+4
| | | | | | | | | | | | | | | | | The new String methods use the new FormatFileInfo and FormatDirEntry functions. Fixes #54451 Change-Id: I414cdfc212ec3c316fb2734756d2117842a23631 Reviewed-on: https://go-review.googlesource.com/c/go/+/491175 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* cmd/dist: actually only compile tests with -compile-onlyAustin Clements2023-04-251-1/+0
| | | | | | | | | | | | | | | | | | | | | | | 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>
* testing/slogtest: tests for slog handlersJonathan Amsterdam2023-04-242-0/+352
| | | | | | | | | | | | | | | Add a package for testing that a slog.Handler implementation satisfies that interface's documented requirements. Code copied from x/exp/slog/slogtest. Updates #56345. Change-Id: I89e94d93bfbe58e3c524758f7ac3c3fba2a2ea96 Reviewed-on: https://go-review.googlesource.com/c/go/+/487895 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
* std: fix various nilness findingsAlan Donovan2023-04-201-2/+1
| | | | | | | | | | | | | | | Found by running $ go run golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest std No actual bugs--other than one panic(nil)--but a few places where error nilness was unclear. Change-Id: Ia916ba30f46f29c1bcf928cc62280169b922463a Reviewed-on: https://go-review.googlesource.com/c/go/+/486675 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Alan Donovan <adonovan@google.com>
* all: add wasip1 supportJohan Brandhorst-Satzkorn2023-04-112-2/+2
| | | | | | | | | | | | | | | | | Fixes #58141 Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I49b66946acc90fdf09ed9223096bfec9a1e5b923 Reviewed-on: https://go-review.googlesource.com/c/go/+/479627 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
* database/sql,testing/quick: use reflect.Value.SetZeroDaniel Martí2023-04-041-1/+1
| | | | | | | | | | Change-Id: I2893a6aa8c2715f69745f424262c20c21370b05f Reviewed-on: https://go-review.googlesource.com/c/go/+/481355 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
* testing: quote -test.v=test2json output when logging itBryan C. Mills2023-03-231-1/+4
| | | | | | | | | | | | | | | | | | | | | | | The -test.v=test2json flag causes the testing package to inject extra control characters in the output to allow the JSON parser to more gracefully handle extraneous writes to os.Stdout and/or os.Stderr in the package under test (see CL 443596). However, it doesn't filter out those control characters because almost no real-world tests will output them. It turns out that testing.TestFlag is one of the rare tests that does output those control characters, because it tests the -test.v=test2json flag itself. Fixes #59181. Change-Id: I35ca6748afcd3d4333563028817caac946f5e86a Reviewed-on: https://go-review.googlesource.com/c/go/+/479035 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
* testing: add Testing functionIan Lance Taylor2023-03-132-0/+77
| | | | | | | | | | | | | | | 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>
* testing: add -fullpath to go testHossein Zolfi2023-02-221-2/+5
| | | | | | | | | | | | | | | 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>
* all: fix typos in go file commentsMarcel Meyer2023-01-091-1/+1
| | | | | | | | | | | | | | | | | | These typos were found by executing grep, aspell, sort, and uniq in a pipe and searching the resulting list manually for possible typos. grep -r --include '*.go' -E '^// .*$' . | aspell list | sort | uniq Change-Id: I56281eda3b178968fbf104de1f71316c1feac64f GitHub-Last-Rev: e91c7cee340fadfa32b0c1773e4e5cd1ca567638 GitHub-Pull-Request: golang/go#57669 Reviewed-on: https://go-review.googlesource.com/c/go/+/460767 Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
* testing: rephrase the sentence about naming test filesAndrey Bozhko2022-12-231-2/+3
| | | | | | | | | | | | | | | | | | | 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>
* testing: in TestRacyOutput, ensure that the Run calls complete before cleanupBryan C. Mills2022-11-163-4/+4
| | | | | | | | | | | | | | | 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>
* testing: reject calls to Run within Cleanup callbacksChangkun Ou2022-11-162-6/+31
| | | | | | | | | | | | | | | | 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>
* testing: fix error message when a parallel Cleanup calls runtime.GoexitChangkun Ou2022-11-142-2/+44
| | | | | | | | | | | | 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>
* testing: Document RunParallel ns/op behaviorFelix Geisendörfer2022-11-071-0/+3
| | | | | | | | | | | | Updates #31884 Change-Id: Ibad3d31038a8426c0bce61c1726392880f934865 Reviewed-on: https://go-review.googlesource.com/c/go/+/447136 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: add Get method for -test.v optionIan Lance Taylor2022-11-032-0/+93
| | | | | | | | | | | | | | | There is existing code that calls flag.Lookup("test.v") and inspects the value. That stopped working as of CL 443596. Make code like that continue to work at least for the case where we aren't using -test.v=test2json. Change-Id: Idb30b149b48ee3987a201e349cf4d9bfe9ddee56 Reviewed-on: https://go-review.googlesource.com/c/go/+/447796 Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* testing: implement -cpu and -count for fuzz testsRuss Cox2022-11-021-42/+60
| | | | | | | | | | | | | Fuzz tests are meant to be run just like ordinary tests, so copy the same loop cpu and count loops used in testing.go (and benchmark.go) into fuzz.go. Change-Id: Ic585df8ccc577869c877b1055e0493803dbeb828 Reviewed-on: https://go-review.googlesource.com/c/go/+/443377 Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
* testing: print names of running tests on test timeoutRuss Cox2022-11-011-4/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Track the running tests and when they started, so that we can report the running tests on a test timeout. % go test -timeout=5s panic: test timed out after 5s running tests: TestTCPSpuriousConnSetupCompletion (4s) ... stack traces as usual ... % go test -run=Script -timeout=10s cmd/go vcs-test.golang.org rerouted to http://127.0.0.1:65168 https://vcs-test.golang.org rerouted to https://127.0.0.1:65169 go test proxy running at GOPROXY=http://127.0.0.1:65170/mod panic: test timed out after 10s running tests: TestScript (10s) TestScript/mod_get_patchcycle (0s) TestScript/mod_get_prefer_incompatible (0s) TestScript/mod_get_promote_implicit (0s) TestScript/mod_get_pseudo (0s) TestScript/mod_get_pseudo_other_branch (0s) TestScript/mod_get_pseudo_prefix (0s) TestScript/mod_get_test (0s) TestScript/mod_get_trailing_slash (0s) TestScript/mod_get_update_unrelated_sum (0s) TestScript/mod_gobuild_import (0s) TestScript/mod_gomodcache (0s) TestScript/mod_gonoproxy (0s) TestScript/mod_load_badchain (0s) TestScript/mod_overlay (0s) TestScript/test_fuzz_minimize (6s) TestScript/test_fuzz_minimize_dirty_cov (7s) ... stack traces as usual ... Change-Id: I3a6647c029097becc06664ebd76a2597c7ed7b8e Reviewed-on: https://go-review.googlesource.com/c/go/+/446176 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
* testing: change Error to Errorf in commentIan Lance Taylor2022-10-281-1/+1
| | | | | | | | | | | | | Fixes #56479 Change-Id: I1d97eb3ea97304e429e178ad05cb9f861b2bce84 Reviewed-on: https://go-review.googlesource.com/c/go/+/446275 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
* testing: fix many test2json inaccuraciesRuss Cox2022-10-267-44/+189
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Test2json is parsing the output stream from the test, which includes package testing's own framing lines intermingled with other output, in particular any output printed via fmt.Printf, println, and so on. We have had recurring problems with unexpected partial output lines causing a framing line to be missed. A recent talk at GopherCon gave an example of an integration test involving Docker that happened to print \r-terminated lines instead of \n-terminated lines in some configurations, which in turn broke test2json badly. (https://www.gophercon.com/agenda/session/944259) There are also a variety of open reported issues with similar problems, which this CL also addresses. The general approach is to add a new testing flag -test.v=json that means to print additional output to help test2json. And then test2json takes advantage of that output. Among the fixes: - Identify testing framing more reliably, using ^V (#23036, #26325, #43683, GopherCon talk) - Test that output with \r\n endings is handled correctly (#43683, #34286) - Use === RUN in fuzz tests (#52636, #48132) - Add === RUN lines to note benchmark starts (#27764, #49505) - Print subtest --- PASS/FAIL lines as they happen (#29811) - Add === NAME lines to emit more test change events, such as when a subtest stops and the parent continues running. - Fix event shown in overall test failure (#27568) - Avoid interleaving of writes to os.Stdout and os.Stderr (#33419) Fixes #23036. Fixes #26325. Fixes #27568. Fixes #27764. Fixes #29811. Fixes #33419. Fixes #34286. Fixes #43683. Fixes #49505. Fixes #52636. Change-Id: Id4207b746a20693f92e52d68c6e4a7f8c41cc7c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/443596 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: add an example showcasing B.RunParallel with B.ReportMetricEddie Lopez2022-10-071-0/+30
| | | | | | | | | | | | | | | | | | This commit was dedicated to adding an example of using B.ReportMetrics with B.RunParallel called ExampleB_ReportMetric_parallel. In this example, the same algorithm for ExampleB_ReportMetric was used, instead with a concurrent for loop using PB.Next instead of a standard one. There is also notes noting when to use the B.ReportMetric methods when running concurrent testing. Fixes #50756 Change-Id: I2a621b4e367af5f4ec47d38a0da1035a8d52f628 Reviewed-on: https://go-review.googlesource.com/c/go/+/437815 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
* testing: update description of SetenvNobuki Fujii2022-09-291-2/+4
| | | | | | | | | | | | | | | Add the description of Setenv that it cannot use if the test have parallel ancestors. Fixes #55128 Change-Id: Ia5a1deaa1a3116d1ebb439600a7d316c7d155412 Reviewed-on: https://go-review.googlesource.com/c/go/+/434115 Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* runtime/coverage: improve unit testsThan McIntosh2022-09-291-0/+7
| | | | | | | | | Add a testpoint to cover support routines used to help implement "go test -cover". Change-Id: Ic28bf884a4e0d2c0a6d8fd04fc29c0c949227f21 Reviewed-on: https://go-review.googlesource.com/c/go/+/432315 Reviewed-by: Bryan Mills <bcmills@google.com>
* testing: fail if T.Setenv is called via T.Run in a parallel testNobuki Fujii2022-09-282-4/+48
| | | | | | | | | | | | | | | The existing implementation can call to T.Setenv in T.Run even after calling to T.Parallel, so I changed it to cause a panic in that case. Fixes #55128 Change-Id: Ib89d998ff56f00f96a5ca218af071bd35fdae53a Reviewed-on: https://go-review.googlesource.com/c/go/+/431101 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
* cmd/go: support new hybrid coverage instrumentationThan McIntosh2022-09-283-2/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If GOEXPERIMENT=coverageredesign is in effect, introduce a new top-level '-cover' option to "go build" to turn on new-style hybrid code coverage instrumentation. Similarly, use the new instrumentation for "go test -cover". The main effects of "-cover" under the hood are to instrument files at the package level using cmd/cover and to pass additional options to the compiler when building instrumented packages. The previous workflow for "go tool -cover mypkg" would expand to a series of "go tool cover" commands (one per file) followed by a single package compilation command to build the rewritten sources. With the new workflow, the Go command will pass all of the Go files in a package to the cover tool as a chunk (along with a config file containing other parameters), then the cover tool will write instrumented versions of the sources along with another "output" config with info on coverage variable names for the the compiler. The Go command will then kick off the compiler on the modified source files, also passing in the config file generated by cmd/cover. Updates #51430. Change-Id: Id65621ff6a8c70a30168c1412c2d6f805ff3b9e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/355452 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* testing: allow go test -run=^$ testingRuss Cox2022-09-161-1/+2
| | | | | | | | | | | This should fix the ssacheck builder. Change-Id: I4b6172df33d6447f7ec8fd8e301c6380efb92588 Reviewed-on: https://go-review.googlesource.com/c/go/+/431336 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* cmd/go, testing: add go test -skip flagRuss Cox2022-09-167-59/+123
| | | | | | | | | | | | | For proposal #41583, add a new 'go test -skip' flag to make it easy to disable specific tests, benchmarks, examples, or fuzz targets. Fixes #41583. Change-Id: Id12a6575f505dafdce4a149aedc454a002e93afa Reviewed-on: https://go-review.googlesource.com/c/go/+/421439 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
* testing: use strings.Buildercuiweixie2022-09-076-17/+17
| | | | | | | | | Change-Id: Ied8a3019f1e21c0e74c798d2b1b279a606a38554 Reviewed-on: https://go-review.googlesource.com/c/go/+/428279 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
* testing: increment tempDirSeq non-atomicallycuiweixie2022-08-301-1/+6
| | | | | | | | | | | | | It's unnecessary to to call atomic.AddInt32 since there is a mutex lock. Change-Id: I31fcece17c34f99a95772d744aebd3f6a8cf1d23 Reviewed-on: https://go-review.googlesource.com/c/go/+/426081 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
* testing: convert common.hasSub to atomic typecuiweixie2022-08-292-6/+6
| | | | | | | | | | Change-Id: I3d8a9b901efabe62f432c06361826f46c78d2605 Reviewed-on: https://go-review.googlesource.com/c/go/+/426080 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: explain using a _test packagebyarbrough2022-08-291-4/+32
| | | | | | | | | | | | | | | | | | | | | The existing documentation did not explain the difference between placing a _test.go file in the same package as what is being tested vs. adding it to a separate _test package. This explains the distinction and adds an example. Concept is explained well here: https://stackoverflow.com/a/31443271 Fixes #25223 Change-Id: Iebaba15207d8aa24f0b370d8dd4062eadb504b5c GitHub-Last-Rev: 7f49c5f4624b358af8052272da8ac3240751ada0 GitHub-Pull-Request: golang/go#54160 Reviewed-on: https://go-review.googlesource.com/c/go/+/420415 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
* testing: convert numFailed to atomic typecuiweixie2022-08-292-5/+4
| | | | | | | | | | Change-Id: Ic3464e95ad8901df5477d7717760b8c6d08ce97b Reviewed-on: https://go-review.googlesource.com/c/go/+/426078 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
* testing: add Elapsed method to testing.Bhopehook2022-08-252-0/+14
| | | | | | | | | | | | | | | | Elapsed returns the measured elapsed time of the benchmark, but does not change the running state of the timer. Fixes #43620. Change-Id: Idd9f64c4632518eec759d2ffccbf0050d84fcc03 Reviewed-on: https://go-review.googlesource.com/c/go/+/420254 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: hopehook <hopehook@qq.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* testing: do not print 'root' benchName during test of package testingRuss Cox2022-08-162-1/+12
| | | | | | | | | | | | | | | | | | | | | | $ cd $GOROOT/src/testing $ go test root root root root PASS $ The root prints have been happening since Go 1.14. There is a test in sub_test.go that calls b.Run directly with a benchmark named "root", which triggers the print. Silence them. Change-Id: I2f0c186f04c6139bc24fab0e91975fcf0a8e80fc Reviewed-on: https://go-review.googlesource.com/c/go/+/421437 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: use io.Seek* instead of deprecated os.SEEK_*Tobias Klauser2022-08-081-1/+1
| | | | | | | | | | | | | | | These are available since Go 1.7. The version used for bootstrap is Go 1.17 for Go 1.20. For #44505 Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2 Reviewed-on: https://go-review.googlesource.com/c/go/+/421634 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
* cmd/compile: mark closures made for generic function expressions as wrappersKeith Randall2022-05-262-10/+22
| | | | | | | | | | | Fixes #52237 Change-Id: I7488020c8d157e069202017a293d18230e3aef0d Reviewed-on: https://go-review.googlesource.com/c/go/+/408876 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
* Revert "testing: document -race goroutine limits"Keith Randall2022-05-111-3/+0
| | | | | | | | | | | | | | | | | This reverts commit 4907c62f99fbfc8608a79a17c20d89f50956d9fc. Reason for revert: Race detector v3, which we just upgraded to, no longer has a goroutine limit. (small caveat: openbsd/amd64 can't be updated, windows/amd64 isn't updated yet but should be by release time.) Change-Id: I90017834501e81d3990d888f1b2baf3432452846 Reviewed-on: https://go-review.googlesource.com/c/go/+/405595 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* all: fix some lint issuesRyan Leung2022-05-081-1/+1
| | | | | | | | | | | | | | | Make some code more simple. Change-Id: I801adf0dba5f6c515681345c732dbb907f945419 GitHub-Last-Rev: a505146baca00a1b3268d11d10510afa8cea6f1d GitHub-Pull-Request: golang/go#49626 Reviewed-on: https://go-review.googlesource.com/c/go/+/364634 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
* all: gofmt main repoRuss Cox2022-04-113-141/+151
| | | | | | | | | | | | | | | [This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: consistently use US spelling of present participlesDaniel Martí2022-04-081-1/+1
| | | | | | | | | | | | | | | | | | It has been agreed that we should prefer the US spelling of words like "canceling" over "cancelling"; for example, see https://go.dev/cl/14526. Fix a few occurrences of the "canceling" inconsistency, as well as: * signaling * tunneling * marshaling Change-Id: I99f3ba0a700a9f0292bc6c1b110af31dd05f1ff0 Reviewed-on: https://go-review.googlesource.com/c/go/+/398734 Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: remove trailing blank doc comment linesRuss Cox2022-04-011-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: include ERROR_SHARING_VIOLATION in Windows cleanup retriesBryan C. Mills2022-03-033-8/+22
| | | | | | | | | | | | Fixes #51442 Updates #50051 Change-Id: I1bfbc08c907077467fd50febbec6299a9b73af41 Reviewed-on: https://go-review.googlesource.com/c/go/+/388916 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: panic in Fuzz if the function returns a valueBryan C. Mills2022-02-161-0/+3
| | | | | | | | | | | | | | | | | | | Otherwise, the behavior of a fuzz target that returns an error could be confusing. Fuzz is already documented to require a function “with no return value”, so this fixes the implementation to match the existing documentation. Fixes #51222 Change-Id: I44ca7ee10960214c92f5ac066ac8484c8bb9cd6f Reviewed-on: https://go-review.googlesource.com/c/go/+/386175 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Nooras Saba‎ <saba@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: remove TODO and link to fuzz docsKatie Hockman2022-02-041-2/+1
| | | | | | | | | Change-Id: I3f5ee9629b0b0f3f29a021a656dbf3bca27e582d Reviewed-on: https://go-review.googlesource.com/c/go/+/383415 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: only snapshot coverage during fuzzingRoland Shoemaker2022-01-101-2/+4
| | | | | | | | | | | | | | | | Only snapshot/reset coverage counters when we are actually fuzzing. This prevents a race when running corpus/seed values during the testing phase. Fixes #50488 Change-Id: I7dd5a0353a296c0b13eede29ad9af7c78814fa2d Reviewed-on: https://go-review.googlesource.com/c/go/+/376554 Trust: Katie Hockman <katie@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* testing: fix deadlock with t.Parallel in testing seed corpusKatie Hockman2022-01-061-4/+5
| | | | | | | | | | | | | | | | | | | The c.startParallel channel on the testContext is stuck in t.Parallel() because c.running starts at 1 for the main fuzz parent test, and is causing a deadlock because it is never released. It would normally be released by tRunner, but needs to instead be released by fRunner instead for fuzz tests. Fixes #50217 Change-Id: I2d010e9adddfd8e8321ff2f9dd2e43daf46c128f Reviewed-on: https://go-review.googlesource.com/c/go/+/374054 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: fix spelling errors found by misspellDan Kortschak2021-12-201-1/+1
| | | | | | | | | Change-Id: Icedd0c3d49259d5aee249ecb33374e9b78e0c275 Reviewed-on: https://go-review.googlesource.com/c/go/+/373376 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: fix typo in commentichxxx2021-12-151-1/+1
| | | | | | | | | | | | Remove duplicate 'the' Change-Id: I3ed81c8d9c488662387e45580a3bcd462448ba44 GitHub-Last-Rev: 86443993b9b58c6fce4e09e283604c32ccc44cec GitHub-Pull-Request: golang/go#50017 Reviewed-on: https://go-review.googlesource.com/c/go/+/372394 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: retry spurious errors from RemoveAll for temp directoriesBryan C. Mills2021-12-143-1/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This works around what appears to be either a kernel bug or a Go runtime or syscall bug affecting certain Windows versions (possibly all pre-2016?). The retry loop is a simplified version of the one used in cmd/go/internal/robustio. We use the same 2-second arbitrary timeout as was used in that package, since it seems to be reliable in practice on the affected builders. (If it proves to be too short, we can lengthen it, within reason, in a followup CL.) Since this puts a higher-level workaround in place, we can also revert the lower-level workaround added to a specific test in CL 345670. This addresses the specific occurrences of the bug for users of (*testing.T).TempDir, but does not fix the underlying bug for Go users outside the "testing" package (which remains open as #25965). Fixes #50051 Updates #48012 Updates #25965 Change-Id: I35be7125f32f05c8350787f5ca9a22974b8d0770 Reviewed-on: https://go-review.googlesource.com/c/go/+/371296 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Patrik Nyblom <pnyb@google.com> Trust: Patrik Nyblom <pnyb@google.com> Run-TryBot: Patrik Nyblom <pnyb@google.com>