Module eqc_erlang_program
This module defines a QuickCheck generator for Erlang programs.
Copyright © Quviq AB, 2014-2017
Version: 1.42.1
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:
- binaries
- binary comprehensions
- number literals in different bases
- escaped special characters in string literals
- juxtaposed string literals
module/1 | Erlang program generator. |
module/2 | Configurable Erlang program generator. |
words/1 | Generate a list of N random words. |
Equivalent to module(Mod, []).
Erlang program generator. Generates the source code for a module
called Mod.
module(Mod::atom(), Options::[any()]) -> eqc_gen:gen(string())
Configurable Erlang program generator. Generates the source code for a
module called Mod.
Options
- {maps, bool()} - Generate map expressions (default:
false).
- {macros, bool()} - Generate macro definitions and calls
(default: false).
- {recursive_funs, bool()} - Generate recursive 'fun' expressions
(default: false).
- {parameterized_modules, bool()} - Generate parameterized modules
(default: false).
- {preamble, string()} - Code to insert after the module header (default: "").
- {words, list(string())} - List of words to use for
variables and atoms (default: 100 common english words).
- {forbidden_words, list(string())} - List of words to not use.
- {weight, Key :: atom(), Weight :: integer()} - Set the
weight for the given key (high weight => generated more
frequently). If weight is zero the correspoding construct is not
generated at all. In the list below the weights for a given key is
relative to the weights of the other keys in the same group, so
it's recommended to set all weights in a group when changing the
weights.
- Atomic expressions: atom, bool,
int, string, char, float,
nil, pat_var (in patterns), var.
- Compound expressions:
small (atomic expression), predef_macro, list,
tuple, map, match,
macrocall, binop, unop,
'case', block, 'if',
'fun', 'receive',
'try', 'catch', try_of,
termcall, varcall, localcall, extcall.
- Operators: any_op, guard_op.
- Pattern variables: fresh_var, bound_var.
- Guards: no_guard, yes_guard.
- List expressions: plain_list, cons, lc.
- List comprehensions: lc_gen, lc_guard.
- Function expressions: lambda (fun(Args) -> Body; ... end),
rec_lambda (fun F(Args) -> Body; ... end),
local_mfa (fun f/N),
ext_mfa (fun m:f/N), any_mfa
(fun M:F/A).
- Map expressions: build_map, update_map.
- Catch clause exception types:
no_etype, lit_etype (exit,
error, or throw), any_etype (_),
var_etype, bad_etype (any atom).
- Try after: try_after, no_try_after.
- Receive timeouts: lit_timeout, inf_timeout, var_timeout.
Generate a list of N random words. Note that duplicates may occur in this list.
Generated by EDoc, Sep 18 2017, 16:17:38.