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

Add SampleTest and update macro #5

Merged
merged 1 commit into from
Jun 23, 2023
Merged

Add SampleTest and update macro #5

merged 1 commit into from
Jun 23, 2023

Conversation

AnIrishDuck
Copy link
Collaborator

Most of this PR is the SampleTest implementation, which was basically copied with some fixes from the quickcheck tester. There are several notable changes:

  • Just using the Debug impl on tuples means there's no need to define a separate shrink function for each Testable. This simplifies the implementations and associated macro.
  • We switch to an iterative shrinking procedure instead of a recursive one. This kills two birds with one stone:

Aside from that, the #[sample_test] macro gets much simpler as we no longer need to derive Arbitrary newtypes for each sampler. This also makes it more ergonomic: you can now define values directly and use function calls instead of the prior lazy_static requirement.

The only downside is when using once_cell::sync::Lazy or lazy_static, you need to call .clone() (as we expect the sampler by-value and these constructs return a Deref). I don't think this is a major problem as the function-call or direct-value use cases are probably the common path.

Copy link

@jblondin jblondin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks interesting! I look forward to playing around with it

F: 'static,
T: 'static,
{
panic::catch_unwind(panic::AssertUnwindSafe(fun)).map_err(|any_err| {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, I've never played with std::panic stuff, fun!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yeah. This was stolen from quickcheck. Useful for when a test run panics (e.g. an assert fails); we don't want to bubble the panic up, we want to treat it as a failure during the shrinking procedure.

@AnIrishDuck AnIrishDuck merged commit fa95e5b into main Jun 23, 2023
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

Successfully merging this pull request may close these issues.

2 participants