aboutsummaryrefslogtreecommitdiff
path: root/src/testing/quick/quick.go
AgeCommit message (Collapse)Author
2025-09-17testing: use reflect.TypeAssert and reflect.TypeForapocelipes
To simplify the code. Updates #62121 Updates #60088 Change-Id: I1cef27b19961721b89a965c708320072a052d9af GitHub-Last-Rev: ffd07a74da87b84b457246b2c94d4ee7540c8e8b GitHub-Pull-Request: golang/go#75494 Reviewed-on: https://go-review.googlesource.com/c/go/+/704575 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-08testing: add available godoc linkcui fliter
Change-Id: I8f4d097601796f53176d490cddf8832b7caa4c05 Reviewed-on: https://go-review.googlesource.com/c/go/+/539836 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-04-04database/sql,testing/quick: use reflect.Value.SetZeroDaniel Martí
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>
2022-04-11all: gofmt main repoRuss Cox
[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>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-26all: use reflect.{Pointer,PointerTo}Cuong Manh Le
Updates #47651 Updates #48665 Change-Id: I69a87b45a5cad7a07fbd855040cd9935cf874554 Reviewed-on: https://go-review.googlesource.com/c/go/+/358454 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-18testing/quick: simplify explanation of -quickchecks flagRob Pike
CL 172698 documented this flag but the description was missing punctuation and could be clearer. Change-Id: I310d91ae8c6b947ce7d1ae7559882f49778f770a Reviewed-on: https://go-review.googlesource.com/c/go/+/172817 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-18testing/quick: clarify that Config.MaxCount is from a flagAndrew Z Allen
Document that the default quickcheck configuration is to run 100 times and that there is a flag that configures it called "quickchecks". Change-Id: I46fdab9d572e132ccc23ef907f9cc6b2d06b37c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/172698 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-27doc: mention testing/quick RNG seeding change in Go 1.9 notesBrad Fitzpatrick
Also reword the testing/quick.Config field docs to conform to the normal subject-first style. Without that style, godoc links /pkg/testing/quick/#Config.Rand to the wrong line, since it doesn't recognize the preceding comment as necessarily being attached. Fixes #20809 Change-Id: I9aebbf763eed9b1ab1a153fa11850d88a65571c6 Reviewed-on: https://go-review.googlesource.com/46910 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-04-05testing/quick: use Uint64 instead of Int63Russ Cox
Followup to CL 39152. Change-Id: I9bfed0c6071ea3d3a43294a6c4a50edc131368cf Reviewed-on: https://go-review.googlesource.com/39313 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-03testing/quick: generate all possible int64, uint64 valuesRuss Cox
When generating a random int8, uint8, int16, uint16, int32, uint32, quick.Value chooses among all possible values. But when generating a random int64 or uint64, it only chooses values in the range [-2⁶², 2⁶²) (even for uint64). It should, like for all the other integers, use the full range. If it had, this would have caught #19807 earlier. Instead it let us discover the presence of #19809. While we are here, also make the default source of randomness not completely deterministic. Fixes #19808. Change-Id: I070f852531c92b3670bd76523326c9132bfc9416 Reviewed-on: https://go-review.googlesource.com/39152 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2016-10-26all: freeze net/rpc and reword the 'frozen' message in other frozen packagesRob Pike
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>
2016-10-24testing/quick, text/tabwriter: freeze packagesBrad Fitzpatrick
Fixes #15557 Change-Id: I02ad98068894e75d4e08e271fdd16cb420519460 Reviewed-on: https://go-review.googlesource.com/31910 Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-05-06Revert "testing/quick: generate more map and slice states"Russ Cox
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>
2016-03-02all: single space after period.Brad Fitzpatrick
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>
2016-02-29all: remove public named return values when uselessBrad Fitzpatrick
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>
2016-02-26testing/quick: generate more map and slice statesMatt T. Proud
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>
2015-08-29testing/quick: terminate for arbitrary recursive typesHåvard Haugen
Recursive types R containing slices of R's did not terminate despite the effort in CL 10821. For recursive types there was a competition between slice expansion by a factor 'complexSize', and termination with probability '1/complexSize' which lead to stack overflow as soon as a recursive struct had slices pointing to its own type. Fix this by shrinking the size hint as a function of recursion depth. This has the dual effect of reducing the number of elements generated per slice and also increasing the probability for termination. Fixes #11148. Change-Id: Ib61155b4f2e2de3873d508d63a1f4be759426d67 Reviewed-on: https://go-review.googlesource.com/13830 Reviewed-by: Adam Langley <agl@golang.org>
2015-06-26testing/quick: improve function signature error.Matt T. Proud
This commit fixes a cosmetic defect whereby quick.Check reports that the provided function returns too many values when it may, in fact, return too few: func f() {} func TestFoo(t *testing.T) { if err := quick.Check(f, nil); err != nil { t.Fatal(err) } } // yields // $ go test -v foo_test.go // === RUN TestFoo // --- FAIL: TestFoo (0.00s) // foo_test.go:76: function returns more than one value. Change-Id: Ia209ff5b57375b30f8db425454e80798908e8ff4 Reviewed-on: https://go-review.googlesource.com/11281 Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-08testing/quick: probabilistically generate nil pointersHåvard Haugen
The documentation for quick.Value says that it "returns an arbitrary value of the given type." In spite of this, nil values for pointers were never generated, which seems more like an oversight than an intentional choice. The lack of nil values meant that testing recursive type like type Node struct { Next *Node } with testing/quick would lead to a stack overflow since the data structure would never terminate. This change may break tests that don't check for nil with pointers returned from quick.Value. Two such instances were found in the standard library, one of which was in the testing/quick package itself. Fixes #8818. Change-Id: Id390dcce649d12fbbaa801ce6f58f5defed77e60 Reviewed-on: https://go-review.googlesource.com/10821 Reviewed-by: Adam Langley <agl@golang.org> Run-TryBot: Adam Langley <agl@golang.org>
2015-03-27testing/quick: fix commentDmitry Vyukov
There is no top-level Values function. Change-Id: I3ea2eea0b5f77f3e1a3f75d1a6472507ef2888bb Reviewed-on: https://go-review.googlesource.com/8196 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-02-04testing/quick: support generation of array types in ValueChris Kastorff
Generating array types like [4]int would fail even though the int type is generatable. Allow generating values of array types when the inner type is generatable. Change-Id: I7d71b3c18edb3737e2fec1ddf5e36c9dc8401971 Reviewed-on: https://go-review.googlesource.com/3865 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.