summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2015-11-04 09:14:24 -0600
committerTristan Sloughter <t@crashfast.com>2015-11-04 09:14:24 -0600
commitf02ec399850ca40c75d66ff690c6edf005189c9a (patch)
tree111101ec13925d9c4b55ddcd4e69c7c5c60cb24e
parent5ad5ceb6c33e72203672cc56df3b3dda7a1625e5 (diff)
parentd8be03ab6a75b2f585487118ae38085c2f758d3c (diff)
Merge pull request #905 from talentdeficit/cover_fixes
fixes for cover under new compiler/eunit/ct
-rw-r--r--src/rebar_prv_cover.erl32
-rw-r--r--test/rebar_cover_SUITE.erl25
2 files changed, 37 insertions, 20 deletions
diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl
index 0b9b9bb..15a067e 100644
--- a/src/rebar_prv_cover.erl
+++ b/src/rebar_prv_cover.erl
@@ -279,21 +279,26 @@ cover_compile(State, apps) ->
Apps = filter_checkouts(rebar_state:project_apps(State)),
AppDirs = app_dirs(Apps),
ExtraDirs = extra_src_dirs(State, Apps),
- cover_compile(State, AppDirs ++ ExtraDirs);
+ cover_compile(State, lists:filter(fun(D) -> ec_file:is_dir(D) end, AppDirs ++ ExtraDirs));
cover_compile(State, Dirs) ->
%% start the cover server if necessary
{ok, CoverPid} = start_cover(),
%% redirect cover output
true = redirect_cover_output(State, CoverPid),
- CompileResult = compile(Dirs, []),
- %% print any warnings about modules that failed to cover compile
- lists:foreach(fun print_cover_warnings/1, lists:flatten(CompileResult)).
-
-compile([], Acc) -> lists:reverse(Acc);
-compile([Dir|Rest], Acc) ->
- ?INFO("covering ~p", [Dir]),
- Result = cover:compile_beam_directory(Dir),
- compile(Rest, [Result|Acc]).
+ lists:foreach(fun(Dir) ->
+ ?DEBUG("cover compiling ~p", [Dir]),
+ case catch(cover:compile_beam_directory(Dir)) of
+ {error, eacces} ->
+ ?WARN("Directory ~p not readable, modules will not be included in coverage", [Dir]);
+ {error, enoent} ->
+ ?WARN("Directory ~p not found", [Dir]);
+ {'EXIT', {Reason, _}} ->
+ ?WARN("Cover compilation for directory ~p failed: ~p", [Dir, Reason]);
+ Results ->
+ %% print any warnings about modules that failed to cover compile
+ lists:foreach(fun print_cover_warnings/1, lists:flatten(Results))
+ end
+ end, Dirs).
app_dirs(Apps) ->
lists:foldl(fun app_ebin_dirs/2, [], Apps).
@@ -302,7 +307,7 @@ app_ebin_dirs(App, Acc) ->
AppDir = rebar_app_info:ebin_dir(App),
ExtraDirs = rebar_dir:extra_src_dirs(rebar_app_info:opts(App), []),
OutDir = rebar_app_info:out_dir(App),
- [filename:join([OutDir, D]) || D <- [AppDir|ExtraDirs]] ++ Acc.
+ [AppDir] ++ [filename:join([OutDir, D]) || D <- ExtraDirs] ++ Acc.
extra_src_dirs(State, Apps) ->
BaseDir = rebar_state:dir(State),
@@ -339,9 +344,8 @@ redirect_cover_output(State, CoverPid) ->
group_leader(F, CoverPid).
print_cover_warnings({ok, _}) -> ok;
-print_cover_warnings({error, File}) ->
- ?WARN("Cover compilation of ~p failed, module is not included in cover data.",
- [File]).
+print_cover_warnings({error, Error}) ->
+ ?WARN("Cover compilation failed: ~p", [Error]).
write_coverdata(State, Task) ->
DataDir = cover_dir(State),
diff --git a/test/rebar_cover_SUITE.erl b/test/rebar_cover_SUITE.erl
index ba078c2..a838d7d 100644
--- a/test/rebar_cover_SUITE.erl
+++ b/test/rebar_cover_SUITE.erl
@@ -72,7 +72,7 @@ basic_extra_src_dirs(Config) ->
Name = rebar_test_utils:create_random_name("cover_extra_"),
Vsn = rebar_test_utils:create_random_vsn(),
- rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
@@ -86,8 +86,11 @@ basic_extra_src_dirs(Config) ->
["eunit", "--cover"],
{ok, [{app, Name}]}),
- Mod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
- {file, _} = cover:is_compiled(Mod).
+ Mod = list_to_atom(Name),
+ {file, _} = cover:is_compiled(Mod),
+
+ ExtraMod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
+ {file, _} = cover:is_compiled(ExtraMod).
release_extra_src_dirs(Config) ->
AppDir = ?config(apps, Config),
@@ -120,10 +123,15 @@ release_extra_src_dirs(Config) ->
["eunit", "--cover"],
{ok, [{app, Name1}, {app, Name2}]}),
- Mod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
+ Mod1 = list_to_atom(Name1),
{file, _} = cover:is_compiled(Mod1),
- Mod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
- {file, _} = cover:is_compiled(Mod2).
+ Mod2 = list_to_atom(Name2),
+ {file, _} = cover:is_compiled(Mod2),
+
+ ExtraMod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
+ {file, _} = cover:is_compiled(ExtraMod1),
+ ExtraMod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
+ {file, _} = cover:is_compiled(ExtraMod2).
root_extra_src_dirs(Config) ->
AppDir = ?config(apps, Config),
@@ -147,6 +155,11 @@ root_extra_src_dirs(Config) ->
["eunit", "--cover"],
{ok, [{app, Name1}, {app, Name2}]}),
+ Mod1 = list_to_atom(Name1),
+ {file, _} = cover:is_compiled(Mod1),
+ Mod2 = list_to_atom(Name2),
+ {file, _} = cover:is_compiled(Mod2),
+
{file, _} = cover:is_compiled(extra).
index_written(Config) ->