1616
1717package munit .internal
1818
19- import cats .effect .{IO , SyncIO }
20- import cats .syntax .all ._
19+ import cats .effect .{IO , ResourceIO , SyncIO }
20+ import cats .syntax .all .*
21+
2122import scala .concurrent .Future
2223
2324private [munit] object NestingChecks {
@@ -41,6 +42,11 @@ private[munit] object NestingChecks {
4142 " your test returns an `IO[IO[_]]`, which means the inner `IO` will not execute." ++
4243 " Call `.flatten` if you want it to execute, or `.void` if you want to discard it"
4344 )
45+ case _ : ResourceIO [_] =>
46+ err(
47+ " your test returns an `IO[ResourceIO[_]]`, which means the inner `ResourceIO` will not execute." ++
48+ " Call `.flatMap(_.use_)` if you want it to execute, or `.void` if you want to discard it"
49+ )
4450 case _ : SyncIO [_] =>
4551 err(
4652 " your test returns an `IO[SyncIO[_]]`, which means the inner `SyncIO` will not execute." ++
@@ -55,6 +61,35 @@ private[munit] object NestingChecks {
5561 }
5662 }
5763
64+ // same as above, but for ResourceIO
65+ def checkNestingResourceIO (fa : ResourceIO [_]): ResourceIO [Any ] = {
66+ def err (msg : String ) = IO .raiseError[Any ](new Exception (msg)).toResource
67+
68+ fa.flatMap {
69+ case _ : IO [_] =>
70+ err(
71+ " your test returns a `ResourceIO[IO[_]]`, which means the inner `IO` will not execute." ++
72+ " Call `.flatMap(_.toResource)` if you want it to execute, or `.void` if you want to discard it"
73+ )
74+ case _ : ResourceIO [_] =>
75+ err(
76+ " your test returns a `ResourceIO[ResourceIO[_]]`, which means the inner `ResourceIO` will not execute." ++
77+ " Call `.flatten` if you want it to execute, or `.void` if you want to discard it"
78+ )
79+ case _ : SyncIO [_] =>
80+ err(
81+ " your test returns a `ResourceIO[SyncIO[_]]`, which means the inner `SyncIO` will not execute." ++
82+ " Call `.flatMap(_.to[IO].toResource)` if you want it to execute, or `.void` if you want to discard it"
83+ )
84+ case _ : Future [_] =>
85+ err(
86+ " your test returns a `ResourceIO[Future[_]]`, which means the inner `Future` might not execute." ++
87+ " Change it to `_.flatMap(x => IO.fromFuture(IO.pure(x)).toResource)` if you want it to execute, or call `.void` if you want to discard it"
88+ )
89+ case v => v.pure[ResourceIO ]
90+ }
91+ }
92+
5893 // same as above, but for SyncIO
5994 def checkNestingSyncIO (fa : SyncIO [_]): SyncIO [Any ] = {
6095 def err (msg : String ) = SyncIO .raiseError[Any ](new Exception (msg))
@@ -65,6 +100,11 @@ private[munit] object NestingChecks {
65100 " your test returns a `SyncIO[IO[_]]`, which means the inner `IO` will not execute." ++
66101 " Call `.to[IO].flatten` if you want it to execute, or `.void` if you want to discard it"
67102 )
103+ case _ : ResourceIO [_] =>
104+ err(
105+ " your test returns an `SyncIO[ResourceIO[_]]`, which means the inner `ResourceIO` will not execute." ++
106+ " Call `.to[IO].flatMap(_.use_)` if you want it to execute, or `.void` if you want to discard it"
107+ )
68108 case _ : SyncIO [_] =>
69109 err(
70110 " your test returns a `SyncIO[SyncIO[_]]`, which means the inner `SyncIO` will not execute." ++
0 commit comments