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 StateMachine(i interface{}) 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 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 StateMachine ¶
func StateMachine(i interface{}) func(*T)
StateMachine 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:
s := new(STATE_MACHINE_DEFINITION_TYPE) RUN_RANDOM_INITIALIZER_ACTION(s) defer CLEANUP(s) CHECK_INVARIANTS(s) for { RUN_RANDOM_ACTION(s) CHECK_INVARIANTS(s) }
StateMachine synthesizes such test from the type of its argument, which must be a pointer to an arbitrary state machine definition type, whose 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;
- Check(t *rapid.T), if present, is ran after every action;
- 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.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func Float32Max ¶ added in v0.2.0
func Float32Min ¶ added in v0.2.0
func Float32Range ¶ added in v0.2.0
func Float64Max ¶ added in v0.2.0
func Float64Min ¶ added in v0.2.0
func Float64Range ¶ added in v0.2.0
func Int16Range ¶ added in v0.2.0
func Int32Range ¶ added in v0.2.0
func Int64Range ¶ added in v0.2.0
func MapOfNValues ¶ added in v0.2.0
func MapOfValues ¶ added in v0.2.0
func RuneFrom ¶ added in v0.2.0
func RuneFrom(runes []rune, tables ...*unicode.RangeTable) *Generator
func SampledFrom ¶
func SampledFrom(slice interface{}) *Generator
func SliceOfBytesMatching ¶ added in v0.2.0
func SliceOfDistinct ¶ added in v0.2.0
func SliceOfNDistinct ¶ added in v0.2.0
func StringMatching ¶ added in v0.2.0
func Uint16Range ¶ added in v0.2.0
func Uint32Range ¶ added in v0.2.0
func Uint64Range ¶ added in v0.2.0
func Uint8Range ¶ added in v0.2.0
func UintptrMax ¶ added in v0.2.0
func UintptrMin ¶ added in v0.2.0
func UintptrRange ¶ added in v0.2.0
type T ¶
type T struct {
// contains filtered or unexported fields
}
func (*T) SkipNow ¶ added in v0.2.0
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.