Skip to content

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

Merged
djspiewak merged 2 commits intotypelevel:series/1.xfrom
Dwolla:specs2
Jul 9, 2025
Merged

Abstract over Specs2 test result kind to enable more consistent support for ScalaCheck#616
djspiewak merged 2 commits intotypelevel:series/1.xfrom
Dwolla:specs2

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]`).
Copy link
Member

@djspiewak djspiewak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

World's most delayed PR review!

@djspiewak djspiewak merged commit fd20d6a into typelevel:series/1.x Jul 9, 2025
@bpholt bpholt deleted the specs2 branch July 9, 2025 20:12
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.

2 participants