Skip to content

Commit

Permalink
Merge pull request #210 from armanbilge/patch-2
Browse files Browse the repository at this point in the history
Update to munit 1.0.0-M6
  • Loading branch information
armanbilge authored Aug 3, 2022
2 parents 4271587 + d4cb826 commit 3e4369b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ThisBuild / tlBaseVersion := "1.0"
ThisBuild / tlBaseVersion := "2.0"

ThisBuild / developers += tlGitHubDev("mpilquist", "Michael Pilquist")
ThisBuild / startYear := Some(2021)
Expand Down Expand Up @@ -28,7 +28,7 @@ lazy val munit = crossProject(JSPlatform, JVMPlatform)
.dependsOn(core)
.settings(
libraryDependencies ++= List(
"org.scalameta" %%% "munit-scalacheck" % "0.7.29",
"org.scalameta" %%% "munit-scalacheck" % "1.0.0-M6",
"org.typelevel" %%% "cats-effect" % "3.3.14" % Test
)
)
23 changes: 5 additions & 18 deletions munit/shared/src/main/scala/munit/ScalaCheckEffectSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
package munit

import cats.implicits._
import org.scalacheck.{Gen, Test}
import org.scalacheck.{Gen, Test => ScalaCheckTest}
import org.scalacheck.Test.PropException
import org.scalacheck.effect.PropF
import org.scalacheck.rng.Seed
import org.scalacheck.util.Pretty

import java.lang.reflect.{InvocationTargetException, UndeclaredThrowableException}
import scala.annotation.tailrec
import scala.concurrent.ExecutionException

/** Extends `ScalaCheckSuite`, adding support for evaluation of effectful properties (`PropF[F]`
* values).
*
Expand All @@ -51,7 +47,7 @@ trait ScalaCheckEffectSuite extends ScalaCheckSuite {
val testResultTransform =
new ValueTransform(
"ScalaCheck TestResult",
{ case p: Test.Result =>
{ case p: ScalaCheckTest.Result =>
super.munitValueTransform(parseTestResult(p))
}
)
Expand All @@ -72,7 +68,7 @@ trait ScalaCheckEffectSuite extends ScalaCheckSuite {
prop.check(scalaCheckTestParameters, genParameters).map(fixResultException).map(parseTestResult)
}

private def parseTestResult(result: Test.Result)(implicit loc: Location): Unit = {
private def parseTestResult(result: ScalaCheckTest.Result)(implicit loc: Location): Unit = {
if (!result.passed) {
val seed = genParameters.initialSeed.get
val seedMessage =
Expand All @@ -85,23 +81,14 @@ trait ScalaCheckEffectSuite extends ScalaCheckSuite {
}
}

private def fixResultException(result: Test.Result): Test.Result =
private def fixResultException(result: ScalaCheckTest.Result): ScalaCheckTest.Result =
result.copy(
status = result.status match {
case p @ PropException(_, e, _) => p.copy(e = rootCause(e))
case p @ PropException(_, e, _) => p.copy(e = Exceptions.rootCause(e))
case default => default
}
)

// https://github.com/scalameta/munit/blob/68c2d13868baec9a77384f11f97505ecc0ce3eba/munit/shared/src/main/scala/munit/MUnitRunner.scala#L318-L326
@tailrec
private def rootCause(x: Throwable): Throwable = x match {
case _: InvocationTargetException | _: ExceptionInInitializerError |
_: UndeclaredThrowableException | _: ExecutionException if x.getCause != null =>
rootCause(x.getCause)
case _ => x
}

}

object ScalaCheckEffectSuite {}

0 comments on commit 3e4369b

Please sign in to comment.