github.com/leanovate/gopter@v0.2.9/example_panic_test.go (about)

     1  package gopter_test
     2  
     3  import (
     4  	"github.com/leanovate/gopter"
     5  	"github.com/leanovate/gopter/gen"
     6  	"github.com/leanovate/gopter/prop"
     7  )
     8  
     9  func Example_panic() {
    10  	parameters := gopter.DefaultTestParameters()
    11  	parameters.Rng.Seed(1234) // Just for this example to generate reproducible results
    12  
    13  	properties := gopter.NewProperties(parameters)
    14  	properties.Property("Will panic", prop.ForAll(
    15  		func(i int) bool {
    16  			if i%2 == 0 {
    17  				panic("hi")
    18  			}
    19  			return true
    20  		},
    21  		gen.Int().WithLabel("number")))
    22  	// When using testing.T you might just use: properties.TestingRun(t)
    23  	properties.Run(gopter.ConsoleReporter(false))
    24  	// Output:
    25  	// ! Will panic: Error on property evaluation after 6 passed tests: Check
    26  	//    paniced: hi
    27  	// number: 0
    28  	// number_ORIGINAL (1 shrinks): 2015020988
    29  }