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

Shrinking hits "empty generator in function" #10

Open
robinp opened this issue Feb 26, 2025 · 2 comments
Open

Shrinking hits "empty generator in function" #10

robinp opened this issue Feb 26, 2025 · 2 comments

Comments

@robinp
Copy link

robinp commented Feb 26, 2025

Sometimes when a property fails and hedgehog shrinks, then hedgehog-fn errors out with the above message, so the failing test value can't be observed.

This seems to be called from apply, in

-- | Extract the root value from a 'TreeT'. Unsafe.
unsafeFromTree :: Functor m => TreeT (MaybeT m) a -> m a
unsafeFromTree =
  fmap (maybe (error "empty generator in function") nodeValue) .
  runMaybeT .
  runTreeT

Is there any hint how to avoid generating functions that fail during shrinking? I would prefer no shrinking rather than an erroring out shrink.

Note that there's some workaround where I just try to re-run and hope that eventually a non-failing shrink path would be hit.

Also note that I tried to limit shrinks using withShrinks, but for some reason that seems to get caught in some endless loop (so it never generates an output). I only guess it is an endless loop, since I recall that when I try to print some generated functions, it would loop writing the function table endlessly. I only assume this is similar, hedgehog trying to print and format a not sufficiently shrunk function, and getting stuck in the loop. (Maybe this is worth a different issue?)

@LightAndLight
Copy link
Collaborator

LightAndLight commented Feb 28, 2025

Do you have a small property test that (probabilistically) replicates the issue? I haven't thought about this project for a long time, so I'd need to play around to debug things.

@robinp
Copy link
Author

robinp commented Feb 28, 2025

@LightAndLight yes, I managed to bare it down. Please give me some time to remove some more cruft so it can be ran independently, will share sometime around next week.

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