aboutsummaryrefslogtreecommitdiff
path: root/src/testing
AgeCommit message (Collapse)Author
2021-03-24[release-branch.go1.16] testing: update helperNames just before checking itTao Qingyun
parent's helperNames has not been set when frameSkip called, moving helperNames initilazing to frameSkip. For #44887 Fixes #44888 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> (cherry picked from commit 67048432026062a98a3937a865aeb05a398148c5) Reviewed-on: https://go-review.googlesource.com/c/go/+/303189 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-02-05testing/fstest: avoid symlink-induced failures in testerRuss Cox
Do not require directory entry and Stat result to match for symlinks, because they won't (Stat dereferences the symlink). Fixes #44113. Change-Id: Ifc6dbce5719906e2f42254a7172f1ef787464a9e Reviewed-on: https://go-review.googlesource.com/c/go/+/290009 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-08testing/fstest,os: clarify racy behavior of TestFSAustin Clements
The testing.TestFS function assumes that the file system it's testing doesn't change under it. Clarify this in the documentation and fix the use of os.TestDirFS that's currently susceptible to this race. Fixes #42637. Change-Id: Ia7792380726177f8953d150ee87381b66cb01cb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/282452 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-01-04testing/fstest: fix typo in error messageDrGo
Change-Id: Iac59f5271c79c46b39733fdf0eb4bf9b0fc0bdca GitHub-Last-Rev: 03f96e32a81d1516a9307b6578c930434783e3d3 GitHub-Pull-Request: golang/go#43450 Reviewed-on: https://go-review.googlesource.com/c/go/+/280953 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-09all: update to use os.ReadDir where appropriateRuss Cox
os.ReadDir is a replacement for ioutil.ReadDir that returns a slice of fs.DirEntry instead of fs.FileInfo, meaning it is the more efficient form. This CL updates call sites throughout the Go source tree wherever possible. As usual, code built using the Go 1.4 bootstrap toolchain is not included. There is also a use in go/build that appears in the public API and can't be changed, at least not without additional changes. Fixes #42026. Change-Id: Icfc9dd52c6045020f6830e22c72128499462d561 Reviewed-on: https://go-review.googlesource.com/c/go/+/266366 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-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-12-04io/fs: add SubRuss Cox
Sub provides a convenient way to refer to a subdirectory automatically in future operations, like Unix's chdir(2). The CL also includes updates to fstest to check Sub implementations. As part of updating fstest, I changed the meaning of TestFS's expected list to introduce a special case: if you list no expected files, that means the FS must be empty. In general it's OK not to list all the expected files, but if you list none, that's almost certainly a mistake - if your FS were broken and empty, you wouldn't find out. Making no expected files mean "must be empty" makes the mistake less likely - if your file system ever worked, then your test will keep it working. That change found a testing bug: embedtest was making exactly that mistake. Fixes #42322. Change-Id: I63fd4aa866b30061a0e51ca9a1927e576d6ec41e Reviewed-on: https://go-review.googlesource.com/c/go/+/274856 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-11-07testing: increase benchmark output to four significant figuresAustin Clements
Currently, the benchmark output from the testing package prints small values with three significant figures. This means it can only distinguish 1 part in 100, or a 1% error, which can be enough to throw off further analysis of the output. This CL increases it to four significant figures. For time values, at least, anything beyond four significant figures is almost certainly noise. Fixes #34626. Change-Id: I3bcf305427130026276e6a4c78167989319f280c Reviewed-on: https://go-review.googlesource.com/c/go/+/267102 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
2020-10-23io/fs, path, path/filepath, testing/fstest: validate patterns in Match, GlobRuss Cox
According to #28614, proposal review agreed in December 2018 that Match should return an error for failed matches where the unmatched part of the pattern has a syntax error. (The failed match has to date caused the scan of the pattern to stop early.) This change implements that behavior: the match loop continues scanning to the end of the pattern, even after a confirmed mismatch, to check whether the pattern is even well-formed. The change applies to both path.Match and filepath.Match. Then filepath.Glob and fs.Glob make a single validity-checking call to Match before beginning their usual processing. Also update fstest.TestFS to check for correct validation in custom Glob implementations. Fixes #28614. Change-Id: Ic1d35a4bb9c3565184ae83dbefc425c5c96318e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/264397 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20testing: print cpu type as label for benchmarksMartin Möhrmann
Supports 386 and amd64 architectures on all operating systems. Example output: $ go test -bench=.* goos: darwin goarch: amd64 pkg: strconv cpu: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz BenchmarkAtof64Decimal-4 24431032 46.8 ns/op ... As the displayed CPU information is only used for information purposes it is lazily initialized when needed using the new internal/sysinfo package. This allows internal/cpu to stay without dependencies and avoid initialization costs when the CPU information is not needed as the new code to query the CPU name in internal/cpu can be dead code eliminated if not used. Fixes #39214 Change-Id: I77ae5c5d2fed6b28fa78dd45075f9f0a6a7f1bfd Reviewed-on: https://go-review.googlesource.com/c/go/+/263804 Trust: Martin Möhrmann <moehrmann@google.com> Reviewed-by: Keith Randall <khr@golang.org>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-20io/fs: add Glob and GlobFSRuss Cox
Add Glob helper function, GlobFS interface, and test. Add Glob method to fstest.MapFS. Add testing of Glob method to fstest.TestFS. For #41190. Change-Id: If89dd7f63e310ba5ca2651340267a9ff39fcc0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/243915 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add ReadDir and ReadDirFSRuss Cox
Add ReadDir helper function, ReadDirFS interface, and test. Add ReadDir method to fstest.MapFS. Add testing of ReadDir method to fstest.TestFS. For #41190. Change-Id: Ib860770ec7433ba77b29e626682b238f1b3bf54f Reviewed-on: https://go-review.googlesource.com/c/go/+/243914 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add Stat and StatFSRuss Cox
Add Stat helper function, StatFS interface, and test. Add Stat method to fstest.MapFS. Add testing of Stat method to fstest.TestFS. For #41190. Change-Id: Icf8b6eb1c3fa6f93a9be8405ec5a9468fb1da97b Reviewed-on: https://go-review.googlesource.com/c/go/+/243913 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add ReadFile and ReadFileFSRuss Cox
Add ReadFile helper function, ReadFileFS interface, and test. Add ReadFile method to fstest.MapFS. Add testing of ReadFile method to fstest.TestFS. For #41190. Change-Id: I5b6a41e2e582824e570463b698b635abaa436c32 Reviewed-on: https://go-review.googlesource.com/c/go/+/243912 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20testing/fstest: new package for testing file system codeRuss Cox
This change adds basic test helpers for file system code. The type MapFS is a simple map-based file system for use when exercising general file system code. The func TestFS tests a file system implementation. For #41190. Change-Id: I5a2036f57e733915ad508651ad7317749794423c Reviewed-on: https://go-review.googlesource.com/c/go/+/243910 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20testing/iotest: add TestReader to test readersRuss Cox
There are many reader behaviors that are subtle and worth testing, and it's nice to have one complete tester instead of many incomplete ones. For #41190, which will use this as part of a larger file system implementation tester. Change-Id: Ib4cc7fae94b0d9b45dfacadc52baa77ad3761322 Reviewed-on: https://go-review.googlesource.com/c/go/+/243909 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-09-28testing: add benchmark for TB.HelperEmmanuel T Odeke
Adds a benchmark for TB.Helper, to use as a judge of future improvements like CL 231717. Change-Id: I17c40d482fc12caa3eb2c1cda39fd8c42356b422 Reviewed-on: https://go-review.googlesource.com/c/go/+/257317 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Trust: Tobias Klauser <tobias.klauser@gmail.com> Trust: Emmanuel Odeke <emm.odeke@gmail.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-09-01testing: fail Example tests that invoke runtime.GoexitChangkun Ou
Previously, if an example test invoked runtime.Goexit, it would pass yet hang until a timeout, while regular tests that invoke runtime.Goexit do fail. This change removes that inconsistent behavior and makes such example tests fail, and panic with an indication of having invoked runtime.Goexit. Fixes #41084 Change-Id: I0ffa152204f2b1580f4d5d6961ba1ce6b13fc022 Reviewed-on: https://go-review.googlesource.com/c/go/+/251857 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@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-08-18testing/iotest: correct ErrReader signature and remove exported errorEmmanuel T Odeke
Corrects ErrReader's signature to what was accepted in the approved proposal, and also removes an exported ErrIO which wasn't part of the proposal and is unnecessary. The new signature allows users to customize their own errors. While here, started examples, with ErrReader leading the way. Updates #38781 Change-Id: Ia7f84721f11061343cfef8b1adc2b7b69bc3f43c Reviewed-on: https://go-review.googlesource.com/c/go/+/248898 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-17testing/iotest: add ErrReaderCarlos Alexandro Becker
Adds an io.Reader that always returns 0 and a non-nil error. Fixes #38781 Change-Id: I56bd124de07bc8809e77c6cfaab33a1e32cfe2ee GitHub-Last-Rev: 4e232b17e9120405d4ea4743350ee361a3505043 GitHub-Pull-Request: golang/go#34741 Reviewed-on: https://go-review.googlesource.com/c/go/+/199501 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.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-02-06testing: make Cleanup work for benchmarks too.Roger Peppe
Fixes #37073. Change-Id: I6fb24a3f9d7b7adf3213ac6a8bcbf5fb43975b7e Reviewed-on: https://go-review.googlesource.com/c/go/+/218117 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@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>