diff --git a/build.sbt b/build.sbt index ced04fc7..993e0855 100644 --- a/build.sbt +++ b/build.sbt @@ -270,32 +270,8 @@ lazy val plugin = project ) .disablePlugins(MimaPlugin) -lazy val munitScalacheck = crossProject(JSPlatform, JVMPlatform, NativePlatform) - .in(file("munit-scalacheck")) - .dependsOn(munit) - .settings( - moduleName := "munit-scalacheck", - sharedSettings, - libraryDependencies += { - "org.scalacheck" %%% "scalacheck" % "1.18.0" - } - ) - .jvmSettings( - sharedJVMSettings - ) - .nativeConfigure(sharedNativeConfigure) - .nativeSettings( - sharedNativeSettings - ) - .jsConfigure(sharedJSConfigure) - .jsSettings(sharedJSSettings) - -lazy val munitScalacheckJVM = munitScalacheck.jvm -lazy val munitScalacheckJS = munitScalacheck.js -lazy val munitScalacheckNative = munitScalacheck.native - lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform) - .dependsOn(munit, munitScalacheck) + .dependsOn(munit) .enablePlugins(BuildInfoPlugin) .settings( sharedSettings, @@ -338,13 +314,14 @@ lazy val testsNative = tests.native lazy val docs = project .in(file("munit-docs")) - .dependsOn(munitJVM, munitScalacheckJVM) + .dependsOn(munitJVM) .enablePlugins(MdocPlugin, DocusaurusPlugin) .disablePlugins(MimaPlugin) .settings( sharedSettings, publish / skip := true, moduleName := "munit-docs", + libraryDependencies += "org.scalameta" %% "munit-scalacheck" % "1.0.0-M11", crossScalaVersions := List(scala213, scala212), test := {}, mdocOut := diff --git a/munit-scalacheck/shared/src/main/scala/munit/ScalaCheckFailException.scala b/munit-scalacheck/shared/src/main/scala/munit/ScalaCheckFailException.scala deleted file mode 100644 index 8cc8f07b..00000000 --- a/munit-scalacheck/shared/src/main/scala/munit/ScalaCheckFailException.scala +++ /dev/null @@ -1,11 +0,0 @@ -package munit - -import scala.util.control.NoStackTrace - -@deprecated( - "This class is not used anywhere and will be removed in a future release", - "0.8.0" -) -class ScalaCheckFailException(message: String) - extends Exception(message) - with NoStackTrace diff --git a/munit-scalacheck/shared/src/main/scala/munit/ScalaCheckSuite.scala b/munit-scalacheck/shared/src/main/scala/munit/ScalaCheckSuite.scala deleted file mode 100644 index 0efa550b..00000000 --- a/munit-scalacheck/shared/src/main/scala/munit/ScalaCheckSuite.scala +++ /dev/null @@ -1,108 +0,0 @@ -package munit - -import org.scalacheck.Prop -import org.scalacheck.{Test => ScalaCheckTest} -import org.scalacheck.util.Pretty -import org.scalacheck.rng.Seed -import scala.util.Success -import scala.util.Failure -import scala.util.Try -import munit.internal.FutureCompat._ - -trait ScalaCheckSuite extends FunSuite { - def property( - name: String - )(body: => Prop)(implicit loc: Location): Unit = { - property(new TestOptions(name, Set.empty, loc))(body) - } - - def property( - options: TestOptions - )(body: => Prop)(implicit loc: Location): Unit = { - test(options)(body) - } - - // Allow property bodies of type Unit - // This is done to support using MUnit assertions in property bodies - // instead of returning a Boolean. - implicit def unitToProp(unit: Unit): Prop = Prop.passed - - override def munitTestTransforms: List[TestTransform] = - scalaCheckPropTransform +: super.munitTestTransforms - - protected def scalaCheckTestParameters = ScalaCheckTest.Parameters.default - - protected def scalaCheckPrettyParameters = Pretty.defaultParams - - protected def scalaCheckInitialSeed: String = Seed.random().toBase64 - - private val scalaCheckPropTransform: TestTransform = - new TestTransform( - "ScalaCheck Prop", - t => { - t.withBodyMap( - _.transformCompat { - case Success(prop: Prop) => propToTry(prop, t) - case r => r - }(munitExecutionContext) - ) - } - ) - - private def propToTry(prop: Prop, test: Test): Try[Unit] = { - import ScalaCheckTest._ - def makeSeed() = - scalaCheckTestParameters.initialSeed.getOrElse( - Seed.fromBase64(scalaCheckInitialSeed).get - ) - val initialSeed = makeSeed() - var seed: Seed = initialSeed - val result = check( - scalaCheckTestParameters, - Prop { genParams => - val r = prop(genParams.withInitialSeed(seed)) - seed = seed.next - r - } - ) - def renderResult(r: Result): String = { - val resultMessage = Pretty.pretty(r, scalaCheckPrettyParameters) - if (r.passed) { - resultMessage - } else { - val seedMessage = - s"""|Failing seed: ${initialSeed.toBase64} - |You can reproduce this failure by adding the following override to your suite: - | - | override def scalaCheckInitialSeed = "${initialSeed.toBase64}" - |""".stripMargin - seedMessage + "\n" + resultMessage - } - } - - result.status match { - case Passed | Proved(_) => - Success(()) - case status @ PropException(_, e, _) => - e match { - case f: FailExceptionLike[_] => - // Promote FailException (i.e failed assertions) to property failures - val r = result.copy(status = Failed(status.args, status.labels)) - Failure(f.withMessage(e.getMessage() + "\n\n" + renderResult(r))) - case _ => - Failure( - new FailException( - message = renderResult(result), - cause = e, - isStackTracesEnabled = false, - location = test.location - ) - ) - } - case _ => - // Fail using the test location - Try(fail("\n" + renderResult(result))(test.location)) - } - } - -} diff --git a/tests/shared/src/main/scala/munit/ScalaCheckExceptionFrameworkSuite.scala b/tests/shared/src/main/scala/munit/ScalaCheckExceptionFrameworkSuite.scala deleted file mode 100644 index 32bce8dc..00000000 --- a/tests/shared/src/main/scala/munit/ScalaCheckExceptionFrameworkSuite.scala +++ /dev/null @@ -1,72 +0,0 @@ -package munit - -import org.scalacheck.Prop - -class ScalaCheckExceptionFrameworkSuite extends ScalaCheckSuite { - override val scalaCheckInitialSeed = - "9WNU_CSZAQwiiPWDlHs4NWI-knIDEKCsgGqdhZgNKnB=" - - property("hide my stacks") { - Prop.forAll { (i: Int) => - throw new StackOverflowError() - Prop(true) - } - } -} - -// NOTE(olafur): extracted this object into a class to avoid the following error with Dotty -// ==> X munit.FrameworkSuite.initializationError 0.002s java.lang.VerifyError: Bad type on operand stack -// Exception Details: -// Location: -// munit/ScalaCheckExceptionFrameworkSuite$.()V @19: invokedynamic -// Reason: -// Type uninitializedThis (current frame, stack[0]) is not assignable to 'munit/ScalaCheckExceptionFrameworkSuite$' -// Current Frame: -// bci: @19 -// flags: { flagThisUninit } -// locals: { uninitializedThis, 'java/lang/Class', 'java/lang/String' } -// stack: { uninitializedThis } -// Bytecode: -// 0x0000000: 1210 4cb2 0015 b200 1a12 1cb6 0020 b600 -// 0x0000010: 234d 2aba 0037 0000 4eb2 003c b600 403a -// 0x0000020: 04b2 003c b600 443a 05b2 003c b600 483a -// 0x0000030: 062a 2b2c 1904 1905 1906 2dbb 004a 5912 -// 0x0000040: 4c10 33b7 004f b700 522a b300 54b1 -// -// FrameworkSuite.(FrameworkSuite.scala:30) -class ScalaCheckExceptionFrameworkSuites - extends FrameworkTest( - classOf[ScalaCheckExceptionFrameworkSuite], - """|munit.ScalaCheckExceptionFrameworkSuite.$anonfun$new$2(ScalaCheckExceptionFrameworkSuite.scala:11) - |munit.ScalaCheckExceptionFrameworkSuite.$anonfun$new$2$adapted(ScalaCheckExceptionFrameworkSuite.scala:10) - |==> failure munit.ScalaCheckExceptionFrameworkSuite.hide my stacks - Failing seed: 9WNU_CSZAQwiiPWDlHs4NWI-knIDEKCsgGqdhZgNKnB= - |You can reproduce this failure by adding the following override to your suite: - | - | override def scalaCheckInitialSeed = "9WNU_CSZAQwiiPWDlHs4NWI-knIDEKCsgGqdhZgNKnB=" - | - |Exception raised on property evaluation. - |> ARG_0: 0 - |> ARG_0_ORIGINAL: -860854860 - |> Exception: java.lang.StackOverflowError: null - |""".stripMargin, - tags = Set(OnlyJVM), - onEvent = { event => - if ( - event.throwable().isDefined() && - event.throwable().get().getCause() != null - ) { - event - .throwable() - .get() - .getCause - .getStackTrace() - .take(2) - .mkString("", "\n", "\n") - } else { - "" - } - } - ) - -object ScalaCheckExceptionFrameworkSuite - extends ScalaCheckExceptionFrameworkSuites diff --git a/tests/shared/src/main/scala/munit/ScalaCheckFrameworkSuite.scala b/tests/shared/src/main/scala/munit/ScalaCheckFrameworkSuite.scala deleted file mode 100644 index 15f34680..00000000 --- a/tests/shared/src/main/scala/munit/ScalaCheckFrameworkSuite.scala +++ /dev/null @@ -1,90 +0,0 @@ -package munit - -import org.scalacheck.Prop.forAll - -class ScalaCheckFrameworkSuite extends ScalaCheckSuite { - - // NOTE(gabro): this is needed for making the test output stable for the failed test below. - // It also serves as a test for overriding this parameter - override val scalaCheckInitialSeed = - "CTH6hXj8ViScMmsO78-k4_RytXHPK_wSJYNH2h4dCpB=" - - property("boolean check (true)") { - forAll { (l1: List[Int], l2: List[Int]) => - l1.size + l2.size == (l1 ::: l2).size - } - } - - property("boolean check (false)") { - forAll { (n: Int) => scala.math.sqrt(n * n) == n } - } - - property("tagged".tag(new Tag("a"))) { - forAll { (n: Int) => n + 0 == n } - } - - property("assertions (true)") { - forAll { (n: Int) => - assertEquals(n * 2, n + n) - assertEquals(n * 0, 0) - } - } - - property("assertions (false)") { - forAll { (n: Int) => - assertEquals(n * 1, n) - assertEquals(n * n, n) - assertEquals(n + 0, n) - } - } - - override def munitFlakyOK: Boolean = true - test("flaky test".flaky) { - forAll { (i: Int) => - assertEquals(1, 0) - } - } - -} - -object ScalaCheckFrameworkSuite - extends FrameworkTest( - classOf[ScalaCheckFrameworkSuite], - """|==> success munit.ScalaCheckFrameworkSuite.boolean check (true) - |==> failure munit.ScalaCheckFrameworkSuite.boolean check (false) - /scala/munit/ScalaCheckFrameworkSuite.scala:18 - |17: - |18: property("boolean check (false)") { - |19: forAll { (n: Int) => scala.math.sqrt(n * n) == n } - | - |Failing seed: CTH6hXj8ViScMmsO78-k4_RytXHPK_wSJYNH2h4dCpB= - |You can reproduce this failure by adding the following override to your suite: - | - | override def scalaCheckInitialSeed = "CTH6hXj8ViScMmsO78-k4_RytXHPK_wSJYNH2h4dCpB=" - | - |Falsified after 0 passed tests. - |> ARG_0: -1 - |> ARG_0_ORIGINAL: 2147483647 - |==> success munit.ScalaCheckFrameworkSuite.tagged - |==> success munit.ScalaCheckFrameworkSuite.assertions (true) - |==> failure munit.ScalaCheckFrameworkSuite.assertions (false) - /scala/munit/ScalaCheckFrameworkSuite.scala:36 - |35: assertEquals(n * 1, n) - |36: assertEquals(n * n, n) - |37: assertEquals(n + 0, n) - |values are not the same - |=> Obtained - |1 - |=> Diff (- obtained, + expected) - |-1 - |+-1 - | - |Failing seed: CTH6hXj8ViScMmsO78-k4_RytXHPK_wSJYNH2h4dCpB= - |You can reproduce this failure by adding the following override to your suite: - | - | override def scalaCheckInitialSeed = "CTH6hXj8ViScMmsO78-k4_RytXHPK_wSJYNH2h4dCpB=" - | - |Falsified after 0 passed tests. - |> ARG_0: -1 - |> ARG_0_ORIGINAL: 2147483647 - |==> skipped munit.ScalaCheckFrameworkSuite.flaky test - ignoring flaky test failure - |""".stripMargin - ) diff --git a/tests/shared/src/test/scala/munit/CustomPrinterSuite.scala b/tests/shared/src/test/scala/munit/CustomPrinterSuite.scala deleted file mode 100644 index 610a9d10..00000000 --- a/tests/shared/src/test/scala/munit/CustomPrinterSuite.scala +++ /dev/null @@ -1,139 +0,0 @@ -package munit - -import org.scalacheck.Prop.forAll -import munit.internal.console.Printers -import org.scalacheck.Arbitrary.arbitrary -import org.scalacheck.Prop - -class CustomPrinterSuite extends FunSuite with ScalaCheckSuite { - - private case class Foo(i: Int) - - private case class Bar(l: List[Int]) - - private case class FooBar(foo: Foo, bar: Bar) - - private val genFoo = arbitrary[Int].map(Foo(_)) - - // limit size to 10 to have a reasonable number of values - private val genBar = arbitrary[List[Int]].map(l => Bar(l.take(10))) - - private val genFooBar = for { - foo <- genFoo - bar <- genBar - } yield FooBar(foo, bar) - - private val longPrinter: Printer = Printer.apply { case l: Long => - s"MoreThanInt($l)" - } - - private val fooPrinter: Printer = Printer.apply { case Foo(i) => - s"Foo(INT($i))" - } - - private val listPrinter: Printer = Printer.apply { case l: List[_] => - l.mkString("[", ",", "]") - } - - private val intPrinter: Printer = Printer.apply { case i: Int => - s"NotNaN($i)" - } - - private val isScala213: Boolean = BuildInfo.scalaVersion.startsWith("2.13") - - private def checkProp( - options: TestOptions, - isEnabled: Boolean = true - )(p: => Prop): Unit = { - test(options) { - assume(isEnabled, "disabled test") - p - } - } - - checkProp("long") { - forAll(arbitrary[Long]) { (l: Long) => - val obtained = Printers.print(l, longPrinter) - val expected = s"MoreThanInt($l)" - assertEquals(obtained, expected) - } - } - - checkProp("list") { - forAll(arbitrary[List[Int]]) { l => - val obtained = Printers.print(l, listPrinter) - val expected = l.mkString("[", ",", "]") - assertEquals(obtained, expected) - } - } - - checkProp("product") { - forAll(genFoo) { foo => - val obtained = Printers.print(foo, fooPrinter) - val expected = s"Foo(INT(${foo.i}))" - assertEquals(obtained, expected) - } - } - - checkProp("int in product", isEnabled = isScala213) { - forAll(genFoo) { foo => - val obtained = Printers.print(foo, intPrinter) - val expected = s"Foo(\n i = NotNaN(${foo.i})\n)" - assertEquals(obtained, expected) - } - } - - checkProp("list in product", isEnabled = isScala213) { - forAll(genBar) { bar => - val obtained = Printers.print(bar, listPrinter) - val expected = s"Bar(\n l = ${bar.l.mkString("[", ",", "]")}\n)" - assertEquals(obtained, expected) - } - } - - checkProp("list and int in product", isEnabled = isScala213) { - forAll(genFooBar) { foobar => - val obtained = Printers - .print(foobar, listPrinter.orElse(intPrinter)) - .filterNot(_.isWhitespace) - val expected = - s"""|FooBar( - | foo = Foo( - | i = NotNaN(${foobar.foo.i}) - | ), - | bar = Bar( - | l = ${foobar.bar.l.mkString("[", ",", "]")} - | ) - |) - |""".stripMargin.filterNot(_.isWhitespace) - assertEquals(obtained, expected) - } - } - - checkProp("all ints in product", isEnabled = isScala213) { - forAll(genFooBar) { foobar => - val obtained = Printers - .print(foobar, intPrinter) - .filterNot(_.isWhitespace) - - val expectedbBarList = foobar.bar.l match { - case Nil => "Nil" - case l => - l.map(i => s"NotNaN($i)").mkString("List(", ",", ")") - } - - val expected = - s"""|FooBar( - | foo = Foo( - | i = NotNaN(${foobar.foo.i}) - | ), - | bar = Bar( - | l = $expectedbBarList - | ) - |) - |""".stripMargin.filterNot(_.isWhitespace) - assertEquals(obtained, expected) - } - } - -} diff --git a/tests/shared/src/test/scala/munit/FrameworkSuite.scala b/tests/shared/src/test/scala/munit/FrameworkSuite.scala index e0f1c44f..44d2ff97 100644 --- a/tests/shared/src/test/scala/munit/FrameworkSuite.scala +++ b/tests/shared/src/test/scala/munit/FrameworkSuite.scala @@ -20,7 +20,6 @@ class FrameworkSuite extends BaseFrameworkSuite { TestTransformFrameworkSuite, ValueTransformCrashFrameworkSuite, ValueTransformFrameworkSuite, - ScalaCheckFrameworkSuite, AsyncFunFixtureFrameworkSuite, AsyncFixtureTeardownFrameworkSuite, DuplicateNameFrameworkSuite, @@ -31,7 +30,6 @@ class FrameworkSuite extends BaseFrameworkSuite { Issue285FrameworkSuite, Issue497FrameworkSuite, Issue583FrameworkSuite, - ScalaCheckExceptionFrameworkSuite, BoxedFrameworkSuite, SkippedFrameworkSuite ) diff --git a/tests/shared/src/test/scala/munit/ScalaCheckInitialSeedSuite.scala b/tests/shared/src/test/scala/munit/ScalaCheckInitialSeedSuite.scala deleted file mode 100644 index dd95f5d2..00000000 --- a/tests/shared/src/test/scala/munit/ScalaCheckInitialSeedSuite.scala +++ /dev/null @@ -1,23 +0,0 @@ -package munit - -import scala.collection.mutable -import org.scalacheck.Prop.forAll - -final class ScalaCheckInitialSeedSuite extends ScalaCheckSuite { - - // initial seed should be used for the first out of 100 `minSuccessfulTests` only - override val scalaCheckInitialSeed = - "9SohH7wEYXCdXK4b9yM2d6TKIN2jBFcBs4QBta-2yTD=" - 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) - } -} diff --git a/tests/shared/src/test/scala/munit/ScalaCheckSeedSuite.scala b/tests/shared/src/test/scala/munit/ScalaCheckSeedSuite.scala deleted file mode 100644 index 79dd2340..00000000 --- a/tests/shared/src/test/scala/munit/ScalaCheckSeedSuite.scala +++ /dev/null @@ -1,21 +0,0 @@ -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) - } -}