Skip to content

Commit

Permalink
Merge pull request #63 from olafurpg/hello-world
Browse files Browse the repository at this point in the history
Fix buggy filtering examples from blog post.
  • Loading branch information
olafurpg authored Mar 8, 2020
2 parents cb87436 + 516bea3 commit 775f73e
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 @@ -212,6 +212,10 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
}

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 Down Expand Up @@ -239,34 +243,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 775f73e

Please sign in to comment.