Skip to content

Commit

Permalink
Handle assume(false) correctly (#629)
Browse files Browse the repository at this point in the history
* Handle assume(false) correctly

`assume(false)` gets now handled in the same way as `test("description".ignore")`.
Added tests to cover both ways to skip tests.

* align behaviour on all 3 platforms

* scalafmt
  • Loading branch information
mzuehlke authored Feb 22, 2023
1 parent 84f8c3b commit 5858f9e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void logTo(RichLogger logger) {
public void testIgnored(Description desc) {
postIfFirst(
desc,
new InfoEvent(desc, Status.Skipped) {
new InfoEvent(desc, Status.Ignored) {
void logTo(RichLogger logger) {
logger.warn(
settings.buildTestResult(Status.Ignored)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package org.junit

class AssumptionViolatedException(message: String) extends RuntimeException
class AssumptionViolatedException(message: String)
extends RuntimeException(message)
1 change: 1 addition & 0 deletions munit/shared/src/main/scala/munit/MUnitRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
val onError: PartialFunction[Throwable, Future[Unit]] = {
case ex: AssumptionViolatedException =>
trimStackTrace(ex)
notifier.fireTestAssumptionFailed(new Failure(description, ex))
Future.successful(())
case NonFatal(ex) =>
trimStackTrace(ex)
Expand Down
27 changes: 27 additions & 0 deletions tests/shared/src/main/scala/munit/SkippedFrameworkSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package munit

class SkippedFrameworkSuite extends FunSuite {
test("pass") {
// println("pass")
}
test("ignore".ignore) {
???
}
test("assume(true)") {
assume(true, "assume it passes")
// println("pass")
}
test("assume(false)") {
assume(false, "assume it fails")
}
}

object SkippedFrameworkSuite
extends FrameworkTest(
classOf[SkippedFrameworkSuite],
"""|==> success munit.SkippedFrameworkSuite.pass
|==> ignored munit.SkippedFrameworkSuite.ignore
|==> success munit.SkippedFrameworkSuite.assume(true)
|==> skipped munit.SkippedFrameworkSuite.assume(false) - assume it fails
|""".stripMargin
)
3 changes: 2 additions & 1 deletion tests/shared/src/test/scala/munit/FrameworkSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class FrameworkSuite extends BaseFrameworkSuite {
Issue285FrameworkSuite,
Issue497FrameworkSuite,
ScalaCheckExceptionFrameworkSuite,
BoxedFrameworkSuite
BoxedFrameworkSuite,
SkippedFrameworkSuite
)
tests.foreach { t => check(t) }
}

0 comments on commit 5858f9e

Please sign in to comment.