c-cube / qcheck

QuickCheck inspired property-based testing for OCaml.
https://c-cube.github.io/qcheck/
BSD 2-Clause "Simplified" License
344 stars 37 forks source link

LWT (and maybe a more general?) runner #136

Open sir4ur0n opened 3 years ago

sir4ur0n commented 3 years ago

In my current project, we sometimes want to run a QCheck test in an LWT context.

So far what we did was using Lwt_main.run inside the test to respect typechecking, e.g.:

QCheck.Test.make QCheck.int (fun i -> Lwt_main.run @@ (* some LWT code here *)) 

However there are various reasons why one does not want to Lwt_main.run inside each test:

Note that rather than only providing an Lwt variant of QCheck.Test.make, maybe we can abstract away the execution context? This reminds me of "hoisting" in Servant (Haskell).

I haven't put much thought into it yet but I think there is a good solution somewhere. What do you think? We may try to give it a shot in my project

c-cube commented 3 years ago

I haven't thought about it either, but the main difficulty is that the whole of Test would have to live in a monad, I think (since running a test case and doing other things, like generating examples, shrinking, etc. are interleaved). A possibility is to make Test a functor (or have a new Make_test functor) parametrized over a monad + some primitives, and have the current Test be an instance of that with the trivial monad type 'a m = 'a.