Skip to content

Conversation

@vch9
Copy link
Contributor

@vch9 vch9 commented Dec 13, 2021

Closes #190

This PR introduces two derivation plugins:

  • qcheck
  • qcheck2

The code and test is duplicated, in the vast majority it's only a renaming to QCheck to QCheck2 (excepts for fun_nary)

- utop # type t = int
val gen : t QCheck.Gen.t = <fun>
val arb : t QCheck.arbitrary =
  {QCheck.gen = <fun>; print = None; small = None; shrink = None;
   collect = None; stats = []}
─( 15:46:16 )─< command 2 >─────
- utop # type t = int [@@deriving qcheck2];;
type t = int
val gen : t QCheck2.Gen.t = <abstr>

This it not ideal as we only derive generators then call make on them, the best would be to use arbitrary for primitive types as they also have printers, shrinkers etc.

However after #195, #208 and this one, I'm getting tired of writing boilerplate code, but I will eventually do this in the future :)

@vch9 vch9 changed the title Deriver: qcheck and qcheck2 WIP: Deriver: qcheck and qcheck2 Dec 13, 2021
@vch9 vch9 force-pushed the qcheck-and-qcheck2 branch from a48a357 to 14be7e2 Compare December 15, 2021 14:47
@vch9 vch9 changed the title WIP: Deriver: qcheck and qcheck2 Deriver: qcheck and qcheck2 Dec 15, 2021
@vch9 vch9 mentioned this pull request Jan 4, 2022
5 tasks
let ty = Ldot (Ldot (Lident "QCheck", "Gen"), "t")
let ty = function
| `QCheck -> Ldot (Ldot (Lident "QCheck", "Gen"), "t")
| `QCheck2 -> Ldot (Ldot (Lident "QCheck2", "Gen"), "t")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would introducing a VERSION module and changing these to use a to_module function improve this duplication?

module type VERSION = sig
  type t
  val version : t
  val to_module : t -> label
end

type version = [`QCheck | `QCheck2]

let to_module = function
  | `QCheck -> "QCheck"
  | `QCheck2 -> "QCheck2"
  

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right, I believe we would never have more than 2 versions but that'd simplify the code a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although, I don't see the real benefit of the module type VERSION.
Isn't:

type version = [`QCheck | `QCheck2]
                    
let to_module : version -> string = function
  | `QCheck -> "QCheck"
  | `QCheck2 -> "QCheck2"

let ty version = Ldot (Ldot (Lident (to_module version), "Gen"), "t")

...

module Make (Version : sig val version : version end) = struct

enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be enough, I would go with that.
Making it a module type might be slightly tidier if more than 2 versions were expected or there were other places that needed that type. In my hacking it didn't seem worthwhile.

@vch9 vch9 force-pushed the qcheck-and-qcheck2 branch from 14be7e2 to 8ce4ca7 Compare January 24, 2022 17:07
@vch9
Copy link
Contributor Author

vch9 commented Jan 24, 2022

Used @tmcgilchrist suggestion to reduce the code duplication and rebased to master. The commits should be squashed on merge, I'm not sure each of them compile and it's not that important if they're split.

@vch9 vch9 force-pushed the qcheck-and-qcheck2 branch from 8ce4ca7 to b1c8290 Compare July 1, 2022 12:17
n-osborne and others added 29 commits November 2, 2022 10:28
Fix "unknown option" error message from runner
Update expected 32bit output for test_gen_no_shrink
CI dune runtest on latest MacOSX too
@jmid jmid merged commit 344f4d7 into c-cube:master Nov 7, 2022
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.

Deriver: support qcheck and qcheck2

6 participants