Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive generators from type definitions #128

Closed
wants to merge 1 commit into from

Commits on Nov 3, 2019

  1. Derive generators from type definitions

    This commit adds a macro to derive generators automatically from type
    definitions `@type`. Certain restrictions apply, such as not being able
    to generate a pid or reference. The macro can be used to create
    generators for all public types within a module:
    
    ```elixir
    use PropCheck.DeriveGenerators
    ```
    
    It can also be used to create generators for other modules, as long as
    they are already compiled:
    
    ```elixir
    use PropCheck.DeriveGenerators, module: OtherModule
    ```
    
    The macro creates a new module `module.Generate`, which contains the
    generators. For each `@type t`, a function `Generate.t()` is created,
    which can then be used as a generator in `forall`. For types
    `@type t(var)` taking a type variable, the function expects a generator
    as an argument for each type variable.
    
    To allow adding types which are cannot be turned into a generator, the
    option `:only` can be used.
    
    ```elixir
    use PropCheck.DeriveGenerators, only: [t: 0]
    ```
    
    With this, only the type `t` will be turned into a generator.
    evnu committed Nov 3, 2019
    Configuration menu
    Copy the full SHA
    5e1a7cc View commit details
    Browse the repository at this point in the history