erlang / rebar3

Erlang build tool that makes it easy to compile and test Erlang applications and releases.
http://www.rebar3.org
Apache License 2.0
1.7k stars 518 forks source link

rebar3 eunit --cover: Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump, {error,beam_lib, {invalid_chunk.. #1538

Closed elpaisa closed 7 years ago

elpaisa commented 7 years ago

I'm having an issue running rebar3 coverage,

Command is: rebar3 eunit --cover

It does all the unit tests and they run ok, but when it comes to coverage it errors with:

Error: {case_clause,
               {'EXIT',
                   {{case_clause,
                        {error,beam_lib,
                            {invalid_chunk,
                                "/private/var/www/al_soc_elk_service/_build/test/lib/al_soc_elk_service/ebin/al_soc_elk_service_sync_tests.beam",
                                "Abst"}}},
                [{cover,do_compile_beam1,3,[{file,"cover.erl"},{line,1539}]},
                 {cover,do_compile_beam,3,[{file,"cover.erl"},{line,1478}]},
                 {lists,map,2,[{file,"lists.erl"},{line,1239}]},
                 {cover,'-pmap_spawn/4-fun-0-',2,
                     [{file,"cover.erl"},{line,2732}]}]}}}
[{rebar_prv_cover,cover_compile_file,1,
                  [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_prv_cover.erl"},
                   {line,346}]},
 {rebar_prv_cover,'-cover_compile/2-lc$^1/1-0-',3,
                  [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_prv_cover.erl"},
                   {line,321}]},
 {rebar_prv_cover,'-cover_compile/2-fun-1-',2,
                  [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_prv_cover.erl"},
                   {line,321}]},
 {lists,foreach,2,[{file,"lists.erl"},{line,1338}]},
 {rebar_prv_cover,cover_compile,2,
                  [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_prv_cover.erl"},
                   {line,317}]},
 {rebar_prv_eunit,compile,1,
                  [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_prv_eunit.erl"},
                   {line,320}]},
 {rebar_prv_eunit,do,1,
                  [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_prv_eunit.erl"},
                   {line,47}]},
 {rebar_core,do,2,
             [{file,"/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_erlang_rebar3/rebar3/work/rebar3-3.3.5/_build/default/lib/rebar/src/rebar_core.erl"},
              {line,153}]}]

Rebar report results:

AL-COL-05321:al_soc_elk_service johnleytondiaz$ rebar3 report "cover"
Rebar3 report
 version 3.3.5
 generated at 2017-04-28T19:44:58+00:00
=================
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)
-----------------
Task: cover
Entered as:
  cover
-----------------
Operating System: x86_64-apple-darwin15.6.0
ERTS: Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Root Directory: /opt/local/lib/erlang
Library directory: /opt/local/lib/erlang/lib
-----------------
Loaded Applications:
bbmustache: 1.3.0
certifi: 0.4.0
cf: 0.2.2
common_test: 1.13
compiler: 7.0.3
crypto: 3.7.2
cth_readable: 1.2.3
dialyzer: 3.0.3
edoc: 0.8.1
erlware_commons: 1.0.0
eunit: 2.3.2
eunit_formatters: 0.3.1
getopt: 0.8.2
inets: 6.3.4
kernel: 5.1.1
providers: 1.6.0
public_key: 1.3
relx: 3.22.2
sasl: 3.0.2
snmp: 5.2.4
ssl_verify_fun: 1.1.1
stdlib: 3.2
syntax_tools: 2.1.1
tools: 2.9
elpaisa commented 7 years ago

This is how my tests look like:

setup() ->
  al_soc_elk_service:set_env(workers, get_test_workers()),
  meck:expect(incidents, documents, fun(WorkerName, Cid, StartTime, EndTime) ->
    [WorkerName, Cid, StartTime, EndTime, []] end),
  meck:expect(al_soc_elk_service_stats, set_status, fun(_WorkerName, _Key, _Value) ->
    ok end),
  meck:expect(al_soc_elk_service_customers, get_customers, fun() ->
    [{1, <<"Test Customer 1">>}, {2, <<"Test Customer 2">>}] end),
  meck:expect(al_soc_elk_service_elasticsearch, prepare, fun(_Date, _Type) ->
    ok end),
  meck:expect(al_soc_elk_service_elasticsearch, start, fun() ->
    ok end),
  meck:expect(gascheduler, start_link, fun(_Scheduler, _Nodes, _Client, _MaxWorkers, _MaxRetries) ->
    {ok, c:pid(0,250,0)} end),
  meck:expect(al_soc_elk_service_db, start, fun(_DB) ->
    {ok, c:pid(0,251,0)} end),
  meck:expect(gascheduler, execute, fun(_, _) ->
    ok end),
  {[incidents, gascheduler, al_soc_elk_service_stats, al_soc_elk_service_customers,
    al_soc_elk_service_elasticsearch, al_soc_elk_service_db]}.

teardown({Apps}) ->
  meck:unload(Apps),
  ok.
all_test_() ->
  {
    setup,
    fun setup/0,
    fun teardown/1,
    [
      {"scheduler", {timeout, ?TEST_TIMEOUT, fun test_scheduler/0}},
      {"workers", {timeout, ?TEST_TIMEOUT, fun test_workers/0}},
      {"stop_all", {timeout, ?TEST_TIMEOUT, fun test_stop_all/0}},
      {"cache", {timeout, ?TEST_TIMEOUT, fun test_cache/0}},
      {"set_workers", {timeout, ?TEST_TIMEOUT, fun test_set_workers/0}},
      {"others", {timeout, ?TEST_TIMEOUT, fun test_others/0}}
    ]
  }.
elpaisa commented 7 years ago

rebar.config

%%-*- mode: erlang -*-
%% ex: ft=erlang
%% {require_otp_vsn, "R19"}.

{erl_opts, [debug_info]}.
{version, "1.0.0"}.
%%{run_user, "root"}.
{sub_dirs, ["rel"]}.
{deps, [
  %% third party

  {jsonx, "", {git, "https://github.com/elpaisa/jsonx.git", {branch, master}}},

  %% Add meck to the list of dependencies
  {meck, "", {git, "https://github.com/basho/meck.git", {tag, "0.8.4"}}},

  %% Include covertool as a dependency

  {mysql, "", {git, "https://github.com/mysql-otp/mysql-otp.git", {tag, "1.2.0"}}},
  {gascheduler, "", {git, "https://github.com/GameAnalytics/gascheduler",  {tag, "1.1.0"} }},
  {elasticsearch, "", {git, "https://github.com/elpaisa/erlangelk", {tag, "0.0.5"}}},
  {qdate, "", {git, "https://github.com/elpaisa/qdate", {tag, "0.4.3"}}},
  {egeoip, "", {git, "https://github.com/mochi/egeoip", {branch, master}}},
  lhttpc
]}.

{plugins, [rebar_covertool]}.

{pre_hooks, [{clean, "rm -rf ebin test/*.beam dialyzer.output .eunit erl_crash.dump logs/* *.log *.coverage.xml"}]}.
{post_hooks, [{'delete-deps', "rm -rf deps .dialyzer_deps_plt"}]}.

{ct_extra_params, "-ct_hooks cth_surefire -erl_args -config erl.config"}.

{cover_enabled, false}.
{cover_export_enabled, false}.
{cover_print_enabled, false}.
{covertool_eunit, {".eunit/cover.coverdata", "eunit.coverage.xml"}}.
{covertool_ct, {"ct.coverdata", "ct.coverage.xml"}}.
{covertool_prefix_len, 2}. % Optional: Use module prefix as (imaginary) package name

{shell, [
  {apps, [al_soc_elk_service]},
  {config, "config/sys.config"}
]}.

{relx, [
  {release, {al_soc_elk_service, "0.0.1"},
    [al_soc_elk_service]
  },
  {dev_mode, false},
  {include_erts, false},
  {extended_start_script, true},

  {sys_config, "config/sys.config"},
  {vm_args, "config/vm.args"}
]}.

{deps_dir, "lib"}.
talentdeficit commented 7 years ago

are you using precompiled beam files (or using a tool that generates them?) cover can't work on files that don't include debug info. this error message could definitely be more helpful though

elpaisa commented 7 years ago

I was having the problem with Macports Erlang 19.2, i installed Homebrew Erlang 19.3 and the issue is gone.