Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitraries.GenForType does not support arrays #86

Closed
Wessie opened this issue Apr 1, 2024 · 6 comments
Closed

Arbitraries.GenForType does not support arrays #86

Wessie opened this issue Apr 1, 2024 · 6 comments

Comments

@Wessie
Copy link

Wessie commented Apr 1, 2024

passing an array type to GenForType returns nil, and this only panics once the properties are actually ran so it isn't obvious what the issue is, it produces the following stack trace:

! roundtrip: Error on property evaluation after 0 passed tests: Check
   paniced: runtime error: invalid memory address or nil pointer dereference
goroutine 19 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x5e
github.com/leanovate/gopter/prop.ForAll.SaveProp.func3.1()
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/prop.go:20 +0x6b
panic({0x6c7ec0?, 0x96c6a0?})
        /usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/leanovate/gopter/prop.ForAll.func1(0xc0000be2e0)
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/prop/forall.go:33 +0xc7
github.com/leanovate/gopter/prop.ForAll.SaveProp.func3(0x7fc1b4964b98?)
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/prop.go:25 +0x5b
github.com/leanovate/gopter.Prop.Check.func1(0x0, 0xc000090580)
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/prop.go:53 +0x132
github.com/leanovate/gopter.(*runner).runWorkers(0xc000094f90)
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/runner.go:49 +0x1cd
github.com/leanovate/gopter.Prop.Check(0xc000090560, 0xc0000f0b80)
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/prop.go:112 +0x1be
github.com/leanovate/gopter.(*Properties).Run(0xc0000d9f38, {0x78f100, 0xc0000be2a0})
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/properties.go:37 +0xa9
github.com/leanovate/gopter.(*Properties).TestingRun(0xc0000d9f38, 0xc000084ea0, {0x0, 0x0, 0x6b14a0?})
        /home/wessie/go/pkg/mod/github.com/leanovate/[email protected]/properties.go:56 +0xfc

GenForType should probably panic if there is an unsupported type

@untoldwind
Copy link
Collaborator

Can you provide a short example to reproduce this?

@Wessie
Copy link
Author

Wessie commented Apr 1, 2024

a := arbitrary.DefaultArbitraries()
gen := a.GenForType(reflect.TypeOf([20]byte{}))
fmt.Println(gen)

will print <nil> https://go.dev/play/p/1_Mxhuc5GKl

@untoldwind
Copy link
Collaborator

Can you check if the current master branch fixes your problem?

@Wessie
Copy link
Author

Wessie commented Apr 2, 2024

Yes, this fixes array support, but it would still be a nice quality of life change if passing an unsupported type to GenForType actually panicked with a reasonable message indicating such.

Also there is a typo in the array_shink.go filename

@Wessie Wessie closed this as completed Apr 2, 2024
@Wessie
Copy link
Author

Wessie commented Apr 3, 2024

I'm sorry, it seems panicking on unsupported types is a breaking change.

Since struct types ignore unsupported fields it means anyone generating structs with unsupported fields now gets a panic instead.

It's fine for the map/slice/array versions but structs explicitly ignore fields https://github.com/leanovate/gopter/blob/master/arbitrary/gen_for_kind.go#L331 if GenForType returns nil.

Sorry for the shortsightedness, maybe we can move the check into Arbitraries.ForAll instead.

@untoldwind
Copy link
Collaborator

Removed the panic for now, have to dig a bit deeper into the ForAll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants