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 shrinks a List required to be nonEmpty to Nil #443

Open
letalvoj opened this issue Nov 30, 2018 · 3 comments
Open

Shrinking shrinks a List required to be nonEmpty to Nil #443

letalvoj opened this issue Nov 30, 2018 · 3 comments

Comments

@letalvoj
Copy link

Let's have a generator of a data structure which contains a non empty list. Like

Gen.nonEmptyListOf(Gen.choose(0,10))

When shrinking kicks in, what happens is that the list gets shortened - well that's an obvious way to reduce the input, I agree. Yet if the error is caused by a different parameter, than the shrinking does not stop and shrinks the list all the way to Nil.

That kind of sucks, because there is definitely a reason for the list to be non empty! In my case it causes an empty.head error which is completely misleading and obscures the actual problem.

IMO the Shrinker should respect the domain of the values specified by the defined Generator.

@charleso
Copy link

Unfortunately in ScalaCheck (and the original QuickCheck) shrinking has to be done separately and in addition to generation. It doesn’t compose.

This problem is made slightly more annoying in ScalaCheck because of the combination of restricted Gens with the global/implicit Shrinker in forAll. I would argue it’s a bug and have opened a PR to remove that particular behaviour (but don’t know if it will be accepted). So you basically wouldn’t get shrinking when using Gen, which is why you’re getting an error, which is a reoccurring problem from what I have observed.

#440

I highly recommend checking out a fairly new library Hedgehog which effectively fixes/solves this problem by integrating shrinking with Gen. There’s a great talk by the creator.

https://m.youtube.com/watch?v=AIv_9T0xKEo

Shameless plug warning. There is also the Scala version which I maintain.

https://github.com/hedgehogqa/scala-hedgehog

@ashawley
Copy link
Contributor

It's a known issue in #129.

Writing your own shrinker is possible, see:

https://stackoverflow.com/questions/50103923/how-do-i-shrink-a-list-but-guarantee-it-isnt-empty

@letalvoj
Copy link
Author

letalvoj commented Nov 30, 2018 via email

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

3 participants