From 65704c9e33ace4ef1f21dd2b745519ed9f4c3415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Mon, 11 Oct 2021 10:32:00 +0200 Subject: [PATCH] Cleanup code --- docs/fixtures.md | 2 +- munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala | 2 -- munit/shared/src/main/scala/munit/AfterEach.scala | 5 +++++ munit/shared/src/main/scala/munit/BeforeEach.scala | 4 ---- munit/shared/src/main/scala/munit/Fixture.scala | 3 +-- munit/shared/src/main/scala/munit/FutureFixture.scala | 2 +- munit/shared/src/main/scala/munit/Suite.scala | 5 ++--- munit/shared/src/main/scala/munit/Test.scala | 2 +- tests/jvm/src/test/scala/munit/TimeoutSuite.scala | 5 +++++ 9 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 munit/shared/src/main/scala/munit/AfterEach.scala diff --git a/docs/fixtures.md b/docs/fixtures.md index 42351598..25d97296 100644 --- a/docs/fixtures.md +++ b/docs/fixtures.md @@ -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 diff --git a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala index a05906af..38684e79 100644 --- a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala @@ -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 @@ -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], diff --git a/munit/shared/src/main/scala/munit/AfterEach.scala b/munit/shared/src/main/scala/munit/AfterEach.scala new file mode 100644 index 00000000..4fb1faa5 --- /dev/null +++ b/munit/shared/src/main/scala/munit/AfterEach.scala @@ -0,0 +1,5 @@ +package munit + +class AfterEach( + val test: Test +) extends Serializable \ No newline at end of file diff --git a/munit/shared/src/main/scala/munit/BeforeEach.scala b/munit/shared/src/main/scala/munit/BeforeEach.scala index 91abf349..99c8406b 100644 --- a/munit/shared/src/main/scala/munit/BeforeEach.scala +++ b/munit/shared/src/main/scala/munit/BeforeEach.scala @@ -3,7 +3,3 @@ package munit class BeforeEach( val test: Test ) extends Serializable - -class AfterEach( - val test: Test -) extends Serializable diff --git a/munit/shared/src/main/scala/munit/Fixture.scala b/munit/shared/src/main/scala/munit/Fixture.scala index 5f296ce5..35a51b24 100644 --- a/munit/shared/src/main/scala/munit/Fixture.scala +++ b/munit/shared/src/main/scala/munit/Fixture.scala @@ -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 = () diff --git a/munit/shared/src/main/scala/munit/FutureFixture.scala b/munit/shared/src/main/scala/munit/FutureFixture.scala index dccac4c1..fa47c61c 100644 --- a/munit/shared/src/main/scala/munit/FutureFixture.scala +++ b/munit/shared/src/main/scala/munit/FutureFixture.scala @@ -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(()) diff --git a/munit/shared/src/main/scala/munit/Suite.scala b/munit/shared/src/main/scala/munit/Suite.scala index c3eae8a0..516b703e 100644 --- a/munit/shared/src/main/scala/munit/Suite.scala +++ b/munit/shared/src/main/scala/munit/Suite.scala @@ -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 @@ -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. diff --git a/munit/shared/src/main/scala/munit/Test.scala b/munit/shared/src/main/scala/munit/Test.scala index d3e25492..74d9ff8c 100644 --- a/munit/shared/src/main/scala/munit/Test.scala +++ b/munit/shared/src/main/scala/munit/Test.scala @@ -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], diff --git a/tests/jvm/src/test/scala/munit/TimeoutSuite.scala b/tests/jvm/src/test/scala/munit/TimeoutSuite.scala index 619e9b59..f5a13510 100644 --- a/tests/jvm/src/test/scala/munit/TimeoutSuite.scala +++ b/tests/jvm/src/test/scala/munit/TimeoutSuite.scala @@ -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) {