qcheck icon indicating copy to clipboard operation
qcheck copied to clipboard

LWT (and maybe a more general?) runner

Open sir4ur0n opened this issue 4 years ago • 1 comments

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:

  • create all prerequisite values once in an LWT context before running the tests
  • run the test as part of a bigger LWT code

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

sir4ur0n avatar Jun 29 '21 09:06 sir4ur0n

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.

c-cube avatar Jun 29 '21 14:06 c-cube