Permalink
Browse files

Add PropEr ASM callback template for gen_server

  • Loading branch information...
mbbx6spp committed Jun 13, 2011
1 parent 45428de commit 7038ae4c62834f7df7959f28f1643acd591acf2e
Showing with 75 additions and 0 deletions.
  1. +69 −0 finsrv_proper_statem.erl
  2. +6 −0 finsrv_proper_statem.template
View
@@ -0,0 +1,69 @@
+%%%' HEADER
+%%% @author {{author_name}} <{{author_email}}>
+%%% @copyright {{copyright_year}} {{author_name}}
+%%% @doc gen_server PropEr Abstract State Machine.
+%%% @end
+-module({{name}}_srv_asm).
+
+-behaviour(proper_statem).
+
+-include_lib("proper/include/proper.hrl").
+
+-export([test/0, sample/0]).
+-export([initial_state/0, command/1,
+ precondition/2, postcondition/3,
+ next_state/3]).
+
+-define(SERVER, {{name}}_srv).
+
+%%%.
+%%%' STATEM CALLBACKS
+test() ->
+ proper:quickcheck(?MODULE:prop_{{name}}()).
+
+sample() ->
+ proper_gen:pick(commands(?MODULE)).
+
+prop_{{name}}() ->
+ ?FORALL(Cmds, commands(?MODULE),
+ ?TRAPEXIT(
+ begin
+ ?SERVER:start_link(),
+ {History, State, Result} = run_commands(?MODULE, Cmds),
+ ?SERVER:stop(),
+ ?WHENFAIL(
+ io:format("History: ~w\nState: ~w\nResult: ~w\n",
+ [History, State, Result]),
+ aggregate(command_names(Cmds), Result =:= ok))
+ end
+ )).
+
+initial_state() ->
+ % TODO: specify initial state
+ [].
+
+command(State) ->
+ % TODO: specify list of commands with appropriate frequency
+ % weights to generate
+ frequency([]).
+
+% TODO: flesh out precondition function clauses
+precondition(State, Request) ->
+ true.
+
+% TODO: flesh out next_state logic clauses
+next_state(State, Value, Request) ->
+ State.
+
+% TODO: flesh out postcondition function clauses
+postcondition(State, Request) ->
+ true.
+
+%%%.
+%%%' PRIVATE FUNCTIONS
+
+%% @private
+matches(X, X) -> 1;
+matches(_, _) -> 0.
+%%%.
+%%% vim: set filetype=erlang tabstop=2 foldmarker=%%%',%%%. foldmethod=marker:
@@ -0,0 +1,6 @@
+{variables, [
+ {name, "myserver"},
+ {copyright_year, "2011"},
+ {author_name, "Susan Potter"},
+ {author_email, "me@susanpotter.net"}]}.
+{template, "finsrv_proper_statem.erl", "test/{{name}}_srv_asm.erl"}.

0 comments on commit 7038ae4

Please sign in to comment.