-
Notifications
You must be signed in to change notification settings - Fork 23
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
Support properties that return Future[Result] #146
Comments
I was waiting for someone to ask for this. Just to confirm, is the biggest reason related to Scala.js? I'm curious, is Scala Hedgehog working in Scala.js for you at the moment, or you're just interested in the possibility? The other new Scala property testing library with integrated shrinking is zio-test which is obviously heavily based around a more IO like computation. I'm not sure if it works on Scala.js though. |
Yeah, biggest reason is Scala.js, where we can't sneak a call in to I'm looking at moving some of my projects from ScalaTest + ScalaCheck to munit + hedgehog. In particular, fs2 uses the ScalaTest 3.2 generators so that we can write property tests that return |
Using I have been using this:
and then:
|
@steinybot Unfortunately, that technique suffers from the same problem as Would the approach to fixing this be changing |
That's actually what it used to be :) Even though that's what the Haskell version does, and it might solve the problem, I think I would vote/recommend that we take a slightly different approach. In particular I think mixing Future-ish things in with GenT can have unintended side-effects. hedgehogqa/haskell-hedgehog#122 What I've been thinking about is being explicit about converting the value inside of final def takeSmallest[F[_]: Monad](n: ShrinkCount, slimit: ShrinkLimit, t: Tree[Option[(List[Log], Option[F[Result]])]]): F[Status]
def report[F[_]: Monad](config: PropertyConfig, size0: Option[Size], seed0: Seed, p: PropertyT[F[Result]]): F[Report] = {
// Default version
def check(config: PropertyConfig, p: PropertyT[Result], seed: Seed): Report =
propertyT.report(config, None, seed, p)
// The one you want:
def checkF[F[_]: Monad](config: PropertyConfig, p: PropertyT[F[Result]], seed: Seed): F[Report] =
propertyT.report(config, None, seed, p) Or something like that. That should actually be relatively easy to do, with less impact, and I think avoids all the complications of having a generic Does that make sense? What do you think? |
I started playing around with this idea here https://github.com/steinybot/scala-hedgehog/tree/future-result. It is a bit broken at the moment but it shouldn't be too hard to fix. |
@steinybot Nice! I started something today too: https://github.com/hedgehogqa/scala-hedgehog/compare/master...mpilquist:wip/effectful-props?expand=1 |
It would be nice to have support in the runner for a What would this look like for Scala.js? Would having a Scala.js runner library make sense? |
In my case, I'd be using I haven't thought too much about runner support as I only use hedgehog via other testing frameworks. |
I made some more progress on this. The main thing left to do is decide what to do regarding stack safety. There are more details on the draft PR. |
Amazing!!! Michael's branch looks almost like what I had in mind, but I hadn't thought about the consequences of needing stack safety now. Sigh. |
Yeah I did wonder what we do with the runner. You could "capture" the I'm still not really sure what to do with my half-baked runner. I won't lie, I vaguely wish "tests" in Scala were just wired up from a single main class (like in Haskell) and the consumers can decide. I'm open to suggestion? Do people find runner useful? |
I use a modified version of the runner (which I hope to open source soon) because I have added stackable traits to support a before/after style and another for scalamock which needs to wrap the test with behaviour verification. I essentially extended It would be interesting to play around with different options and see how it works out. |
I'm not certain we need stack safety. Non-identity effects will bring their own stack safety (e.g. Future and IO). We just need to make sure the default |
I didn't really look into it much at the time. I was getting StackOverflowErrors from Id but yeah I think just making sure that the ones that are actually used are safe should be good enough. Sorry for the slackness on this, I plan to pick this back up soon 🤞. |
I did take another look at this last week but I didn't get very far. I was having a hard time finding what is actually causing the StackOverflow's since they are thrown within all the composed functions and not the place that is doing the composition. Anyone have tips on how to deal with this? There has been a bit of "turbulence" in my work situation at the moment so I am likely to be putting my spare time into a commercial project before this one sadly. |
This would include a
Property.check(...): Future[Report]
function. Scalacheck doesn't support this but ScalaTest 3.2's built-in property testing support does. It's really useful when writing effectful tests that run on Scala.js, where you can't await futures inside the properties.The text was updated successfully, but these errors were encountered: