panics in checks: no labels/values printed
antifuchs opened this issue · comments
I find that code like the following:
package panics
import (
"testing"
"github.com/leanovate/gopter"
"github.com/leanovate/gopter/gen"
"github.com/leanovate/gopter/prop"
)
func TestPanic(t *testing.T) {
properties := gopter.NewProperties(nil)
properties.Property("Will panic", prop.ForAll(
func(i int) bool {
if i%2 == 0 {
panic("hi")
}
return true
},
gen.Int().WithLabel("number")))
properties.TestingRun(t)
}
does catch the panic, but while it prints the random seed, it does not print the parameters that resulted in the panic:
Click for output
$ go test -run TestPanic . ! Will panic: Error on property evaluation after 0 passed tests: Check paniced: hi goroutine 20 [running]: runtime/debug.Stack(0xc0000b36e8, 0x130fa80, 0x13ded80) /usr/local/Cellar/go/1.11.5/libexec/src/runtime/debug/stack.go:24 +0xa7 github.com/leanovate/gopter.SaveProp.func1.1(0xc0000b3cf0) /Users/asf/go/src/github.com/leanovate/gopter/prop.go:19 +0x6e panic(0x130fa80, 0x13ded80) /usr/local/Cellar/go/1.11.5/libexec/src/runtime/panic.go:513 +0x1b9 github.com/antifuchs/o_test.TestPanic.func1(0x0) /Users/asf/go/src/github.com/antifuchs/o/ranges_properties_test.go:131 +0x39 reflect.Value.call(0x130d6c0, 0x13a01f0, 0x13, 0x138a736, 0x4, 0x1643500, 0x0, 0x0, 0x0, 0x0, ...) /usr/local/Cellar/go/1.11.5/libexec/src/reflect/value.go:447 +0x454 reflect.Value.Call(0x130d6c0, 0x13a01f0, 0x13, 0x1643500, 0x0, 0x0, 0x13898c0, 0x1, 0x1643500) /usr/local/Cellar/go/1.11.5/libexec/src/reflect/value.go:308 +0xa4 github.com/leanovate/gopter/prop.checkConditionFunc.func2(0x1643500, 0x0, 0x0, 0x1643500) /Users/asf/go/src/github.com/leanovate/gopter/prop/check_condition_func.go :37 +0x5e github.com/leanovate/gopter/prop.ForAll.func1(0xc00009a560, 0x13a0258) /Users/asf/go/src/github.com/leanovate/gopter/prop/forall.go:40 +0x266 github.com/leanovate/gopter.SaveProp.func1(0xc00009a560, 0x0) /Users/asf/go/src/github.com/leanovate/gopter/prop.go:24 +0x6c github.com/leanovate/gopter.Prop.Check.func1(0x0, 0xc000084fd0, 0x1625ca0) /Users/asf/go/src/github.com/leanovate/gopter/prop.go:52 +0x155 github.com/leanovate/gopter.(*runner).runWorkers(0xc000089170, 0x0) /Users/asf/go/src/github.com/leanovate/gopter/runner.go:49 +0x2d1 github.com/leanovate/gopter.Prop.Check(0xc000084fb0, 0xc000090840, 0x138be08) /Users/asf/go/src/github.com/leanovate/gopter/prop.go:110 +0x194 github.com/leanovate/gopter.(*Properties).Run(0xc000089110, 0x13e0d60, 0xc00009a520, 0xc00008b1e0) /Users/asf/go/src/github.com/leanovate/gopter/properties.go:37 +0xbc github.com/leanovate/gopter.(*Properties).TestingRun(0xc000089110, 0xc000116100, 0x0, 0x0, 0x0) /Users/asf/go/src/github.com/leanovate/gopter/properties.go:56 +0x137 github.com/antifuchs/o_test.TestPanic(0xc000116100) /Users/asf/go/src/github.com/antifuchs/o/ranges_properties_test.go:133 +0x126 testing.tRunner(0xc000116100, 0x13a01f8) /usr/local/Cellar/go/1.11.5/libexec/src/testing/testing.go:827 +0xbf created by testing.(*T).Run /usr/local/Cellar/go/1.11.5/libexec/src/testing/testing.go:878 +0x35cElapsed time: 275.319µs
--- FAIL: TestPanic (0.00s)
properties.go:57: failed with initial seed: 1552922262110846000
FAIL
FAIL github.com/antifuchs/o 0.015s
What I would expect to see is to see the "Labels of the failing property" printed.
To work around this, I hard-code the random seed in the test options and return false
at the start of my function if I am interested in the values, but this seems like a thing gopter could & should do automatically, especially as it already captures the panic.
There is no an example/test for this case (example_panic_test.go). Also tweaked the console reporter so that in non-verbose mode the error-stack is suppressed.
Just upgraded gopter and can confirm that it works! Thanks for fixing this!