Abstract over Specs2 test result kind to enable more consistent support for ScalaCheck#616
Merged
djspiewak merged 2 commits intotypelevel:series/1.xfrom Jul 9, 2025
Merged
Conversation
…ind of test results This lets `CatsResource#withResource` accept test implementations that return kinds like `*` (`A`), `* -> *` (`F[A]`), and `(* -> *) -> *` (`org.scalacheck.effect.PropF[F]`).
djspiewak
approved these changes
Jul 9, 2025
Member
djspiewak
left a comment
There was a problem hiding this comment.
World's most delayed PR review!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces
AsFutureResult[A], which can be thought of an extension ofUnsafeRun[F].unsafeToFuture[A]when anAsResult[A]is available. As far as I can tell, this is necessary to support structures likeorg.scalacheck.effect.PropF[F], where it is not possible to write an instance ofUnsafeRun[PropF], sincePropF#checkreturnsResultand notA. (This doesn't work, even using e.g.UnsafeRun[({ type λ[α] = PropF[F] })#λ].)This lets us abstract over different kinds of results, such as
A(assuming anAsResult[A]),F[A](assuming anUnsafeRun[F]andAsResult[A]), orPropF[F](assuming anUnsafeRun[F]).If this is merged, I'll make a followup PR to typelevel/scalacheck-effect adding a new
scalacheck-effect-specs2project with atrait Specs2ScalaCheckEffectwhich will provide an instance ofAsFutureResult[PropF[F]].This enables users to use
CatsResource#withResourcewith many different kinds of tests. This was motivated by work I recently completed introducing Cats Effect into parts of an existing project. That project had existing tests that returnedMatchResult[A]andMatchResult[scala.concurrent.Future[A]](as well as some tests implemented in Twitter'sFuture). With these changes, I was able to add tests that operate inIOandPropFwhile minimizing the changes needed to the existing tests. (Without these tests, using the existing tests withwithResourceswould have involved a fair amount of boilerplate wrapping the existing tests inIO.)