Skip to content

Commit

Permalink
Fix buggy filtering examples from blog post.
Browse files Browse the repository at this point in the history
Previously, the "rich filtering capabilities" examples from the initial
MUnit release announcement for v0.3 did not work as expected because of
the async changes in v0.5. This commit fixes the example and improves
the handling of tests with the Ignore tag.
  • Loading branch information
Olafur Pall Geirsson committed Mar 8, 2020
1 parent 1301010 commit 516bea3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 0 additions & 2 deletions munit/shared/src/main/scala/munit/FunSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ abstract class FunSuite
munitExpectFailure(options, body)
} else if (options.tags(Flaky)) {
munitFlaky(options, body)
} else if (options.tags(Ignore)) {
Future.successful(Ignore)
} else {
body()
}
Expand Down
22 changes: 14 additions & 8 deletions munit/shared/src/main/scala/munit/MUnitRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
return Future.successful(false)
}
notifier.fireTestStarted(description)
if (test.tags(Ignore)) {
notifier.fireTestIgnored(description)
return Future.successful(false)
}
val onError: PartialFunction[Throwable, Future[Unit]] = {
case ex: AssumptionViolatedException =>
StackTraces.trimStackTrace(ex)
Expand All @@ -225,34 +229,36 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
}
}

private def futureFromAny(any: Any): Future[Any] = any match {
case f: Future[_] => f
case _ => Future.successful(any)
}

private def runTestBody(
notifier: RunNotifier,
description: Description,
test: suite.Test
): Future[Unit] = {
val result = StackTraces.dropOutside {
val result: Future[Any] = StackTraces.dropOutside {
val beforeEachResult = runBeforeEach(test)
beforeEachResult.error match {
val any = beforeEachResult.error match {
case None =>
try test.body()
finally runAfterEach(test, beforeEachResult.loadedFixtures)
case Some(error) =>
try runAfterEach(test, beforeEachResult.loadedFixtures)
finally throw error
}
futureFromAny(any)
}
result match {
result.map {
case f: TestValues.FlakyFailure =>
StackTraces.trimStackTrace(f)
notifier.fireTestAssumptionFailed(new Failure(description, f))
Future.successful(())
case TestValues.Ignore =>
notifier.fireTestIgnored(description)
Future.successful(())
case f: Future[_] =>
f.map(_ => ())
case _ =>
Future.successful(())
()
}
}

Expand Down
6 changes: 3 additions & 3 deletions website/blog/2020-02-01-hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ import scala.util.Properties
import munit._
object Windows213 extends Tag("Windows213")
class MySuite extends FunSuite {
// reminder: type Test = GenericTest[Any]
// reminder: type Test = GenericTest[Future[Any]]
override def munitNewTest(test: Test): Test = {
val isIgnored =
options.tags(Windows213) && !(
test.tags(Windows213) && !(
Properties.isWin &&
Properties.versionNumberString.startsWith("2.13")
)
if (isIgnored) test.withBody(() => Ignore)
if (isIgnored) test.tag(Ignore)
else test
}

Expand Down

0 comments on commit 516bea3

Please sign in to comment.