File: example_panic_test.go

package info (click to toggle)
golang-github-leanovate-gopter 0.2.9%2Bgit20210201.bbbf00e-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 696 kB
  • sloc: makefile: 37
file content (29 lines) | stat: -rw-r--r-- 782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package gopter_test

import (
	"github.com/leanovate/gopter"
	"github.com/leanovate/gopter/gen"
	"github.com/leanovate/gopter/prop"
)

func Example_panic() {
	parameters := gopter.DefaultTestParameters()
	parameters.Rng.Seed(1234) // Just for this example to generate reproducible results

	properties := gopter.NewProperties(parameters)
	properties.Property("Will panic", prop.ForAll(
		func(i int) bool {
			if i%2 == 0 {
				panic("hi")
			}
			return true
		},
		gen.Int().WithLabel("number")))
	// When using testing.T you might just use: properties.TestingRun(t)
	properties.Run(gopter.ConsoleReporter(false))
	// Output:
	// ! Will panic: Error on property evaluation after 6 passed tests: Check
	//    paniced: hi
	// number: 0
	// number_ORIGINAL (1 shrinks): 2015020988
}