Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Dec 30, 2024
1 parent 7bc5906 commit 3d60f3f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 31 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ ThisBuild / apiURL := Some(url("https://typelevel.org/cats-effect/api/3.x/"))

ThisBuild / autoAPIMappings := true

ThisBuild / Test / testOptions += Tests.Argument("+l")

val CatsVersion = "2.11.0"
val CatsMtlVersion = "1.3.1"
val ScalaCheckVersion = "1.17.1"
Expand Down
10 changes: 9 additions & 1 deletion tests/shared/src/test/scala/cats/effect/BaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ package cats.effect

import munit.FunSuite

trait BaseSuite extends FunSuite with Runners
trait BaseSuite extends FunSuite with Runners {

override def munitValueTransforms: List[ValueTransform] =
super.munitValueTransforms ++ List(
new ValueTransform("IO", { case _: IO[_] => sys.error("Non-evaluated IO") }),
new ValueTransform("SyncIO", { case _: SyncIO[_] => sys.error("Non-evaluated SyncIO") })
)

}
40 changes: 22 additions & 18 deletions tests/shared/src/test/scala/cats/effect/IOSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -526,26 +526,28 @@ class IOSuite extends BaseSuite with DisciplineSuite with ScalaCheckSuite with I
assertCompleteAs(fa, 44)
}

// format: off
ticked("asyncCheckAttempt - produce a failure when the registration raises an error after result") { implicit ticker =>
case object TestException extends RuntimeException
ticked(
"asyncCheckAttempt - produce a failure when the registration raises an error after result"
) { implicit ticker =>
case object TestException extends RuntimeException

assertFailAs(IO.asyncCheckAttempt[Int](_ => IO(Right(42))
.flatMap(_ => IO.raiseError(TestException)))
.void, TestException)
}
// format: on
assertFailAs(
IO.asyncCheckAttempt[Int](_ => IO(Right(42)).flatMap(_ => IO.raiseError(TestException)))
.void,
TestException)
}

// format: off
ticked("asyncCheckAttempt - produce a failure when the registration raises an error after callback") { implicit ticker =>
case object TestException extends RuntimeException
ticked(
"asyncCheckAttempt - produce a failure when the registration raises an error after callback"
) { implicit ticker =>
case object TestException extends RuntimeException

val fa = IO.asyncCheckAttempt[Int](cb => IO(cb(Right(42)))
.flatMap(_ => IO.raiseError(TestException)))
.void
assertFailAs(fa, TestException)
}
// format: on
val fa = IO
.asyncCheckAttempt[Int](cb =>
IO(cb(Right(42))).flatMap(_ => IO.raiseError(TestException)))
.void
assertFailAs(fa, TestException)
}

ticked("asyncCheckAttempt - ignore asyncCheckAttempt callback") { implicit ticker =>
case object TestException extends RuntimeException
Expand Down Expand Up @@ -739,7 +741,7 @@ class IOSuite extends BaseSuite with DisciplineSuite with ScalaCheckSuite with I

ticked("async - calling async callback with null during registration (ticked)") {
implicit ticker =>
IO.async[Int] { cb => IO(cb(null)).as(None) }.map(_ + 1).attempt.map { e =>
val test = IO.async[Int] { cb => IO(cb(null)).as(None) }.map(_ + 1).attempt.map { e =>
assertCompleteAs(
IO {
e match {
Expand All @@ -750,6 +752,8 @@ class IOSuite extends BaseSuite with DisciplineSuite with ScalaCheckSuite with I
()
)
}

assertCompleteAs(test, ())
}

ticked("async - calling async callback with null after registration (ticked)") {
Expand Down
16 changes: 10 additions & 6 deletions tests/shared/src/test/scala/cats/effect/std/ConsoleSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ class ConsoleSuite extends BaseSuite {
case class Foo(n: Int, b: Boolean)

test("select default Show.fromToString (IO)") {
IO.print(Foo(1, true)) // compilation test
IO.println(Foo(1, true)) // compilation test
val _ = (
IO.print(Foo(1, true)), // compilation test
IO.println(Foo(1, true)) // compilation test
)
}

test("select default Show.fromToString (Console[IO])") {
Console[IO].print(Foo(1, true)) // compilation test
Console[IO].println(Foo(1, true)) // compilation test
Console[IO].error(Foo(1, true)) // compilation test
Console[IO].errorln(Foo(1, true)) // compilation test
val _ = (
Console[IO].print(Foo(1, true)), // compilation test
Console[IO].println(Foo(1, true)), // compilation test
Console[IO].error(Foo(1, true)), // compilation test
Console[IO].errorln(Foo(1, true)) // compilation test
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class DispatcherSuite extends BaseSuite with DetectPlatform {
}
}
}.replicateA_(if (isJVM) 10000 else 1)

}
}

Expand Down Expand Up @@ -183,7 +182,7 @@ class DispatcherSuite extends BaseSuite with DetectPlatform {
case (runner, release) =>
IO(runner.unsafeRunAndForget(release)) *>
IO.sleep(100.millis) *>
IO(intercept[IllegalStateException](runner.unsafeRunAndForget(IO(ko))))
IO(intercept[IllegalStateException](runner.unsafeRunAndForget(IO(fail("fail")))))
}

assertCompleteAs(test.void, ())
Expand Down Expand Up @@ -428,7 +427,7 @@ class DispatcherSuite extends BaseSuite with DetectPlatform {
real(s"$name - raise an error on leaked runner") {
dispatcher.use(IO.pure(_)) flatMap { runner =>
IO {
intercept[IllegalStateException](runner.unsafeRunAndForget(IO(ko)))
intercept[IllegalStateException](runner.unsafeRunAndForget(IO(fail("fail"))))
}
}
}
Expand All @@ -451,7 +450,7 @@ class DispatcherSuite extends BaseSuite with DetectPlatform {

test
.use(t =>
IO.fromFutureCancelable(IO((t.future, IO.unit))).timeoutTo(1.second, IO.pure(false)))
IO.fromFutureCancelable(IO((t.future, IO.unit))).timeoutTo(3.second, IO.pure(false)))
.flatMap(t => IO(assertEquals(t, true)))
}

Expand Down Expand Up @@ -514,7 +513,7 @@ class DispatcherSuite extends BaseSuite with DetectPlatform {
.guarantee(latch2.complete(()).void)

_ <- release &> challenge
} yield ko
} yield fail("fail")
}
}

Expand Down Expand Up @@ -671,5 +670,4 @@ class DispatcherSuite extends BaseSuite with DetectPlatform {
}
}

private def ko(implicit loc: munit.Location) = fail("fail")
}

0 comments on commit 3d60f3f

Please sign in to comment.