[ANN] ppx_factory v0.0.0

Cryptosense is happy to announce the initial release of ppx_factory!

ppx_factory is a ppx that will derive factory methods from your record and variant type definitions. It’s partly inspired by factory_bot, factory_boy and such alternatives in various other languages. The idea of factory methods is that they are meant to replace test fixtures and allow you to build test values while only defining the bits that are relevant to your test.

For example, the following code:

type t =
  | A of {aa : int; ab: string}
  | B of {ba : bool; bb : float list }
[@@deriving factory]

will provide you with:

val a_factory : ?aa: int -> ?ab: string -> unit -> t
val b_factory : ?ba: int -> ?bb: string -> unit -> t

The use of factories improved the quality and legibility of our test code a lot and we hope ppx_factory can prove as helpful to you as it is to us!

It’s in a beta release at this point so any feedback is appreciated!

You can find it on github and opam!

4 Likes

Links to factory_boy and factory_bot are broken.

Ouh thanks, just fixed it!