From bd37c21064f9871618960d49e1d4d1bf7497178c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Zu=CC=88hlke?= Date: Thu, 6 Jul 2023 09:34:24 +0200 Subject: [PATCH 1/2] In case of any Throwable inside a test mark the test as failed. --- munit/shared/src/main/scala/munit/MUnitRunner.scala | 3 +++ .../src/main/scala/munit/SwallowedExceptionSuite.scala | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/munit/shared/src/main/scala/munit/MUnitRunner.scala b/munit/shared/src/main/scala/munit/MUnitRunner.scala index a438577d..4ce99ec7 100644 --- a/munit/shared/src/main/scala/munit/MUnitRunner.scala +++ b/munit/shared/src/main/scala/munit/MUnitRunner.scala @@ -310,6 +310,9 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite) handleNonFatalOrStackOverflow(ex) case ex: StackOverflowError => handleNonFatalOrStackOverflow(ex) + case ex => + notifier.fireTestFailure(new Failure(description, ex)) + Future.successful(()) } val result: Future[Unit] = try runTestBody(notifier, description, test).recoverWith(onError) diff --git a/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala b/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala index 6bd26b16..988a3901 100644 --- a/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala +++ b/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala @@ -6,10 +6,15 @@ class SwallowedExceptionSuite extends FunSuite { test("issue-51") { throw new Exception("i am not reported") with NoStackTrace } + + test("issue-650") { + throw new IllegalAccessError("i am reported") + } } object SwallowedExceptionSuite extends FrameworkTest( classOf[SwallowedExceptionSuite], """|==> failure munit.SwallowedExceptionSuite.issue-51 - i am not reported + |==> failure munit.SwallowedExceptionSuite.issue-650 - i am reported |""".stripMargin ) From 82625dd1ceae35a67e39796c87f8f784ae7ce327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Zu=CC=88hlke?= Date: Fri, 7 Jul 2023 08:32:34 +0200 Subject: [PATCH 2/2] fail the entire suite in case of a fatal exception --- munit/shared/src/main/scala/munit/MUnitRunner.scala | 1 + .../src/main/scala/munit/SwallowedExceptionSuite.scala | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/munit/shared/src/main/scala/munit/MUnitRunner.scala b/munit/shared/src/main/scala/munit/MUnitRunner.scala index 4ce99ec7..a081d81b 100644 --- a/munit/shared/src/main/scala/munit/MUnitRunner.scala +++ b/munit/shared/src/main/scala/munit/MUnitRunner.scala @@ -311,6 +311,7 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite) case ex: StackOverflowError => handleNonFatalOrStackOverflow(ex) case ex => + suiteAborted = true notifier.fireTestFailure(new Failure(description, ex)) Future.successful(()) } diff --git a/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala b/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala index 988a3901..5428270a 100644 --- a/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala +++ b/tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala @@ -10,11 +10,16 @@ class SwallowedExceptionSuite extends FunSuite { test("issue-650") { throw new IllegalAccessError("i am reported") } + + test("should not be executed") { + assertEquals(1, 1) + } } object SwallowedExceptionSuite extends FrameworkTest( classOf[SwallowedExceptionSuite], """|==> failure munit.SwallowedExceptionSuite.issue-51 - i am not reported |==> failure munit.SwallowedExceptionSuite.issue-650 - i am reported + |==> skipped munit.SwallowedExceptionSuite.should not be executed - Suite has been aborted |""".stripMargin )