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

Print property seeds and add docs about reproducing test failures #90

Merged
merged 3 commits into from
Apr 1, 2020

Conversation

gabro
Copy link
Member

@gabro gabro commented Mar 29, 2020

Previously we would not print seeds when a property would fail, so it would be impossible to deterministically reproduce a failure.
Now we print the seed when a property fails and we added docs to explain how to reproduce failures

Comment on lines 58 to 59
val seed = scalaCheckTestParameters.initialSeed.getOrElse(Seed.random())
val result = check(scalaCheckTestParameters, prop.useSeed(test.name, seed))
Copy link
Member Author

Choose a reason for hiding this comment

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

The ScalaCheck runner uses prop.viewSeed(name, seed) but that causes the prop to use an hardcoded println to output the seed, which would look quite messy since it appears before the test failure in the output.

Instead, we determine the seed in the same way ScalaCheck does (getting it from the parameters or falling back to a random one) and inject it in the property using useSeed (which is what propertyWithSeed does in ScalaCheck)

Now we're free to print the seed ourselves, which looks much better and more consistent with the rest of the failure message.

Comment on lines 39 to 44
implicit class XtensionScalaCheckTestParameters(
params: ScalaCheckTest.Parameters
) {
def withInitialSeed(encodedSeed: String): ScalaCheckTest.Parameters =
params.withInitialSeed(Seed.fromBase64(encodedSeed).get)
}
Copy link
Member Author

@gabro gabro Mar 29, 2020

Choose a reason for hiding this comment

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

ScalaCheck does something analogous in propertyWithSeed, and I think it makes sense (since we print the Base64 encoded form in test failures)

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

It seems like a regression to declare the seed as a string instead of int, why do we need to use base64 encoded strings?

docs/integrations/scalacheck.md Outdated Show resolved Hide resolved
@gabro
Copy link
Member Author

gabro commented Mar 29, 2020

ScalaCheck itself uses base64 encoded seeds in the output. See an example here https://gist.github.com/non/aeef5824b3f681b9cfc141437b16b014

You can still use Long if you prefer, but I preferred to stay consistent with the default ScalaCheck runner

@olafurpg
Copy link
Member

Using a Base64 encoded string is fine.

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍


To reproduce the failure you can follow the suggestion to fix the seed:

```scala
Copy link
Member

Choose a reason for hiding this comment

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

In these cases I normally use the diff language to highlight what's changed

 class MySuite extends ScalaCheckSuite {
+   override val scalaCheckInitialSeed = "CTH6hXj8ViScMmsO78-k4_RytXHPK_wSJYNH2h4dCpB="
    // ...
 }

Copy link
Member Author

Choose a reason for hiding this comment

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

nice idea 👍 done!

@gabro gabro merged commit 0d5b12a into scalameta:master Apr 1, 2020
@gabro gabro deleted the seeds branch April 1, 2020 10:03
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