PropCheck.Derive
Generating simple PropCheck generators from type definitions.
Usage
In order to derive a PropCheck generator with PropCheck.Derive, add a use statement to
the module for which you want to derive the generators, or use an explicit module argument
to define the module for which generators are to be generated. PropCheck.Derive will then
attempt to create a generator for each @type. There are some requirements which must be fulfilled
in order to do that:
-
Cyclic types are not allowed.
PropCheck.Deriveshould detect those and raise an error. -
Some types are not supported. For example,
pid()cannot be created. Other types such asmaybe_improper_listare not yet implemented, as their semantics are not clear.
Usage within a module
iex> use PropCheck
iex> Application.ensure_all_started(:propcheck_derive)
iex> defmodule Hello do
...> use PropCheck.Derive
...> @type my_type :: integer()
...> end
iex> {:ok, my_type} = produce(Hello.Generate.my_type())
iex> is_integer(my_type)
trueUsage outside of a module
iex> use PropCheck
iex> Application.ensure_all_started(:propcheck_derive)
iex> use PropCheck.Derive, module: String
iex> {:ok, string} = produce(String.Generate.t())
iex> is_binary(string)
trueLicense
PropCheck.Derive is licensed under GPL 3 as is PropCheck.
Quality of the generators
Please note that hand-written generators are likely to be better suited for non-trivial types.
PropCheck.Derive makes use of oneof/1 and other simple union generators, but it does not
use frequency/1 or similar generators to make some cases more likely then others.
TODOs
-
The semantics for
maybe_improper_listis unclear. Can we add generators for that type? - Opaque types are not handled. Should we create a generator for them?