[erlang-questions] rebar eunit test pass but fail on cover test

Luis Rascão luis.rascao@REDACTED
Tue Aug 4 00:40:32 CEST 2015


Hi,
This appears to be a bug in OTP's cover.erl, i isolated your code to the
following simple module:

-module(t).
-compile([export_all]).

pad(A, L) ->
    P = << <<"#">> || _ <- lists:seq(1, L) >>,
    <<A/binary, P/binary>>.

test() ->
    pad(<<"hi">>, 2).

i then issue the following commands in an erl shell:

1> c(t, [debug_info]).
{ok,t}
2> t:test().
<<"hi##">>                      %% no problem here
3> cover:start().
{ok,<0.39.0>}
4> cover:compile_beam("t.beam").
{ok,t}
5> t:test().
** exception error: bad argument
     in function  t:'-pad/2-lbc$^0/2-0-'/2 (t.erl, line 5)
     in call from t:pad/2 (t.erl, line 5)

Cover manipulates the original .beam abstract code, inserts it's hooks for
code
coverage statistics and then compiles the manipulated abstract code and
loads it,
rebar then runs the eunit test. A closer look at the abstract code before
and after the
manipulation shows the following:

before:
    [{match,5,
                       {var,5,'P'},
                       {bc,5,
                           {bin,5,
                               [{bin_element,5,
                                   * {string,5,"#"},*
                                    default,default}]}

after:
    {match,5,
                      {var,5,'P'},
                      {bc,5,
                          {bin,5,
                              [{bin_element,5,
                                   *{block,0,[{string,5,"#"}]},*
                                   default,default}]},

if i hack cover.erl and remove the *{block* instruction the test succeeds,
could this really be a Cover or am i missing something?

On Thu, Jul 16, 2015 at 9:49 PM, ruanbeihong <ruanbeihong@REDACTED> wrote:

> Hi everyone,
>
> I'm learning erlang  for a while. Currently I'm using rebar
> to manage building and test work. I find the cover test
> provided in rebar (eunit?) quite convenient.
>
> But recently I come across a strange situation: when running
> test without '{cover_enabled, true}.' in rebar.conf, it
> works find and passed my test, but with it will result in a
> fail of test. And the crush info is IMO not quite useful.
>
> So I ask here for someone might come across same problem and
> to see if this is a bug.
>
> My code is at  https://github.com/jamesruan/z85
> commit: 6e0fc13667
> simply git clone it and run:
>   rebar eunit
> or
>   rebar -C rebar.conf eunit
> The first will success in my environment (
> Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async-
> threads:10] [kernel-poll:false])
> But the second will fail.
>
> Thanks,
>
> James Ruan
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
PGP fingerprint: F708 E141 AE8D 2D38 E1BC  DF3D 1719 3EA0 647D 7260
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150803/975fee58/attachment.htm>


More information about the erlang-questions mailing list