Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Oct 11, 2021
1 parent a9c06df commit 65704c9
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class MySuite extends munit.FunSuite {
Return a `Future`-like value from the methods `beforeAll`, `beforeEach`,
`afterEach` and `afterAll` to make an asynchronous fixture. By default, only
`Future[_]` values are recognized. Override `munitValueTransforms` to add
support for writing async fixture with other `Future`-like types, see
support for other `Future`-like types, see
[declare async tests](tests.md#declare-async-test) for more details.

```scala mdoc:reset
Expand Down
2 changes: 0 additions & 2 deletions munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import sbt.testing.Task
import sbt.testing.EventHandler
import sbt.testing.Logger
import scala.concurrent.duration.Duration
import scala.concurrent.BlockContext
import java.util.concurrent.Executors
import scala.concurrent.Promise
import scala.concurrent.ExecutionContext
Expand All @@ -22,7 +21,6 @@ object PlatformCompat {
task.execute(eventHandler, loggers)
Future.successful(())
}
private[this] val _blockContext = new ThreadLocal[BlockContext]()
@deprecated("use the overload with an explicit ExecutionContext", "1.0.0")
def waitAtMost[T](
future: Future[T],
Expand Down
5 changes: 5 additions & 0 deletions munit/shared/src/main/scala/munit/AfterEach.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package munit

class AfterEach(
val test: Test
) extends Serializable
4 changes: 0 additions & 4 deletions munit/shared/src/main/scala/munit/BeforeEach.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ package munit
class BeforeEach(
val test: Test
) extends Serializable

class AfterEach(
val test: Test
) extends Serializable
3 changes: 1 addition & 2 deletions munit/shared/src/main/scala/munit/Fixture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ abstract class Fixture[T](val fixtureName: String) {
def beforeAll(): Any = ()

/**
* Runs before each individual test case.
* An error in this method aborts the test case.
* Runs before each individual test case. An error in this method aborts the test case.
*/
def beforeEach(context: BeforeEach): Any = ()

Expand Down
2 changes: 1 addition & 1 deletion munit/shared/src/main/scala/munit/FutureFixture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.concurrent.Future
/**
* Extend this class if you want to create a Fixture where all methods have `Future[Any]` as the result type.
*/
abstract class FutureFixture[T](name: String) extends Fixture[Future[T]](name) {
abstract class FutureFixture[T](name: String) extends Fixture[T](name) {
override def beforeAll(): Future[Any] = Future.successful(())
override def beforeEach(context: BeforeEach): Future[Any] =
Future.successful(())
Expand Down
5 changes: 2 additions & 3 deletions munit/shared/src/main/scala/munit/Suite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import scala.concurrent.Future
abstract class Suite extends PlatformSuite {

/** The value produced by test bodies. */
type TestValue = Future[Any]
final type TestValue = Future[Any]
final type Fixture[T] = munit.Fixture[T]
final type Test = munit.Test
final type BeforeEach = munit.BeforeEach
final type AfterEach = munit.AfterEach
Expand All @@ -29,8 +30,6 @@ abstract class Suite extends PlatformSuite {
}
def munitExecutionContext: ExecutionContext = parasiticExecutionContext

type Fixture[T] = munit.Fixture[T]

/**
* Runs once before all test cases and before all suite-local fixtures are setup.
* An error in this method aborts the test suite.
Expand Down
2 changes: 1 addition & 1 deletion munit/shared/src/main/scala/munit/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.concurrent.Future
* @param tags the annotated tags for this test case.
* @param location the file and line number where this test was defined.
*/
sealed class Test(
final class Test(
val name: String,
val body: () => Future[Any],
val tags: Set[Tag],
Expand Down
5 changes: 5 additions & 0 deletions tests/jvm/src/test/scala/munit/TimeoutSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import scala.concurrent.duration.FiniteDuration

class TimeoutSuite extends munit.FunSuite {
override val munitTimeout: FiniteDuration = Duration(100, "ms")
test("slow".fail) {
Future {
Thread.sleep(1000)
}
}
test("infinite-loop".fail) {
Future {
while (true) {
Expand Down

0 comments on commit 65704c9

Please sign in to comment.