massemanet/eper

redbug does not work in eunit

e-shubin opened this issue · 2 comments

A simple eunit test case causes an error in redbug

rb_test() ->
    {_, _} = redbug:start("lists:sort->stack", [{print_file, "redbug.txt"}]),
    timer:sleep(2000),
    ?assertEqual([1,2,3], lists:sort([3,2,1])),
    redbug:stop().
=ERROR REPORT==== 4-Feb-2014::15:04:28 ===
Error in process <0.69.0> with exit value: {terminated,[{io,format,[<0.67.0>,"~s~n",["\n15:04:28 <0.65.0>({erlang,apply,2}) {lists,sort,[[3,2,1]]}"]],[]},{redbug,'-mk_outer/1-fun-2-',5,[{file,"redbug.erl"},{line,343}]},{redbug,'-wrap_print_fun/1-fun-0-',3,[{file,"redbug.erl"},{line... 

I works good if eunit is not used.
I would love to see redbug working in eunit tests.

It works though if I put a sleep before redbug:stop/0 call.

seems there's something screwy in how eunit handles file:fwrite/3. I'll discuss this with the eunit people.
Since the below works, this is hopefully not a showstopper for you.

t_0_test() ->
  Filename = "redbug.txt",
  {_, _} = redbug:start("lists:sort->stack", [{print_file, Filename}]),
  [1,2,3] = lists:sort([3,2,1]),
  redbug:stop(),
  ?assertEqual(ok,ok).