Documentation ¶
Overview ¶
Package rapid implements utilities for property-based testing.
Rapid checks that properties you define hold for a large number of automatically generated test cases. If a failure is found, rapid fails the current test and presents an automatically minimized version of the failing test case.
Please note that rapid is alpha software; the documentation is very incomplete, unclear and probably full of grammatical errors.
Index ¶
- func Check(t *testing.T, prop func(*T))
- func MakeCheck(prop func(*T)) func(*testing.T)
- func Run(m StateMachine) func(*T)
- type Generator
- func ArrayOf(count int, elem *Generator) *Generator
- func Boolean() *Generator
- func Byte() *Generator
- func ByteMax(max byte) *Generator
- func ByteMin(min byte) *Generator
- func ByteRange(min byte, max byte) *Generator
- func Custom(fn interface{}) *Generator
- func Float32() *Generator
- func Float32Max(max float32) *Generator
- func Float32Min(min float32) *Generator
- func Float32Range(min float32, max float32) *Generator
- func Float64() *Generator
- func Float64Max(max float64) *Generator
- func Float64Min(min float64) *Generator
- func Float64Range(min float64, max float64) *Generator
- func Int() *Generator
- func Int16() *Generator
- func Int16Max(max int16) *Generator
- func Int16Min(min int16) *Generator
- func Int16Range(min int16, max int16) *Generator
- func Int32() *Generator
- func Int32Max(max int32) *Generator
- func Int32Min(min int32) *Generator
- func Int32Range(min int32, max int32) *Generator
- func Int64() *Generator
- func Int64Max(max int64) *Generator
- func Int64Min(min int64) *Generator
- func Int64Range(min int64, max int64) *Generator
- func Int8() *Generator
- func Int8Max(max int8) *Generator
- func Int8Min(min int8) *Generator
- func Int8Range(min int8, max int8) *Generator
- func IntMax(max int) *Generator
- func IntMin(min int) *Generator
- func IntRange(min int, max int) *Generator
- func Just(val interface{}) *Generator
- func MapOf(key *Generator, val *Generator) *Generator
- func MapOfN(key *Generator, val *Generator, minLen int, maxLen int) *Generator
- func MapOfNValues(val *Generator, minLen int, maxLen int, keyFn interface{}) *Generator
- func MapOfValues(val *Generator, keyFn interface{}) *Generator
- func OneOf(gens ...*Generator) *Generator
- func Ptr(elem *Generator, allowNil bool) *Generator
- func Rune() *Generator
- func RuneFrom(runes []rune, tables ...*unicode.RangeTable) *Generator
- func SampledFrom(slice interface{}) *Generator
- func SliceOf(elem *Generator) *Generator
- func SliceOfBytesMatching(expr string) *Generator
- func SliceOfDistinct(elem *Generator, keyFn interface{}) *Generator
- func SliceOfN(elem *Generator, minLen int, maxLen int) *Generator
- func SliceOfNDistinct(elem *Generator, minLen int, maxLen int, keyFn interface{}) *Generator
- func String() *Generator
- func StringMatching(expr string) *Generator
- func StringN(minRunes int, maxRunes int, maxLen int) *Generator
- func StringOf(elem *Generator) *Generator
- func StringOfN(elem *Generator, minElems int, maxElems int, maxLen int) *Generator
- func Uint() *Generator
- func Uint16() *Generator
- func Uint16Max(max uint16) *Generator
- func Uint16Min(min uint16) *Generator
- func Uint16Range(min uint16, max uint16) *Generator
- func Uint32() *Generator
- func Uint32Max(max uint32) *Generator
- func Uint32Min(min uint32) *Generator
- func Uint32Range(min uint32, max uint32) *Generator
- func Uint64() *Generator
- func Uint64Max(max uint64) *Generator
- func Uint64Min(min uint64) *Generator
- func Uint64Range(min uint64, max uint64) *Generator
- func Uint8() *Generator
- func Uint8Max(max uint8) *Generator
- func Uint8Min(min uint8) *Generator
- func Uint8Range(min uint8, max uint8) *Generator
- func UintMax(max uint) *Generator
- func UintMin(min uint) *Generator
- func UintRange(min uint, max uint) *Generator
- func Uintptr() *Generator
- func UintptrMax(max uintptr) *Generator
- func UintptrMin(min uintptr) *Generator
- func UintptrRange(min uintptr, max uintptr) *Generator
- type StateMachine
- type T
- func (t *T) Error(args ...interface{})
- func (t *T) Errorf(format string, args ...interface{})
- func (t *T) Fail()
- func (t *T) FailNow()
- func (t *T) Failed() bool
- func (t *T) Fatal(args ...interface{})
- func (t *T) Fatalf(format string, args ...interface{})
- func (t *T) Log(args ...interface{})
- func (t *T) Logf(format string, args ...interface{})
- func (t *T) Skip(args ...interface{})
- func (t *T) SkipNow()
- func (t *T) Skipf(format string, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check fails the current test if rapid can find a test case which falsifies prop.
Property is falsified in case of a panic or a call to (*T).Fatalf, (*T).Fatal, (*T).Errorf, (*T).Error, (*T).FailNow or (*T).Fail.
func MakeCheck ¶
MakeCheck is a convenience function for defining subtests suitable for (*testing.T).Run. It allows you to write this:
t.Run("subtest name", rapid.MakeCheck(func(t *rapid.T) { // test code }))
instead of this:
t.Run("subtest name", func(t *testing.T) { rapid.Check(t, func(t *rapid.T) { // test code }) })
func Run ¶ added in v0.3.1
func Run(m StateMachine) func(*T)
Run is a convenience function for defining "state machine" tests, to be run by Check or MakeCheck.
State machine test is a pattern for testing stateful systems that looks like this:
m := new(StateMachineType) m.RandomInitAction(t) // optional defer m.Cleanup() // optional m.Check(t) for { m.RandomAction(t) m.Check(t) }
Run synthesizes such test from the type of m, which must be a pointer. Note that for each test case, new state machine instance is created via reflection; any data inside m is ignored.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func Float32Max ¶
func Float32Min ¶
func Float32Range ¶
func Float64Max ¶
func Float64Min ¶
func Float64Range ¶
func Int16Range ¶
func Int32Range ¶
func Int64Range ¶
func MapOfNValues ¶
func MapOfValues ¶
func SampledFrom ¶
func SampledFrom(slice interface{}) *Generator
func SliceOfBytesMatching ¶
func SliceOfDistinct ¶
func SliceOfNDistinct ¶
func StringMatching ¶
func Uint16Range ¶
func Uint32Range ¶
func Uint64Range ¶
func Uint8Range ¶
func UintptrMax ¶
func UintptrMin ¶
func UintptrRange ¶
type StateMachine ¶
type StateMachine interface { // Check is ran after every action and should contain invariant checks. // // Other public methods are treated as follows: // - Init(t *rapid.T), InitAnySuffixHere(t *rapid.T), if present, // are used as "initializer" actions; exactly one is ran at the beginning // of each test case; // - Cleanup(), if present, is called at the end of each test case; // - All other public methods should have a form ActionName(t *rapid.T) // and are used as possible actions. At least one action has to be specified. Check(*T) }
type T ¶
type T struct {
// contains filtered or unexported fields
}
func (*T) SkipNow ¶
func (t *T) SkipNow()
SkipNow marks the current test case as invalid. If too many test cases are skipped, rapid will mark the test as failing due to inability to generate enough valid test cases.
Prefer Filter to SkipNow, and prefer generators that always produce valid test cases to Filter.