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

Abstract over Specs2 test result kind to enable more consistent support for ScalaCheck #616

Open
wants to merge 2 commits into
base: series/1.x
Choose a base branch
from

Conversation

bpholt
Copy link
Member

@bpholt bpholt commented Dec 18, 2024

This PR introduces AsFutureResult[A], which can be thought of an extension of UnsafeRun[F].unsafeToFuture[A] when an AsResult[A] is available. As far as I can tell, this is necessary to support structures like org.scalacheck.effect.PropF[F], where it is not possible to write an instance of UnsafeRun[PropF], since PropF#check returns Result and not A. (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 an AsResult[A]), F[A] (assuming an UnsafeRun[F] and AsResult[A]), or PropF[F] (assuming an UnsafeRun[F]).

If this is merged, I'll make a followup PR to typelevel/scalacheck-effect adding a new scalacheck-effect-specs2 project with a trait Specs2ScalaCheckEffect which will provide an instance of AsFutureResult[PropF[F]].

This enables users to use CatsResource#withResource with 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 returned MatchResult[A] and MatchResult[scala.concurrent.Future[A]] (as well as some tests implemented in Twitter's Future). With these changes, I was able to add tests that operate in IO and PropF while minimizing the changes needed to the existing tests. (Without these tests, using the existing tests with withResources would have involved a fair amount of boilerplate wrapping the existing tests in IO.)

…ind of test results

This lets `CatsResource#withResource` accept test implementations
that return kinds like `*` (`A`), `* -> *` (`F[A]`), and
`(* -> *) -> *` (`org.scalacheck.effect.PropF[F]`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant