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

Restore v0.7.x fixture ordering #724

Merged
merged 2 commits into from
Jan 2, 2024
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
10 changes: 8 additions & 2 deletions munit/shared/src/main/scala/munit/MUnitRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,25 @@ class MUnitRunner(val cls: Class[_ <: Suite], newInstance: () => Suite)

private lazy val munitTests: mutable.ArrayBuffer[Test] =
mutable.ArrayBuffer[Test](suite.munitTests(): _*)
private val suiteFixture = new Fixture[Unit](cls.getName()) {

// Suite fixtures are implemented as regular fixtures
// We split up the before*/after* methods so we can order them explicitly
private val suiteFixtureBefore = new Fixture[Unit](cls.getName()) {
def apply(): Unit = ()
override def beforeAll(): Unit =
suite.beforeAll()
override def beforeEach(context: BeforeEach): Unit =
suite.beforeEach(context)
}
private val suiteFixtureAfter = new Fixture[Unit](cls.getName()) {
def apply(): Unit = ()
override def afterEach(context: AfterEach): Unit =
suite.afterEach(context)
override def afterAll(): Unit =
suite.afterAll()
}
private lazy val munitFixtures: List[AnyFixture[_]] =
suiteFixture :: suite.munitFixtures.toList
suiteFixtureBefore :: (suite.munitFixtures.toList ::: suiteFixtureAfter :: Nil)

override def filter(filter: Filter): Unit = {
val newTests = munitTests.filter { t =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,29 @@ object FixtureOrderFrameworkSuite
|beforeEach(a, 1)
|beforeEach(b, 1)
|test(1)
|afterEach(ad-hoc, 1)
|afterEach(a, 1)
|afterEach(b, 1)
|afterEach(ad-hoc, 1)
| + 1 <elapsed time>
|beforeEach(ad-hoc, 2)
|beforeEach(a, 2)
|beforeEach(b, 2)
|test(2)
|afterEach(ad-hoc, 2)
|afterEach(a, 2)
|afterEach(b, 2)
|afterEach(ad-hoc, 2)
| + 2 <elapsed time>
|beforeEach(ad-hoc, 3)
|beforeEach(a, 3)
|beforeEach(b, 3)
|test(3)
|afterEach(ad-hoc, 3)
|afterEach(a, 3)
|afterEach(b, 3)
|afterEach(ad-hoc, 3)
| + 3 <elapsed time>
|afterAll(ad-hoc)
|afterAll(a)
|afterAll(b)
|afterAll(ad-hoc)
|""".stripMargin,
format = StdoutFormat
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SuiteLocalFixtureSuite extends FunSuite {
n = 1
}
override def afterAll(): Unit = {
assertEquals(n, 17)
assertEquals(n, 16)
n = -11
}
}
Expand All @@ -34,7 +34,7 @@ class SuiteLocalFixtureSuite extends FunSuite {
}

override def afterAll(): Unit = {
assertEquals(counter(), 17)
assertEquals(counter(), -10)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

}

1.to(5).foreach { i =>
Expand Down