From 5858f9ef36791dcc1d24525c767f30898fc161f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Z=C3=BChlke?= Date: Wed, 22 Feb 2023 17:25:52 +0100 Subject: [PATCH] Handle assume(false) correctly (#629) * 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 --- .../junitinterface/EventDispatcher.java | 2 +- .../junit/AssumptionViolatedException.scala | 3 ++- .../src/main/scala/munit/MUnitRunner.scala | 1 + .../scala/munit/SkippedFrameworkSuite.scala | 27 +++++++++++++++++++ .../src/test/scala/munit/FrameworkSuite.scala | 3 ++- 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/shared/src/main/scala/munit/SkippedFrameworkSuite.scala diff --git a/junit-interface/src/main/java/munit/internal/junitinterface/EventDispatcher.java b/junit-interface/src/main/java/munit/internal/junitinterface/EventDispatcher.java index c5c037f0..d49a4eaa 100644 --- a/junit-interface/src/main/java/munit/internal/junitinterface/EventDispatcher.java +++ b/junit-interface/src/main/java/munit/internal/junitinterface/EventDispatcher.java @@ -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) diff --git a/munit/native/src/main/scala/org/junit/AssumptionViolatedException.scala b/munit/native/src/main/scala/org/junit/AssumptionViolatedException.scala index 97194903..4e027030 100644 --- a/munit/native/src/main/scala/org/junit/AssumptionViolatedException.scala +++ b/munit/native/src/main/scala/org/junit/AssumptionViolatedException.scala @@ -1,3 +1,4 @@ package org.junit -class AssumptionViolatedException(message: String) extends RuntimeException +class AssumptionViolatedException(message: String) + extends RuntimeException(message) diff --git a/munit/shared/src/main/scala/munit/MUnitRunner.scala b/munit/shared/src/main/scala/munit/MUnitRunner.scala index 1982e2a2..9a2bd48a 100644 --- a/munit/shared/src/main/scala/munit/MUnitRunner.scala +++ b/munit/shared/src/main/scala/munit/MUnitRunner.scala @@ -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) diff --git a/tests/shared/src/main/scala/munit/SkippedFrameworkSuite.scala b/tests/shared/src/main/scala/munit/SkippedFrameworkSuite.scala new file mode 100644 index 00000000..fb632b09 --- /dev/null +++ b/tests/shared/src/main/scala/munit/SkippedFrameworkSuite.scala @@ -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 + ) diff --git a/tests/shared/src/test/scala/munit/FrameworkSuite.scala b/tests/shared/src/test/scala/munit/FrameworkSuite.scala index 4a65d88d..d91ef2df 100644 --- a/tests/shared/src/test/scala/munit/FrameworkSuite.scala +++ b/tests/shared/src/test/scala/munit/FrameworkSuite.scala @@ -31,7 +31,8 @@ class FrameworkSuite extends BaseFrameworkSuite { Issue285FrameworkSuite, Issue497FrameworkSuite, ScalaCheckExceptionFrameworkSuite, - BoxedFrameworkSuite + BoxedFrameworkSuite, + SkippedFrameworkSuite ) tests.foreach { t => check(t) } }