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

Migrate kernel and law tests to munit #3787

Draft
wants to merge 2 commits into
base: series/3.5.x
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ val Specs2Version = "4.20.0"
val ScalaCheckVersion = "1.17.0"
val DisciplineVersion = "1.4.0"
val CoopVersion = "1.2.0"
val MUnitVersion = "1.0.0-M8"
val DisciplineMUnitVersion = "2.0.0-M3"

val MacrotaskExecutorVersion = "1.1.1"

Expand Down Expand Up @@ -393,8 +395,7 @@ lazy val kernel = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(
name := "cats-effect-kernel",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % CatsVersion,
"org.specs2" %%% "specs2-core" % Specs2Version % Test
"org.typelevel" %%% "cats-core" % CatsVersion
),
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[MissingClassProblem]("cats.effect.kernel.Ref$SyncRef"),
Expand Down Expand Up @@ -451,7 +452,7 @@ lazy val laws = crossProject(JSPlatform, JVMPlatform, NativePlatform)
name := "cats-effect-laws",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-laws" % CatsVersion,
"org.typelevel" %%% "discipline-specs2" % DisciplineVersion % Test)
"org.typelevel" %%% "discipline-munit" % DisciplineMUnitVersion % Test)
)
.disablePlugins(JCStressPlugin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ package cats.effect.kernel

import cats.implicits._

import org.specs2.mutable.Specification

import scala.concurrent.ExecutionContext
import scala.concurrent.duration.{Duration, FiniteDuration}

class SyntaxSpec extends Specification {

"kernel syntax" >> ok
class SyntaxSuite {

def concurrentForwarder[F[_]: Concurrent] =
Concurrent[F]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.scalacheck.{Arbitrary, Gen, Prop}
import org.scalacheck.util.Pretty

// A dumping ground for random helpers for property tests
private[effect] trait BaseSpec {
private[effect] trait BaseSuite {

implicit def kleisliEq[F[_], A, B](implicit ev: Eq[A => F[B]]): Eq[Kleisli[F, A, B]] =
Eq.by[Kleisli[F, A, B], A => F[B]](_.run)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import cats.effect.kernel.testkit.OutcomeGenerators
import cats.laws.discipline.{ApplicativeErrorTests, MonadErrorTests}

import org.scalacheck.{Arbitrary, Cogen}
import org.specs2.mutable.Specification
import org.typelevel.discipline.specs2.mutable.Discipline

class OutcomeSpec extends Specification with Discipline {
import munit.DisciplineSuite

class OutcomeSuite extends DisciplineSuite {
import OutcomeGenerators._

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ package laws
import cats.data.ContT
import cats.effect.kernel.testkit.freeEval._

import org.specs2.mutable.Specification
import org.typelevel.discipline.specs2.mutable.Discipline
import munit.DisciplineSuite

class ClockSpec extends Specification with Discipline with BaseSpec {
class ClockSuite extends DisciplineSuite with BaseSuite {

// we only need to test the ones that *aren't* also Sync
checkAll("ContT[FreeEitherSync, Int, *]", ClockTests[ContT[FreeEitherSync, Int, *]].clock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ import cats.effect.kernel.testkit.freeEval.{syncForFreeT, FreeEitherSync}
import cats.free.FreeT
import cats.laws.discipline.arbitrary._

import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline
import munit.DisciplineSuite

class EitherTFreeSyncSpec
extends Specification
with Discipline
with BaseSpec
with LowPriorityImplicits {
class EitherTFreeSyncSuite extends DisciplineSuite with BaseSuite with LowPriorityImplicits {
import FreeSyncGenerators._
import SyncTypeGenerators._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import cats.effect.kernel.testkit.pure._
import cats.laws.discipline.arbitrary._

import org.scalacheck.Prop
import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline

import scala.concurrent.duration._

class EitherTPureConcSpec extends Specification with Discipline with BaseSpec {
import munit.DisciplineSuite

class EitherTPureConcSuite extends DisciplineSuite with BaseSuite {
import PureConcGenerators._
import OutcomeGenerators._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ import cats.effect.kernel.testkit.freeEval.{syncForFreeT, FreeEitherSync}
import cats.free.FreeT
import cats.laws.discipline.arbitrary._

import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline
import munit.DisciplineSuite

class FreeSyncSpec
extends Specification
with Discipline
with BaseSpec
with LowPriorityImplicits {
class FreeSyncSuite extends DisciplineSuite with BaseSuite with LowPriorityImplicits {
import FreeSyncGenerators._
import SyncTypeGenerators._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import cats.effect.kernel.testkit.TimeT
import cats.effect.kernel.testkit.pure._
import cats.syntax.all._

import org.specs2.mutable.Specification

import scala.concurrent.duration._

import munit.FunSuite
// import scala.concurrent.TimeoutException

class GenTemporalSpec extends Specification { outer =>
class GenTemporalSuite extends FunSuite { outer =>

type F[A] = PureConc[Throwable, A]

Expand All @@ -37,28 +37,20 @@ class GenTemporalSpec extends Specification { outer =>

val loop: TimeT[F, Unit] = F.sleep(5.millis).foreverM

"temporal" should {
"timeout" should {
"return identity when infinite duration" in {
val fa = F.pure(true)
F.timeout(fa, Duration.Inf) mustEqual fa
}
}
test("timeout should return identity when infinite duration") {
val fa = F.pure(true)
assertEquals(F.timeout(fa, Duration.Inf), fa)
}

"timeoutTo" should {
"return identity when infinite duration" in {
val fa: TimeT[F, Boolean] = F.pure(true)
val fallback: TimeT[F, Boolean] = F.raiseError(new RuntimeException)
F.timeoutTo(fa, Duration.Inf, fallback) mustEqual fa
}
}
test("timeoutTo should return identity when infinite duration") {
val fa: TimeT[F, Boolean] = F.pure(true)
val fallback: TimeT[F, Boolean] = F.raiseError(new RuntimeException)
assertEquals(F.timeoutTo(fa, Duration.Inf, fallback), fa)
}

"timeoutAndForget" should {
"return identity when infinite duration" in {
val fa: TimeT[F, Boolean] = F.pure(true)
F.timeoutAndForget(fa, Duration.Inf) mustEqual fa
}
}
test("timeoutAndForget should return identity when infinite duration") {
val fa: TimeT[F, Boolean] = F.pure(true)
assertEquals(F.timeoutAndForget(fa, Duration.Inf), fa)
}

// TODO enable these tests once Temporal for TimeT is fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ import cats.effect.kernel.testkit.freeEval.{syncForFreeT, FreeEitherSync}
import cats.free.FreeT
import cats.laws.discipline.arbitrary._

import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline
import munit.DisciplineSuite

class IorTFreeSyncSpec
extends Specification
with Discipline
with BaseSpec
with LowPriorityImplicits {
class IorTFreeSyncSuite extends DisciplineSuite with BaseSuite with LowPriorityImplicits {
import FreeSyncGenerators._
import SyncTypeGenerators._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import cats.effect.kernel.testkit.pure._
import cats.laws.discipline.arbitrary._

import org.scalacheck.Prop
import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline

import scala.concurrent.duration._

class IorTPureConcSpec extends Specification with Discipline with BaseSpec {
import munit.DisciplineSuite

class IorTPureConcSuite extends DisciplineSuite with BaseSuite {
import PureConcGenerators._
import OutcomeGenerators._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ import cats.laws.discipline.MiniInt
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._

import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline
import munit.DisciplineSuite

class KleisliFreeSyncSpec
extends Specification
with Discipline
with BaseSpec
with LowPriorityImplicits {
class KleisliFreeSyncSuite extends DisciplineSuite with BaseSuite with LowPriorityImplicits {
import FreeSyncGenerators._
import SyncTypeGenerators._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ import cats.effect.kernel.testkit.pure._
import cats.laws.discipline.{arbitrary, MiniInt}

import org.scalacheck.{Arbitrary, Cogen, Prop}
import org.specs2.mutable._
import org.specs2.scalacheck.Parameters
import org.typelevel.discipline.specs2.mutable.Discipline

import scala.concurrent.duration._

class KleisliPureConcSpec
extends Specification
with Discipline
with BaseSpec
import munit.DisciplineSuite

class KleisliPureConcSuite
extends DisciplineSuite
with BaseSuite
with LowPriorityKleisliInstances {
import PureConcGenerators._
import arbitrary.{catsLawsArbitraryForKleisli => _, _}
Expand Down Expand Up @@ -78,12 +76,17 @@ class KleisliPureConcSpec
: Cogen[Outcome[Kleisli[TimeT[PureConc[Int, *], *], MiniInt, *], Int, A]] =
OutcomeGenerators.cogenOutcome[Kleisli[TimeT[PureConc[Int, *], *], MiniInt, *], Int, A]

override def scalaCheckTestParameters =
super
.scalaCheckTestParameters
// we need to bound this a little tighter because these tests take FOREVER
.withMinSuccessfulTests(25)

checkAll(
"Kleisli[PureConc]",
GenTemporalTests[Kleisli[TimeT[PureConc[Int, *], *], MiniInt, *], Int]
.temporal[Int, Int, Int](10.millis)
// we need to bound this a little tighter because these tests take FOREVER
)(Parameters(minTestsOk = 25))
)
}

//Push the priority of Kleisli instances down so we can explicitly summon more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import cats.effect.kernel.testkit.freeEval.{syncForFreeT, FreeEitherSync}
import cats.free.FreeT
import cats.laws.discipline.arbitrary._

import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline
import munit.DisciplineSuite

class OptionTFreeSyncSpec extends Specification with Discipline with BaseSpec with FreeSyncEq {
class OptionTFreeSyncSuite extends DisciplineSuite with BaseSuite with FreeSyncEq {

import FreeSyncGenerators._
import SyncTypeGenerators._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import cats.laws.discipline.arbitrary._
import cats.syntax.all._

import org.scalacheck.Prop
import org.specs2.mutable._
import org.typelevel.discipline.specs2.mutable.Discipline

import scala.concurrent.duration._

class OptionTPureConcSpec extends Specification with Discipline with BaseSpec {
import munit.DisciplineSuite

class OptionTPureConcSuite extends DisciplineSuite with BaseSuite {
import PureConcGenerators._
import OutcomeGenerators._

Expand All @@ -47,26 +47,21 @@ class OptionTPureConcSpec extends Specification with Discipline with BaseSpec {
bO => bO.flatten.fold(false)(_ => true)
))

"optiont bracket" should {
"forward completed zeros on to the handler" in {
var observed = false
test("optiont bracket forward completed zeros on to the handler") {
var observed = false

val test = OptionT.none[PureConc[Int, *], Unit] guaranteeCase {
case Outcome.Succeeded(fa) =>
observed = true
val test = OptionT.none[PureConc[Int, *], Unit] guaranteeCase {
case Outcome.Succeeded(fa) =>
observed = true

OptionT(fa.value.map(_ must beNone).as(None))
OptionT(fa.value.map(assertEquals(_, None)).as(None))

case _ => Applicative[OptionT[PureConc[Int, *], *]].unit
}
case _ => Applicative[OptionT[PureConc[Int, *], *]].unit
}

pure.run(test.value) must beLike {
case Outcome.Succeeded(Some(None)) => ok
case _ => ko
}
assert(pure.run(test.value) === Outcome.Succeeded(Some(Option.empty[Unit])))

observed must beTrue
}
assert(observed)
}

checkAll(
Expand Down
Loading