diff --git a/munit/shared/src/main/scala/munit/Assertions.scala b/munit/shared/src/main/scala/munit/Assertions.scala index 40d72498..2ac37118 100644 --- a/munit/shared/src/main/scala/munit/Assertions.scala +++ b/munit/shared/src/main/scala/munit/Assertions.scala @@ -196,8 +196,10 @@ trait Assertions extends MacroCompat.CompileErrorMacro { fail(expectedExceptionMsg) } catch { case e: FailExceptionLike[_] - if !T.runtimeClass.isAssignableFrom(e.getClass()) || - e.getMessage.contains(expectedExceptionMsg) => + if !T.runtimeClass.isAssignableFrom(e.getClass()) => + throw e + case e: FailExceptionLike[_] + if e.getMessage.contains(expectedExceptionMsg) => throw e case NonFatal(e) => if (T.runtimeClass.isAssignableFrom(e.getClass())) { diff --git a/munit/shared/src/main/scala/munit/FunSuite.scala b/munit/shared/src/main/scala/munit/FunSuite.scala index 97b10629..c96bd239 100644 --- a/munit/shared/src/main/scala/munit/FunSuite.scala +++ b/munit/shared/src/main/scala/munit/FunSuite.scala @@ -2,7 +2,6 @@ package munit import scala.collection.mutable import scala.concurrent.Future -import scala.util.control.NonFatal import munit.internal.PlatformCompat import scala.concurrent.duration.Duration import scala.concurrent.duration.FiniteDuration @@ -36,7 +35,7 @@ trait BaseFunSuite try { waitForCompletion(() => munitValueTransform(body)) } catch { - case NonFatal(e) => + case e: Throwable => Future.failed(e) } }, diff --git a/tests/shared/src/test/scala/munit/FailExceptionSuite.scala b/tests/shared/src/test/scala/munit/FailExceptionSuite.scala index 33237a4c..4874adcf 100644 --- a/tests/shared/src/test/scala/munit/FailExceptionSuite.scala +++ b/tests/shared/src/test/scala/munit/FailExceptionSuite.scala @@ -1,6 +1,11 @@ package munit class FailExceptionSuite extends BaseSuite { + test("throwing an exception fails the test".fail) { + throw new RuntimeException("asdf") + println("should not reach here") + } + test("assertion-error") { val e = intercept[AssertionError] { fail("hello world!") @@ -8,7 +13,7 @@ class FailExceptionSuite extends BaseSuite { assert(clue(e).isInstanceOf[Serializable]) } -test("assertion-error-no-exception") { + test("assertion-error-no-exception") { try { intercept[AssertionError] { println("throwing no exception!")