Skip to content

Commit

Permalink
Merge pull request massemanet#34 from robertoaloi/print_return
Browse files Browse the repository at this point in the history
Add support for print_return option
  • Loading branch information
massemanet committed Jul 3, 2015
2 parents 80e7cd6 + b602d54 commit 489ce82
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/redbug.txt
Expand Up @@ -66,6 +66,7 @@ print_file (standard_io) print to this file
print_msec (false) print milliseconds on time stamps
print_depth (999999) formatting depth for "~P"
print_re ("") print only strings that match this regexp
print_return (true) print return value
print_fun ('') custom print fun. gets called once for each trace
message. It can be a fun/1, (called as F(Msg),
return value is ignored), or a fun/2 (called as
Expand Down
10 changes: 8 additions & 2 deletions src/redbug.erl
Expand Up @@ -39,6 +39,7 @@
print_msec = false, % print milliseconds in timestamps?
print_depth = 999999, % Limit for "~P" formatting depth
print_re = "", % regexp that must match to print
print_return = true, % print return value
print_fun = '', % custom print handler
%% trc file-related
file = "", % file to write trace msgs to
Expand Down Expand Up @@ -106,6 +107,7 @@ help() ->
, "print_msec (false) print milliseconds on timestamps"
, "print_depth (999999) formatting depth for \"~P\""
, "print_re (\"\") print only strings that match this RE"
, "print_return (true) print the return value"
, "print_fun () custom print handler, fun/1 or fun/2;"
, " fun(TrcMsg) -> <ignored>"
, " fun(TrcMsg,AccOld) -> AccNew"
Expand Down Expand Up @@ -350,7 +352,7 @@ mk_blocker() ->

mk_outer(#cnf{file=[_|_]}) ->
fun(_) -> ok end;
mk_outer(#cnf{print_depth=Depth,print_msec=MS} = Cnf) ->
mk_outer(#cnf{print_depth=Depth,print_msec=MS,print_return=Ret} = Cnf) ->
OutFun = mk_out(Cnf),
fun({Tag,Data,PI,TS}) ->
MTS = fix_ts(MS,TS),
Expand Down Expand Up @@ -383,7 +385,11 @@ mk_outer(#cnf{print_depth=Depth,print_msec=MS} = Cnf) ->
false->
ok
end;
{'retn',{{M,F,A},Val}} ->
{'retn',{{M,F,A},Val0}} ->
Val = case Ret of
true -> Val0;
false -> '...'
end,
OutFun("~n% ~s ~s~n% ~p:~p/~p -> ~P",
[MTS,to_str(PI),M,F,A,Val,Depth]);
{'send',{MSG,ToPI}} ->
Expand Down
13 changes: 13 additions & 0 deletions src/redbug_eunit.erl
Expand Up @@ -128,6 +128,19 @@ t_8_test() ->
?assertEqual(sort,
e(2,e(4,e(2,Msgs)))).

t_9_test() ->
Filename = "redbug.txt",
Options = [{print_file, Filename}, {time, 999}, {print_return, false}],
{_,_} = redbug:start("lists:sort->return", Options),
[1,2,3] = lists:sort([3,2,1]),
timer:sleep(1100),
maybe_show(Filename),
?assertEqual(<<"lists:sort([3,2,1])">>,
get_line_seg(Filename,2,2)),
?assertEqual([<<"lists:sort/1">>,<<"->">>,<<"'...'">>],
get_line_seg(Filename,4,2,4)),
maybe_delete(Filename).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% trace file utilities
maybe_show(Filename) ->
Expand Down

0 comments on commit 489ce82

Please sign in to comment.