Skip to content

Commit

Permalink
Add in send and recieve code
Browse files Browse the repository at this point in the history
  • Loading branch information
zkessin committed Aug 31, 2014
1 parent 527e254 commit 710d292
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/erlog_mailbox.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(erlog_mailbox).

-include("erlog_int.hrl").

-compile(export_all).


send(Pid, Msg) ->
Pid ! Msg,
{succeed_last,Msg}.

receive_msg(Timeout) ->
receive
Msg ->
{succeed_last, Msg}
after Timeout ->
fail
end.

16 changes: 16 additions & 0 deletions stdlib/erlang.pl
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@
N is Place + 1,
get_record(RecordName, Rest, N).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Send and receive
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

send(Pid,Msg) :-
ecall(erlog_mailbox:send(Pid,Msg),_).

receive(Msg,Timeout) :-
ecall(erlog_mailbox:receive_msg(Timeout),Msg).

receive(Msg) :-
receive(Msg, infinity).


44 changes: 44 additions & 0 deletions test/erlog_mailbox_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-module(erlog_mailbox_tests).

-include_lib("eqc/include/eqc.hrl").
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
-include("erlog_test.hrl").

make_erlog() ->
application:set_env(erlog, consult_path, [".", "../stdlib"]),
{ok, ERLOG} = erlog:new(),
erlog:consult(ERLOG,"erlang.pl").

prop_send() ->
?FORALL(Msg,
{word,non_empty(list(choose(65,90)))},
begin
{ok, ERLOG1} = make_erlog(),
{{succeed, _R}, _ERLOG2} = erlog:prove(ERLOG1, {send, self(), Msg}),
receive
Msg ->
true
after 100 ->
false
end
end).


prop_recieve() ->
?FORALL(Msg,
{word,non_empty(list(choose(65,90)))},
begin
{ok, ERLOG1} = make_erlog(),
self() ! Msg,

{{succeed, R}, _ERLOG2} = erlog:prove(ERLOG1, {'receive', {'Msg'}, 500}),
Msg =:= proplists:get_value('Msg', R)
end).

recieve_after_test() ->
{ok, ERLOG1} = make_erlog(),
?assertMatch({fail, _}, erlog:prove(ERLOG1, {'receive', {'Msg'}, 5})),
true.


0 comments on commit 710d292

Please sign in to comment.