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

Handle assume(false) correctly #629

Merged
merged 3 commits into from
Feb 22, 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
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) }
}