summaryrefslogtreecommitdiff
path: root/src/rebar_prv_cover.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_prv_cover.erl')
-rw-r--r--src/rebar_prv_cover.erl33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl
index 13c12d1..0ee6742 100644
--- a/src/rebar_prv_cover.erl
+++ b/src/rebar_prv_cover.erl
@@ -8,6 +8,7 @@
-export([init/1,
do/1,
maybe_cover_compile/1,
+ maybe_cover_compile/2,
maybe_write_coverdata/2,
format_error/1]).
@@ -43,8 +44,12 @@ do(State) ->
-spec maybe_cover_compile(rebar_state:t()) -> ok.
maybe_cover_compile(State) ->
+ maybe_cover_compile(State, []).
+
+-spec maybe_cover_compile(rebar_state:t(), [file:name()]) -> ok.
+maybe_cover_compile(State, ExtraDirs) ->
case rebar_state:get(State, cover_enabled, false) of
- true -> cover_compile(State);
+ true -> cover_compile(State, ExtraDirs);
false -> ok
end.
@@ -151,9 +156,10 @@ analysis(State, Task) ->
restore_cover_paths(State) ->
lists:foreach(fun(App) ->
AppDir = rebar_app_info:out_dir(App),
- _ = code:add_path(filename:join([AppDir, "ebin"]))
+ _ = code:add_path(filename:join([AppDir, "ebin"])),
+ _ = code:add_path(filename:join([AppDir, "test"]))
end, rebar_state:project_apps(State)),
- _ = code:add_path(filename:join([rebar_dir:base_dir(State), "ebin"])),
+ _ = code:add_path(filename:join([rebar_dir:base_dir(State), "test"])),
ok.
analyze_to_file(Mod, State, Task) ->
@@ -269,7 +275,7 @@ strip_coverdir(File) ->
filename:join(lists:reverse(lists:sublist(lists:reverse(filename:split(File)),
2))).
-cover_compile(State) ->
+cover_compile(State, ExtraDirs) ->
%% start the cover server if necessary
{ok, CoverPid} = start_cover(),
%% redirect cover output
@@ -277,7 +283,7 @@ cover_compile(State) ->
%% cover compile the modules we just compiled
Apps = filter_checkouts(rebar_state:project_apps(State)),
CompileResult = compile_beam_directories(Apps, []) ++
- compile_bare_test_directory(State),
+ compile_extras(ExtraDirs, []),
%% print any warnings about modules that failed to cover compile
lists:foreach(fun print_cover_warnings/1, CompileResult).
@@ -285,10 +291,8 @@ filter_checkouts(Apps) -> filter_checkouts(Apps, []).
filter_checkouts([], Acc) -> lists:reverse(Acc);
filter_checkouts([App|Rest], Acc) ->
- AppDir = filename:absname(rebar_app_info:dir(App)),
- CheckoutsDir = filename:absname("_checkouts"),
- case lists:prefix(CheckoutsDir, AppDir) of
- true -> filter_checkouts(Rest, Acc);
+ case rebar_app_info:is_checkout(App) of
+ true -> filter_checkouts(Rest, Acc);
false -> filter_checkouts(Rest, [App|Acc])
end.
@@ -298,13 +302,10 @@ compile_beam_directories([App|Rest], Acc) ->
"ebin"])),
compile_beam_directories(Rest, Acc ++ Result).
-compile_bare_test_directory(State) ->
- case cover:compile_beam_directory(filename:join([rebar_dir:base_dir(State),
- "ebin"])) of
- %% if directory doesn't exist just return empty result set
- {error, enoent} -> [];
- Result -> Result
- end.
+compile_extras([], Acc) -> Acc;
+compile_extras([Dir|Rest], Acc) ->
+ Result = cover:compile_beam_directory(Dir),
+ compile_extras(Rest, Acc ++ Result).
start_cover() ->
case cover:start() of