summaryrefslogtreecommitdiff
path: root/src/testing
Commit message (Collapse)AuthorAgeFilesLines
* testing: comment out flag.Parse from exampleDaniel Martí2016-11-251-1/+1
| | | | | | | | | | | | | | | | | | The TestMain docs explain that flag.Parse() should be called if TestMain itself depends on command-line flags. The issue here is that the example implementation does not use any flags, and thus the flag.Parse call is unnecessary. This leads to people who use this example as a starting point for their own implementations to forget that the call is not necessary in most cases. Comment it out instead of removing the line to keep it as a reminder, as suggested by Minux Ma. Change-Id: I6ffc5413e7036366ae3cf0f069b7065e832a3b45 Reviewed-on: https://go-review.googlesource.com/33273 Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: add T.Context methodBrad Fitzpatrick2016-11-034-33/+95
| | | | | | | | | | | | | | | | | From the doc comment: Context returns the context for the current test or benchmark. The context is cancelled when the test or benchmark finishes. A goroutine started during a test or benchmark can wait for the context's Done channel to become readable as a signal that the test or benchmark is over, so that the goroutine can exit. Fixes #16221. Fixes #17552. Change-Id: I657df946be2c90048cc74615436c77c7d9d1226c Reviewed-on: https://go-review.googlesource.com/31724 Reviewed-by: Rob Pike <r@golang.org>
* testing: mark tests and benchmarks failed if a race occurs during executionRuss Cox2016-11-032-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: $ go test -race -v -run TestRace === RUN TestRace ================== WARNING: DATA RACE Write at 0x00c420076420 by goroutine 7: _/Users/rsc/go/src/cmd/go/testdata/src/testrace.TestRace.func1() /Users/rsc/go/src/cmd/go/testdata/src/testrace/race_test.go:10 +0x3b Previous write at 0x00c420076420 by goroutine 6: _/Users/rsc/go/src/cmd/go/testdata/src/testrace.TestRace() /Users/rsc/go/src/cmd/go/testdata/src/testrace/race_test.go:13 +0xcc testing.tRunner() /Users/rsc/go/src/testing/testing.go:656 +0x104 Goroutine 7 (running) created at: _/Users/rsc/go/src/cmd/go/testdata/src/testrace.TestRace() /Users/rsc/go/src/cmd/go/testdata/src/testrace/race_test.go:12 +0xbb testing.tRunner() /Users/rsc/go/src/testing/testing.go:656 +0x104 Goroutine 6 (running) created at: testing.(*T).Run() /Users/rsc/go/src/testing/testing.go:693 +0x536 testing.runTests.func1() /Users/rsc/go/src/testing/testing.go:877 +0xaa testing.tRunner() /Users/rsc/go/src/testing/testing.go:656 +0x104 testing.runTests() /Users/rsc/go/src/testing/testing.go:883 +0x4ac testing.(*M).Run() /Users/rsc/go/src/testing/testing.go:818 +0x1c3 main.main() _/Users/rsc/go/src/cmd/go/testdata/src/testrace/_test/_testmain.go:42 +0x20f ================== --- PASS: TestRace (0.00s) PASS Found 1 data race(s) FAIL _/Users/rsc/go/src/cmd/go/testdata/src/testrace 1.026s $ After: $ go test -race -v -run TestRace === RUN TestRace ================== WARNING: DATA RACE Write at 0x00c420076420 by goroutine 7: _/Users/rsc/go/src/cmd/go/testdata/src/testrace.TestRace.func1() /Users/rsc/go/src/cmd/go/testdata/src/testrace/race_test.go:10 +0x3b Previous write at 0x00c420076420 by goroutine 6: _/Users/rsc/go/src/cmd/go/testdata/src/testrace.TestRace() /Users/rsc/go/src/cmd/go/testdata/src/testrace/race_test.go:13 +0xcc testing.tRunner() /Users/rsc/go/src/testing/testing.go:656 +0x104 Goroutine 7 (running) created at: _/Users/rsc/go/src/cmd/go/testdata/src/testrace.TestRace() /Users/rsc/go/src/cmd/go/testdata/src/testrace/race_test.go:12 +0xbb testing.tRunner() /Users/rsc/go/src/testing/testing.go:656 +0x104 Goroutine 6 (running) created at: testing.(*T).Run() /Users/rsc/go/src/testing/testing.go:693 +0x536 testing.runTests.func1() /Users/rsc/go/src/testing/testing.go:877 +0xaa testing.tRunner() /Users/rsc/go/src/testing/testing.go:656 +0x104 testing.runTests() /Users/rsc/go/src/testing/testing.go:883 +0x4ac testing.(*M).Run() /Users/rsc/go/src/testing/testing.go:818 +0x1c3 main.main() _/Users/rsc/go/src/cmd/go/testdata/src/testrace/_test/_testmain.go:42 +0x20f ================== --- FAIL: TestRace (0.00s) testing.go:609: race detected during execution of test FAIL FAIL _/Users/rsc/go/src/cmd/go/testdata/src/testrace 0.022s $ Fixes #15972. Change-Id: Idb15b8ab81d65637bb535c7e275595ca4a6e450e Reviewed-on: https://go-review.googlesource.com/32615 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: introduce testing/internal/testdeps for holding testmain dependenciesRuss Cox2016-11-022-26/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, we don't have package testing to import package regexp directly, because then regexp can't have internal tests (or at least they become more difficult to write), for fear of an import cycle. The solution we've been using is for the generated test main package (pseudo-import path "testmain", package main) to import regexp and pass in a matchString function for use by testing when implementing the -run flags. This lets testing use regexp but without depending on regexp and creating unnecessary cycles. We want to add a few dependencies to runtime/pprof, notably regexp but also compress/gzip, without causing those packages to have to work hard to write internal tests. Restructure the (dare I say it) dependency injection of regexp.MatchString to be more general, and use it for the runtime/pprof functionality in addition to the regexp functionality. The new package testing/internal/testdeps is the root for the testing dependencies handled this way. Code using testing.MainStart will have to change from passing in a matchString implementation to passing in testdeps.TestDeps{}. Users of 'go test' don't do this, but other build systems that have recreated 'go test' (for example, Blaze/Bazel) may need to be updated. The new testdeps setup should make future updates unnecessary, but even so we keep the comment about MainStart not being subject to Go 1 compatibility. Change-Id: Iec821d2afde10c79f95f3b23de5e71b219f47b92 Reviewed-on: https://go-review.googlesource.com/32455 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: add a method testing.CoverModeRob Pike2016-11-011-0/+7
| | | | | | | | | | | | This makes it possible to avoid tests where coverage affects the test results by skipping them (or otherwise adjusting them) when coverage is enabled. Update #17699 Change-Id: Ifcc36cfcd88ebd677890e82ba80ee3d696ed3d7c Reviewed-on: https://go-review.googlesource.com/32483 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing: don't warn if -bench was passedDaniel Martí2016-11-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a previous change, cmd/go was taught to show a "no tests ran" warning if test did nothing. But it missed a case - if no tests nor examples ran but any benchmarks were meant to be run, it would still produce the warning. This meant that running only benchmarks, which is common, would be confusing: $ go test -run='^$' -bench=. testing: warning: no tests to run BenchmarkFoo-4 300000 5056 ns/op [...] I believe this was because of a copy-paste error in the tests. This was being tested, but on the wrong file which does contain a test that was being run. Fix the path and fix the now failing test by never showing the warning if -bench was given a non-empty string. The rationale is that if -bench was given but there was no output, it's obvious that nothing happened as benchmarks always produce output even without -v. So showing a warning in those cases is redundant. To make future typos less likely, make sure that no tests are being run in the cases where we only want to run benchmarks. Fixes #17603. Change-Id: I4c626caf39f72260c6a9761c06446663f465f947 Reviewed-on: https://go-review.googlesource.com/32157 Reviewed-by: Marcel van Lohuizen <mpvl@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* runtime: Profile goroutines holding contended mutexes.Peter Weinberger2016-10-281-13/+30
| | | | | | | | | | | | runtime.SetMutexProfileFraction(n int) will capture 1/n-th of stack traces of goroutines holding contended mutexes if n > 0. From runtime/pprof, pprot.Lookup("mutex").WriteTo writes the accumulated stack traces to w (in essentially the same format that blocking profiling uses). Change-Id: Ie0b54fa4226853d99aa42c14cb529ae586a8335a Reviewed-on: https://go-review.googlesource.com/29650 Reviewed-by: Austin Clements <austin@google.com>
* all: freeze net/rpc and reword the 'frozen' message in other frozen packagesRob Pike2016-10-261-1/+1
| | | | | | | | | | Make the messages grammatically korrect and consistent. Fixes #16844 Change-Id: I7c137b4dc25c0c875ed07b0c64c67ae984c39cbc Reviewed-on: https://go-review.googlesource.com/32112 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing/quick, text/tabwriter: freeze packagesBrad Fitzpatrick2016-10-241-0/+2
| | | | | | | | Fixes #15557 Change-Id: I02ad98068894e75d4e08e271fdd16cb420519460 Reviewed-on: https://go-review.googlesource.com/31910 Reviewed-by: Andrew Gerrand <adg@golang.org>
* cmd/go, testing: indicate when no tests are runCaio Marcelo de Oliveira Filho2016-10-193-12/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | For example, testing the current directory: $ go test -run XXX testing: warning: no tests to run PASS ok testing 0.013s $ And in a summary: $ go test -run XXX testing ok testing 0.013s [no tests to run] $ These make it easy to spot when the -run regexp hasn't matched anything or there are no tests. Previously the message was printed in the "current directory" case when there were no tests at all, but not for no matches, and either way was not surfaced in the directory list summary form. Fixes #15211. Change-Id: I1c82a423d6bd429fb991c9ca964c9d26c96fd3c5 Reviewed-on: https://go-review.googlesource.com/22341 Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
* testing: wrap long comment lineRuss Cox2016-10-191-1/+2
| | | | | | | | Requested in CL 31324 review. Change-Id: Ic81410e07cce07c6f3727bc46d86b6c54c15eca0 Reviewed-on: https://go-review.googlesource.com/31410 Reviewed-by: Rob Pike <r@golang.org>
* testing: document that Skip cannot undo ErrorRuss Cox2016-10-181-0/+1
| | | | | | | | | Fixes #16502. Change-Id: Id8e117a724d73cd51844c06d47bbeba61f8dc827 Reviewed-on: https://go-review.googlesource.com/31324 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
* testing: fix flag usage messagesRuss Cox2016-10-182-14/+14
| | | | | | | | Fixes #16404. Change-Id: Iabaeeef3eff2fff6e5ed2d6bc9ef9c2f6d1cb5e7 Reviewed-on: https://go-review.googlesource.com/31332 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: mention in docs for Logf that a final newline is added if neededRob Pike2016-10-161-4/+5
| | | | | | | | Fixes #16423 Change-Id: I9635db295be4d356d427adadd309084e16c4582f Reviewed-on: https://go-review.googlesource.com/31255 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: add Name method to *T and *BAndrew Gerrand2016-09-281-0/+6
| | | | | | | | | | | Fixes #17231 Change-Id: I0d6007ab504f2277cb6affc9e2050157a6ad4d5e Reviewed-on: https://go-review.googlesource.com/29970 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Minux Ma <minux@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: improve the documentation for the -run flagRob Pike2016-09-121-7/+11
| | | | | | | | | It's not intuitive, especially in the presence of subtests, so improve the explanation and extend and explain the examples. Change-Id: I6c4d3f8944b60b12311d0c0f0a8e952e7c35a9ed Reviewed-on: https://go-review.googlesource.com/28995 Reviewed-by: Andrew Gerrand <adg@golang.org>
* testing: respect benchtime on very fast benchmarksJosh Bleecher Snyder2016-08-101-4/+3
| | | | | | | | | | When ns/op dropped below 1, the old code ignored benchtime and reverted to 1s. Change-Id: I59752cef88d8d73bfd5b085f5400ae657f78504e Reviewed-on: https://go-review.googlesource.com/26664 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
* testing: document that logs are dumped to standard outputIan Lance Taylor2016-06-231-1/+1
| | | | | | | | | | | | | | | Since at least 1.0.3, the testing package has said that logs are dumped to standard error, but has in fact dumped the logs to standard output. We could change to dump to standard error, but after doing it this way for so long I think it's better to change the docs. Fixes #16138. Change-Id: If39c7ce91f51c7113f33ebabfb8f84fd4611b9e1 Reviewed-on: https://go-review.googlesource.com/24311 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
* testing: added package doc for sub(tests/benchmarks)Marcel van Lohuizen2016-05-251-0/+55
| | | | | | | | Change-Id: I6991cd7a41140da784a1ff8d69c5ea2032d05850 Reviewed-on: https://go-review.googlesource.com/23354 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: don't be silent if a test's goroutine fails a test after test exitsMarcel van Lohuizen2016-05-242-2/+31
| | | | | | | | | | | Fixes #15654 Change-Id: I9bdaa9b76d480d75f24d95f0235efd4a79e3593e Reviewed-on: https://go-review.googlesource.com/23320 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
* testing: fix vet warningAliaksandr Valialkin2016-05-121-2/+2
| | | | | | | | Updates #11041 Change-Id: I32a381854e6a4fd791db380150efab57e6dfc38c Reviewed-on: https://go-review.googlesource.com/23081 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* Revert "testing/quick: generate more map and slice states"Russ Cox2016-05-062-29/+35
| | | | | | | | | | | This reverts commit 0ccabe2e0b42a2602e0f37ce28d5368aa811f530. Change-Id: Ib1c230fb6801c0ee26f4a352b0c1130fa240a76a Reviewed-on: https://go-review.googlesource.com/22860 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing: add matching of subtestMarcel van Lohuizen2016-04-212-10/+179
| | | | | | | | | | | | | | | | | | | | | | | Allows passing regexps per subtest to --test.run and --test.bench Note that the documentation explicitly states that the split regular expressions match the correpsonding parts (path components) of the bench/test identifier. This is intended and slightly different from the i'th RE matching the subtest/subbench at the respective level. Picking this semantics allows guaranteeing that a test or benchmark identifier as printed by go test can be passed verbatim (possibly quoted) to, respectively, -run or -bench: subtests and subbenches might have a '/' in their name, causing a misaligment if their ID is passed to -run or -bench as is. This semantics has other benefits, but this is the main motivation. Fixes golang.go#15126 Change-Id: If72e6d3f54db1df6bc2729ac6edc7ab3c740e7c3 Reviewed-on: https://go-review.googlesource.com/19122 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: removed flakey testMarcel van Lohuizen2016-04-141-51/+0
| | | | | | | | | | | | | | | The synchronization in this test is a bit complicated and likely incorrect, judging from the sporadically hanging trybots. Most of what this is supposed to test is already tested in TestTestContext, so I'll just remove it. Fixes #15170 Change-Id: If54db977503caa109cec4516974eda9191051888 Reviewed-on: https://go-review.googlesource.com/22080 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing: fix flakey test on plan9Marcel van Lohuizen2016-04-061-32/+27
| | | | | | | | | | | | allow for more than 0.00s. Fixes #15149 Change-Id: I1d428a9b3c9bb3d1db8682c53b86e44cecc1dde1 Reviewed-on: https://go-review.googlesource.com/21602 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: fixed bug introduced by CL 21504Marcel van Lohuizen2016-04-062-1/+25
| | | | | | | | | | This broke T.Run Change-Id: I12c8fe3612f3fa2caa83049c1c7003056daf2b0c Reviewed-on: https://go-review.googlesource.com/21600 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing: improve outputMarcel van Lohuizen2016-04-053-13/+158
| | | | | | | | | | | | | | | | | | | | | | This introduces a few changes - Skipped benchmarks now print a SKIP line, also if there was no output - The benchmark name is only printed if there the benchmark was not skipped or did not fail in the probe phase. It also fixes a bug of doubling a skip message in chatty mode in absense of a failure. The chatty flag is now passed in the common struct to allow for testing of the printed messages. Fixes #14799 Change-Id: Ia8eb140c2e5bb467e66b8ef20a2f98f5d95415d5 Reviewed-on: https://go-review.googlesource.com/21504 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: unflake TestBRunMarcel van Lohuizen2016-04-041-2/+6
| | | | | | | | | | | by only testing the lower bound of memalloc Fixes #15063 Change-Id: Iab2fdd75e9ce98c641bfbce57f142fa47176772d Reviewed-on: https://go-review.googlesource.com/21507 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
* cmd/go: fix proc-count accumulation in benchmark nameAlberto Donizetti2016-03-261-1/+1
| | | | | | | | | | | Fixes #14964 Change-Id: I5f772426081efaa9315c4ecaf60de850af324f1d Reviewed-on: https://go-review.googlesource.com/21139 Reviewed-by: Ahmed Waheed <oneofone@gmail.com> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: probe with N=1Marcel van Lohuizen2016-03-252-26/+26
| | | | | | | | | | | | | | | | | | | Change control flow to probe with N=1. This calls benchFunc the same number of times as the old implementation in the absence of subbenchmarks. To be compatible with existing tools, benchmarking only prints a line for "leaf" benchmarks. This means, though, that the name of a benchmark can only be printed after the first iteration. Issue #14863 Change-Id: Ic7b9b89b058f8ebb5287755f24f9e47df8c9537c Reviewed-on: https://go-review.googlesource.com/21043 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* testing: expose subtest and subbenchmark functionalityMarcel van Lohuizen2016-03-223-13/+10
| | | | | | | | | Fixes #12166 Change-Id: Ie62cba2c39beb5732447ba3688c93c08ef12abb5 Reviewed-on: https://go-review.googlesource.com/18898 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
* testing: added name matcher and sanitizerMarcel van Lohuizen2016-03-225-26/+207
| | | | | | | | | | | | | | | | | The matcher is responsible for sanitizing and uniquing the test and benchmark names and thus needs to be included before the API can be exposed. Matching currently uses the regexp to only match the top-level tests/benchmarks. Support for subtest matching is for another CL. Change-Id: I7c8464068faef7ebc179b03a7fe3d01122cc4f0b Reviewed-on: https://go-review.googlesource.com/18897 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: add test for not exceeding maximum parallismMarcel van Lohuizen2016-03-212-1/+52
| | | | | | | | | | | Fixed bug that slipped probably slipped in after rebasing and explain why it failed on nacl/netbsd/plan9, which set default maxparallelism to 1. Change-Id: I4d59682fb2843d138b320334189f53fcdda5b2f6 Reviewed-on: https://go-review.googlesource.com/20980 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* testing: disable tests that cause a hang on some platformsMarcel van Lohuizen2016-03-181-53/+1
| | | | | | | | | | | plan9, nacl, and netbsd to be precise. Only the first test causes a hang, but just to be sure. Change-Id: I400bb356ee2a0cf12c8666c95af79c924d1629aa Reviewed-on: https://go-review.googlesource.com/20839 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* testing: always ignore RunParallel in probe phaseMarcel van Lohuizen2016-03-181-1/+4
| | | | | | Change-Id: If45410a2d7e48d1c9e6800cd98f81dd89024832c Reviewed-on: https://go-review.googlesource.com/20852 Reviewed-by: Russ Cox <rsc@golang.org>
* testing: finish implementation of subtestsMarcel van Lohuizen2016-03-182-0/+249
| | | | | | | | API not exposed yet. Change-Id: Iaba0adc0fa1ae8075e6b56796f99ee8db9177a78 Reviewed-on: https://go-review.googlesource.com/18896 Reviewed-by: Russ Cox <rsc@golang.org>
* testing: implementation of subbenchmarksMarcel van Lohuizen2016-03-182-27/+205
| | | | | | | | API is not exposed yet. Change-Id: I729360ef2be1d8ea683ca93cdb1763897cc8657c Reviewed-on: https://go-review.googlesource.com/18895 Reviewed-by: Russ Cox <rsc@golang.org>
* testing: hoisted chunks of code to prepare for Run methodMarcel van Lohuizen2016-03-182-58/+100
| | | | | | | | | | | | | | | | | | testing.go: - run method will evolve into the Run method. - added level field in common benchmark.go: - benchContext will be central to distinguish handling of benchmarks between normal Run methods and ones called from within Benchmark function. - expandCPU will evolve into the processing hook for Run methods called within normal processing. - runBench will evolve into the Run method. Change-Id: I1816f9985d5ba94deb0ad062302ea9aee0bb5338 Reviewed-on: https://go-review.googlesource.com/18894 Reviewed-by: Russ Cox <rsc@golang.org>
* testing: prepare for the introduction of Run methodsMarcel van Lohuizen2016-03-183-76/+274
| | | | | | | | | | | | | The biggest change is that each test is now responsible for managing the starting and stopping of its parallel subtests. The "Main" test could be run as a tRunner as well. This shows that the introduction of subtests is merely a generalization of and consistent with the current semantics. Change-Id: Ibf8388c08f85d4b2c0df69c069326762ed36a72e Reviewed-on: https://go-review.googlesource.com/18893 Reviewed-by: Russ Cox <rsc@golang.org>
* testing: implement 'Unordered Output' in Examples.Brady Catherman2016-03-091-5/+21
| | | | | | | | | | | | | | | | | Adds a type of output to Examples that allows tests to have unordered output. This is intended to help clarify when the output of a command will produce a fixed return, but that return might not be in an constant order. Examples where this is useful would be documenting the rand.Perm() call, or perhaps the (os.File).Readdir(), both of which can not guarantee order, but can guarantee the elements of the output. Fixes #10149 Change-Id: Iaf0cf1580b686afebd79718ed67ea744f5ed9fc5 Reviewed-on: https://go-review.googlesource.com/19280 Reviewed-by: Andrew Gerrand <adg@golang.org>
* all: single space after period.Brad Fitzpatrick2016-03-025-12/+12
| | | | | | | | | | | | | | | | | | | | The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: make copyright headers consistent with one space after periodBrad Fitzpatrick2016-03-013-3/+3
| | | | | | | | | | | | | | | | | | | | | | This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: remove public named return values when uselessBrad Fitzpatrick2016-02-291-24/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Named returned values should only be used on public funcs and methods when it contributes to the documentation. Named return values should not be used if they're only saving the programmer a few lines of code inside the body of the function, especially if that means there's stutter in the documentation or it was only there so the programmer could use a naked return statement. (Naked returns should not be used except in very small functions) This change is a manual audit & cleanup of public func signatures. Signatures were not changed if: * the func was private (wouldn't be in public godoc) * the documentation referenced it * the named return value was an interesting name. (i.e. it wasn't simply stutter, repeating the name of the type) There should be no changes in behavior. (At least: none intended) Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109 Reviewed-on: https://go-review.googlesource.com/20024 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
* testing: make failure in benchmark cause non-zero exit statusCaio Marcelo de Oliveira Filho2016-02-282-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | Moves the implementation of RunBenchmarks to a non-exported function that returns whether the execution was OK, and uses that to identify failure in benchmarks.The exported function is kept for compatibility. Like before, benchmarks will only be executed if tests and examples pass. The PASS message will not be printed if there was a failure in a benchmark. Example output BenchmarkThatCallsFatal-8 --- FAIL: BenchmarkThatCallsFatal-8 x_test.go:6: called by benchmark FAIL exit status 1 FAIL _/.../src/cmd/go/testdata/src/benchfatal 0.009s Fixes #14307. Change-Id: I6f3ddadc7da8a250763168cc099ae8b325a79602 Reviewed-on: https://go-review.googlesource.com/19889 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing/quick: generate more map and slice statesMatt T. Proud2016-02-262-35/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | This change adds support in testing/quick to generate maps and slices in additional states: (1.) nil maps (2.) nil slices (3.) empty slice occupancy: `len(s) == 0 && s != nil` (4.) partial slice occupancy: `len(s) < cap(s) && s != nil` (5.) full slice occupancy: `len(s) == cap(s) && s != nil` Prior to this, only #5 was ever generated, thereby not sufficiently exercising all of the fuzzable code path outcomes. This change depends on https://go-review.googlesource.com/#/c/17499/. Change-Id: I9343c475cefbd72ffc5237281826465c25872206 Reviewed-on: https://go-review.googlesource.com/16470 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* testing: move comment inside T.ParallelRuss Cox2016-01-061-3/+4
| | | | | | | | | This was supposed to be in CL 18204 but I submitted from the web instead of my computer and lost this final edit. Change-Id: I41598e936bb088d77f5e44752eda74222a4208c7 Reviewed-on: https://go-review.googlesource.com/18310 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing: add clear panic for duplicate call to t.ParallelRuss Cox2016-01-041-1/+6
| | | | | | Change-Id: I155633b58e1823344a26c3edf11f5626fae080ee Reviewed-on: https://go-review.googlesource.com/18204 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* testing: use debug.SetTraceback("all") to show all goroutines at test timeoutRuss Cox2015-12-181-0/+2
| | | | | | | | | Fixes #13681. Change-Id: I308930f4d9200fbe0f09cd08c38392ca1bb0db67 Reviewed-on: https://go-review.googlesource.com/18044 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com>
* testing: document that T and B are safe for concurrent callsRuss Cox2015-12-012-0/+19
| | | | | | | | Fixes #13108. Change-Id: I474cc2a3b7ced1c9eb978fc815f9c6bae9fb3ecc Reviewed-on: https://go-review.googlesource.com/17235 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* testing: pause the test timer while waiting in T.ParallelCaleb Spare2015-11-241-3/+5
| | | | | | | | | | | | | | | Before, we reset the timer at the end of T.Parallel, which is okay assuming that T.Parallel is the first thing in the test. Snapshot the elapsed time at the beginning of Parallel and include it in the total duration so that any time spent in the test before calling Parallel is reported in the test duration as well. Updates #12243. Change-Id: Ieca553e1f801e16b9b6416463fa8f7fa65425185 Reviewed-on: https://go-review.googlesource.com/16989 Reviewed-by: Russ Cox <rsc@golang.org>