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

Extract real exception for munit with Future #196

Merged
merged 2 commits into from
Apr 29, 2022
Merged

Extract real exception for munit with Future #196

merged 2 commits into from
Apr 29, 2022

Conversation

andrzejressel
Copy link
Contributor

When using munit exception in Future, these exceptions are additionally wrapped in ExecutionException. That causes test failure to lose its context:

==> X munit.Example.three  0.063s munit.FailException: scalacheck-effect\munit\shared\src\main\scala\munit\ScalaCheckEffectSuite.scala:52
51:      { case p: PropF[f] =>
52:        super.munitValueTransform(checkPropF[f](p))
53:      }
Failing seed: _6dy7RwgZvdFcKb-_3Y6drdCAgSpLtmNv3gD0gMvqOJ=
You can reproduce this failure by adding the following override to your suite:

  override def scalaCheckInitialSeed = "_6dy7RwgZvdFcKb-_3Y6drdCAgSpLtmNv3gD0gMvqOJ="

Exception raised on property evaluation.
> ARG_0: 0
> ARG_1: 0
> ARG_0_ORIGINAL: 507884176
> ARG_1_ORIGINAL: 1
> Exception: java.util.concurrent.ExecutionException: Boxed Exception
    at munit.Assertions.fail(Assertions.scala:283)
    at munit.Assertions.fail$(Assertions.scala:277)
    at munit.FunSuite.fail(FunSuite.scala:11)
    at munit.ScalaCheckEffectSuite.$anonfun$checkPropF$1(ScalaCheckEffectSuite.scala:69)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)

This pull request introduces proper exception extraction just like munit itself does:

==> X munit.Example.three  0.078s munit.FailException: scalacheck-effect\munit\shared\src\main\scala\munit\ScalaCheckEffectSuite.scala:60
59:      { case p: PropF[f] =>
60:        super.munitValueTransform(checkPropF[f](p))
61:      }
Failing seed: 2ZteDaQ-7jWeBpOv8dlnj5csn65IF5mqhIJrBwKVbDC=
You can reproduce this failure by adding the following override to your suite:

  override def scalaCheckInitialSeed = "2ZteDaQ-7jWeBpOv8dlnj5csn65IF5mqhIJrBwKVbDC="

Exception raised on property evaluation.
> ARG_0: 0
> ARG_1: 0
> ARG_0_ORIGINAL: -1848315845
> ARG_1_ORIGINAL: -1
> Exception: munit.ComparisonFailException: scalacheck-effect\munit\shared\src\test\scala\munit\Example.scala:47
46:    PropF.forAllF { (a: Int, b: Int) =>
47:      Future { assertEquals(a + b, b + a + 1) }
48:    }
values are not the same
=> Obtained
0
=> Diff (- obtained, + expected)
-0
+1
    at munit.Assertions.fail(Assertions.scala:283)
    at munit.Assertions.fail$(Assertions.scala:277)
    at munit.FunSuite.fail(FunSuite.scala:11)
    at munit.ScalaCheckEffectSuite.$anonfun$checkPropF$2(ScalaCheckEffectSuite.scala:77)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)

@mpilquist
Copy link
Member

Thanks! Could you run prePR to fix the formatting issues?

@andrzejressel
Copy link
Contributor Author

Fixed

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