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

Avoid running earlier successes with --quickcheck-replay #410

Merged
merged 5 commits into from
Apr 10, 2024

Conversation

facundominguez
Copy link
Contributor

@facundominguez facundominguez commented Mar 18, 2024

On failure, tasty-quickcheck now suggests string seeds (with an implementation-dependent structure). Integer seeds are still accepted as input though.

Fixes #383

@facundominguez facundominguez marked this pull request as ready for review March 18, 2024 21:29
in printf "Use --quickcheck-replay=%d%s to reproduce." seed sizeStr
makeReplayMsg :: (QCGen, Int) -> String
makeReplayMsg seedSz =
printf "Use --quickcheck-single-replay=\"%s\" to reproduce." (show seedSz)
Copy link
Contributor Author

@facundominguez facundominguez Mar 18, 2024

Choose a reason for hiding this comment

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

Probably we should display both the value of --quickcheck-replay and --quickcheck-single-replay here. Otherwise, the user of --quickcheck-replay has no way to get a seed.

The value printed for --quickcheck-replay would be only meaningful when not setting --quickcheck-single-replay. Otherwise, the result of the run is unrelated to the value of --quickcheck-replay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What are the remaining use cases for --quickcheck-replay now? I guess you can just reuse it without introducing a new command line flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know who is relying on the old behavior. I'm happy to break that if nobody cares.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it hard to imagine that someone would consciously prefer old behaviour to a new, but it seems you can support both without too much trouble. If it's --quickcheck-replay=(QCGen ..., 42) do a new thing, if it's --quichckeck-replay=QCGen... do the old thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And when printing, should we show both forms when sensible?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Showing one form would be enough IMO.

Copy link
Contributor Author

@facundominguez facundominguez Mar 19, 2024

Choose a reason for hiding this comment

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

It can be done as you suggest. But note that the old form is unusable if the user has no way to discover the seeds that go with it. What would be the purpose of supporting the old form as input then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just an escape hatch. I do not see why a user might want the old behavior back; but someone could have a regression script still using an old format. Not crashing in such scenario would be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed. Also added a note to the change log. Thanks for your review @Bodigrim!

@facundominguez facundominguez force-pushed the fd/single-replay branch 3 times, most recently from b87ef3a to f5206e2 Compare March 19, 2024 01:55
On failure, tasty-quickcheck now suggests string seeds (no integer seeds anymore).
Integer seeds are still accepted as input though.
@facundominguez facundominguez changed the title Implement --quickcheck-single-replay for tasty-quickcheck Avoid running earlier successes with --quickcheck-replay Mar 19, 2024
@facundominguez
Copy link
Contributor Author

I was wondering, is this PR good to merge? Or does it need more reviews?

Copy link
Collaborator

@Bodigrim Bodigrim left a comment

Choose a reason for hiding this comment

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

A few more wibbles, but overall looks good to me, thanks!

CC @andreasabel @martijnbastiaan @VictorCMiraldo to review.

