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

In case of any Throwable inside a test mark the test as failed. #669

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions munit/shared/src/main/scala/munit/MUnitRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
handleNonFatalOrStackOverflow(ex)
case ex: StackOverflowError =>
handleNonFatalOrStackOverflow(ex)
case ex =>
Copy link

@filipwiech filipwiech Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a fatal exception, would it then make sense to abort the suite, or not really/it doesn't matter? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good idea 👍

suiteAborted = true
notifier.fireTestFailure(new Failure(description, ex))
Future.successful(())
}
val result: Future[Unit] =
try runTestBody(notifier, description, test).recoverWith(onError)
Expand Down
10 changes: 10 additions & 0 deletions tests/shared/src/main/scala/munit/SwallowedExceptionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ 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")
}

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
)