Module eqc_erlang_program

This module defines a QuickCheck generator for Erlang programs.

Copyright © Quviq AB, 2014-2017

Version: 1.42.1

Description

This module defines a QuickCheck generator for Erlang programs. It generates Erlang source code for a well-formed Erlang module that should compile without errors. The purpose is to test syntax manipulating tools, like parse transforms or compilers. It does not try to generate a program that has any interesting behaviour when run (the majority of generated programs will crash instantly).

Usage

This program generator can for example be used to test the Erlang compiler. Other application areas are syntax tools or coverage tools.

A simple example of how to test the compiler is presented below:
  compile(Code) ->
    compile(Code, []).
 
  compile(Code, Options) ->
    File = lists:concat([?TEST_MODULE, ".erl"]),
    file:write_file(File, Code),
    compile:file(File, Options).
 
  prop_compile() ->
    ?FORALL(Code, eqc_erlang_program:module(?TEST_MODULE),
    begin
      Res      = compile(Code),
      Expected = {ok, ?TEST_MODULE},
      ?WHENFAIL(
        begin
          eqc:format("~s\n", [Code]),
          compile(Code, [report_errors])
        end,
        equals(Res, Expected))
    end).
  

Limitations

At the moment it does not generate the following:

Function Index

module/1Erlang program generator.
module/2Configurable Erlang program generator.
words/1Generate a list of N random words.

Function Details

module/1

module(Mod::atom()) -> eqc_gen:gen(string())

Equivalent to module(Mod, []).

Erlang program generator. Generates the source code for a module called Mod.

module/2

module(Mod::atom(), Options::[any()]) -> eqc_gen:gen(string())

Configurable Erlang program generator. Generates the source code for a module called Mod.

Options

words/1

words(N::integer()) -> eqc_gen:gen(string())

Generate a list of N random words. Note that duplicates may occur in this list.


Generated by EDoc, Sep 18 2017, 16:17:38.