-- | Replay seed. The @Left int@ form is kept for legacy purposes.
-- The form @Right (qcgen, intSize)@ holds both the seed and the size
-- to run QuickCheck tests.
newtype QuickCheckReplay = QuickCheckReplay (Maybe (Either Int (QCGen, Int)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could it be

Suggested change
newtype QuickCheckReplay = QuickCheckReplay (Maybe (Either Int (QCGen, Int)))
newtype QuickCheckReplay = QuickCheckReplay (Maybe (Int, Maybe QCGen))

?

Copy link
Contributor Author

@facundominguez facundominguez Mar 26, 2024

Choose a reason for hiding this comment

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

I find the code easier to approach as it is.

  • The two Ints in the Either type have different meanings, whether the meaning of the Int in the Maybe form depends on the value of the second component of the pair.

  • The quickcheck API can take the pair (QCGen, Int) as is without further ado.

But let me know if you still think the Maybe form is to be preferred.

Another option is to use a custom type:

data Seed = OldSeed Int | NewSeed (QCGen, Int)

or

data QuickcheckReplay = QuickcheckReplay Int | QuickcheckReplayNew (QCGen, Int)

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, unless someone else feels strongly about it, I'm fine to keep it as is.

Co-authored-by: ˌbodʲɪˈɡrʲim <[email protected]>
Copy link
Contributor

@martijnbastiaan martijnbastiaan left a comment

Choose a reason for hiding this comment

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

LGTM.

I do like a custom data type better (Seed/QuickCheckReplay), but I'm fine with keeping it as it is now too.

@facundominguez
Copy link
Contributor Author

facundominguez commented Apr 5, 2024

Thanks @martijnbastiaan

I do like a custom data type better (Seed/QuickCheckReplay),

I contributed an implementation of this idea in facundominguez#1.
I could make it a follow up PR to UnkindPartition/tasty or maintainers can cherry-pick it if they wish.

@Bodigrim
Copy link
Collaborator

Bodigrim commented Apr 9, 2024

I contributed an implementation of this idea in facundominguez#1.
I could make it a follow up PR to UnkindPartition/tasty or maintainers can cherry-pick it if they wish.

This looks nice. Please add it to this PR + mention the change to QuickCheckReplay in the changlog + bump major version of tasty-quickcheck - and I think we'll be good to merge.

@Bodigrim
Copy link
Collaborator

Bodigrim commented Apr 9, 2024

  • please ensure that everything has correct @since pragmas.

@facundominguez
Copy link
Contributor Author

facundominguez commented Apr 9, 2024

  • add it to this PR
  • mention the change to QuickCheckReplay in the changelog
  • bump major version of tasty-quickcheck
  • please ensure that everything has correct @since pragmas.

I added @since 0.11 tags to the data constructors of the QuickCheckReplay data type. Let me know if more tags are needed.

@Bodigrim
Copy link
Collaborator

Bodigrim commented Apr 9, 2024

@facundominguez thanks! README.md can use an update too, if you are up to it.

@amesgen as an original author of #383, are you happy with this solution?

@facundominguez
Copy link
Contributor Author

facundominguez commented Apr 10, 2024

README.md can use an update too, if you are up to it.

I'm a bit embarrassed to admit that I cannot discover on my own what needs updating there. 🙈

Copy link
Contributor

@amesgen amesgen left a comment

Choose a reason for hiding this comment

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

This looks excellent!

@Bodigrim Bodigrim merged commit 83b3a53 into UnkindPartition:master Apr 10, 2024
14 checks passed
@Bodigrim
Copy link
Collaborator

I'm a bit embarrassed to admit that I cannot discover on my own what needs updating there. 🙈

@facundominguez the output of --help could be updated, but I'm not sure it was kept up-to-date before anyway.

Thanks for your contribution, merging.

github-merge-queue bot pushed a commit to IntersectMBO/ouroboros-consensus that referenced this pull request Jun 25, 2024
From the
[changelog](https://hackage.haskell.org/package/tasty-quickcheck-0.11/changelog):

> Produce seeds that run a single failing tests instead of reproducing
all the earlier successes
([#410](UnkindPartition/tasty#410)).
>
> Seeds are now pairs instead of single integers, e.g.
`--quickcheck-replay="(SMGen 2909028190965759779
12330386376379709109,0)"`
>
> Single integer seeds are still accepted as input, but they do run
through earlier successes.
>
> The `QuickCheckReplay` type used as a tasty option has three data
constructors now. `QuickCheckReplayNone` is the default value and
provides no seed. `QuickCheckReplayLegacy` takes an integer as before.
The `QuickCheckReplay` data constructor takes the new seed form.

This is very useful both for slow tests, as well as for the WIP nightly
tests.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Feb 1, 2025
Version 0.11.1
--------------

* Add timeouts for individual tests within a property
  ([#425](UnkindPartition/tasty#425)).
* Define `showDefaultValue` for `QuickCheckTests`,
  `QuickCheckMaxSize` and `QuickCheckMaxRatio`
  ([#428](UnkindPartition/tasty#428)).
* Print the number of QuickCheck shrinks in the progress message
  ([#431](UnkindPartition/tasty#431)).
* Drop support for GHC 7.10.

Version 0.11
--------------

* Fix issues with QuickCheck progress reporting in the presence of `withMaxSuccess`
  ([#419](UnkindPartition/tasty#419)).
* Produce seeds that run a single failing tests instead of reproducing
  all the earlier successes ([#410](UnkindPartition/tasty#410)).

  Seeds are now pairs instead of single integers, e.g.
  `--quickcheck-replay="(SMGen 2909028190965759779 12330386376379709109,0)"`

  Single integer seeds are still accepted as input, but they do run through
  earlier successes.

  The `QuickCheckReplay` type used as a tasty option has three data constructors
  now. `QuickCheckReplayNone` is the default value and provides no seed.
  `QuickCheckReplayLegacy` takes an integer as before. The `QuickCheckReplay`
  data constructor takes the new seed form.
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.

QuickCheck: allow to print/specify seed for a failure without having to replay through previous successes
4 participants