Skip to content

Commit

Permalink
Fix scalameta#497 - don't load fixtures for empty test suites
Browse files Browse the repository at this point in the history
Previously, MUnit loaded fixtures even for test suites that had no
tests. Now, we skip the entire suite if there are no tests to run.
  • Loading branch information
olafurpg committed Mar 5, 2022
1 parent 9653a0e commit d5a9fce
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion munit/shared/src/main/scala/munit/MUnitRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)
}

private def runAll(notifier: RunNotifier): Future[Unit] = {
if (PlatformCompat.isIgnoreSuite(cls)) {
if (PlatformCompat.isIgnoreSuite(cls) || munitTests.isEmpty) {
val description = getDescription()
notifier.fireTestIgnored(description)
return Future.successful(())
Expand Down
44 changes: 44 additions & 0 deletions tests/shared/src/main/scala/munit/Issue497FrameworkSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package munit

import org.junit.experimental.categories.Category

class Slow extends Tag("Slow")

@Category(Array(classOf[Slow]))
class Issue497FrameworkSuite extends FunSuite {
def println(msg: String): Unit = TestingConsole.out.println(msg)
val myFixture = new Fixture[Unit]("myFixture") {
def apply(): Unit = println("### myFixture apply() ###")

override def beforeAll(): Unit = {
println("### beforeAll is running ###")
}

override def afterAll(): Unit = {
println("### afterAll is running ###")
}
}
override def munitFixtures = List(myFixture)

test("test1") {
myFixture()
assertEquals(1, 1)
}

test("test2") {
myFixture()
assertEquals(1, 1)
}
}

object Issue497FrameworkSuite
extends FrameworkTest(
classOf[Issue497FrameworkSuite],
"""|munit.Issue497FrameworkSuite:
|""".stripMargin,
arguments = Array("--exclude-categories=munit.Slow"),
tags = Set(
OnlyJVM
),
format = StdoutFormat
)
1 change: 1 addition & 0 deletions tests/shared/src/test/scala/munit/FrameworkSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FrameworkSuite extends BaseFrameworkSuite {
AssertionsFrameworkSuite,
Issue179FrameworkSuite,
Issue285FrameworkSuite,
Issue497FrameworkSuite,
ScalaCheckExceptionFrameworkSuite,
BoxedFrameworkSuite
)
Expand Down

0 comments on commit d5a9fce

Please sign in to comment.