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

Regenerate default seed at every prop iteration #124

Merged
merged 2 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ trait ScalaCheckSuite extends FunSuite {

private def propToTry(prop: Prop, test: Test): Try[Unit] = {
import ScalaCheckTest._
val seed =
def seed =
scalaCheckTestParameters.initialSeed.getOrElse(
Seed.fromBase64(scalaCheckInitialSeed).get
)
val result = check(scalaCheckTestParameters, prop.useSeed(test.name, seed))
val result = check(
scalaCheckTestParameters,
Prop(genParams => prop(genParams.withInitialSeed(seed)))
)
Comment on lines +52 to +59
Copy link
Member Author

Choose a reason for hiding this comment

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

this way if the user hasn't overridden the default seed, we recompute it in the Prop lambda (which is what viewSeed does in vanilla ScalaCheck)

def renderResult(r: Result) = {
val resultMessage = Pretty.pretty(r, scalaCheckPrettyParameters)
if (r.passed) {
Expand Down
21 changes: 21 additions & 0 deletions tests/shared/src/test/scala/munit/ScalaCheckSeedSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package munit

import scala.collection.mutable
import org.scalacheck.Prop.forAll

// Regression test for https://github.com/scalameta/munit/issues/118
final class ScalaCheckSeedSuite extends ScalaCheckSuite {

private val ints = mutable.Set.empty[Int]

property("generating int") {
forAll { (i: Int) =>
ints.add(i)
true
}
}

test("generated int are not all the same") {
assert(ints.size > 1)
}
}