Skip to content

Commit

Permalink
Update the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Jun 19, 2022
1 parent ba30103 commit b58baef
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy val docs = project
lazy val root = tlCrossRootProject.aggregate(core)

lazy val core = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.crossType(CrossType.Pure)
.in(file("core"))
.settings(
name := "munit-cats-effect",
Expand Down
62 changes: 0 additions & 62 deletions core/shared/src/test/scala/munit/CatsEffectFixturesSpec.scala

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import munit.catseffect.ResourceFixture.FixtureNotInstantiatedException

import scala.concurrent.duration._

class CatsEffectFixturesPlatformSpec extends CatsEffectSuite with CatsEffectAssertions {
class CatsEffectFixturesSpec extends CatsEffectSuite with CatsEffectAssertions {

var acquired: Int = 0
var released: Int = 0
@volatile var acquired: Int = 0
@volatile var released: Int = 0

val fixture = ResourceSuiteLocalFixture(
"fixture",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,34 @@

package munit

import cats.effect.{IO, SyncIO, Resource}
import cats.syntax.flatMap._
import cats.effect.IO
import cats.effect.Resource
import cats.effect.SyncIO

import scala.concurrent.Promise
import scala.concurrent.duration._

class CatsEffectFunFixturesSpec extends CatsEffectSuite with CatsEffectFunFixtures {
val latch: Promise[Unit] = Promise[Unit]()
var completedFromTest: Option[Boolean] = None
var completedFromTeardown: Option[Boolean] = None

var completedFromResourceAcquire: Option[Boolean] = None
var completedFromResourceRelease: Option[Boolean] = None
@volatile var completedFromTest: Option[Boolean] = None

@volatile var completedFromResourceAcquire: Option[Boolean] = None
@volatile var completedFromResourceRelease: Option[Boolean] = None

val latchOnTeardown: SyncIO[FunFixture[String]] =
ResourceFixture[String](
resource = Resource.make[IO, String](
IO {
completedFromResourceAcquire = Some(true)
"test"
}
)(_ =>
IO {
completedFromResourceRelease = Some(true)
}
),
setup = { (_: TestOptions, _: String) =>
IO {
completedFromResourceAcquire = Some(false)
}
},
teardown = { (_: String) =>
IO {
completedFromResourceRelease = Some(false)
completedFromTeardown = Some(latch.trySuccess(()));
}
}
ResourceFunFixture[String](
Resource
.make[IO, String](
IO {
completedFromResourceAcquire = Some(true)
"test"
}
)(_ =>
IO {
completedFromResourceRelease = Some(true)
}
)
)

override def afterAll(): Unit = {
Expand All @@ -62,8 +53,6 @@ class CatsEffectFunFixturesSpec extends CatsEffectSuite with CatsEffectFunFixtur
assertEquals(completedFromResourceRelease, Some(true))
// promise was completed first by the test
assertEquals(completedFromTest, Some(true))
// and then there was a completion attempt by the teardown
assertEquals(completedFromTeardown, Some(false))
}

latchOnTeardown.test("teardown runs only after test completes") { _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ExampleSuite extends CatsEffectSuite {

import cats.effect.std.Dispatcher

val dispatcher = ResourceFixture(Dispatcher[IO])
val dispatcher = ResourceFunFixture(Dispatcher[IO])

dispatcher.test("resources can be lifted to munit fixtures") { dsp =>
dsp.unsafeRunAndForget(IO(42))
Expand Down

0 comments on commit b58baef

Please sign in to comment.