summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-04-03 11:14:08 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-04-03 11:14:08 -0400
commit6fe3c02de823f4196032a0e6564e41006b74cbc1 (patch)
treec4549903439698b79a800c942695d053abaf2a8c /src
parent9a985df6e457cd558e7b5868de896b6b4a5043aa (diff)
parentdf4673d378ed9417a79d22aea7251f7f04468f77 (diff)
Merge pull request #298 from talentdeficit/cover_paths
cover enhancements
Diffstat (limited to 'src')
-rw-r--r--src/rebar_prv_cover.erl36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl
index d6e18dc..13c12d1 100644
--- a/src/rebar_prv_cover.erl
+++ b/src/rebar_prv_cover.erl
@@ -14,7 +14,7 @@
-include("rebar.hrl").
-define(PROVIDER, cover).
--define(DEPS, []).
+-define(DEPS, [app_discovery]).
%% ===================================================================
%% Public API
@@ -29,7 +29,8 @@ init(State) ->
{example, "rebar3 cover"},
{short_desc, "Perform coverage analysis."},
{desc, ""},
- {opts, cover_opts(State)}])),
+ {opts, cover_opts(State)},
+ {profiles, [test]}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
@@ -135,14 +136,25 @@ import(CoverData) ->
end.
analysis(State, Task) ->
+ OldPath = code:get_path(),
+ ok = restore_cover_paths(State),
Mods = cover:imported_modules(),
- lists:map(
- fun(Mod) ->
- {ok, Answer} = cover:analyze(Mod, coverage, line),
- {ok, File} = analyze_to_file(Mod, State, Task),
- {Mod, process(Answer), File}
- end,
- Mods).
+ Analysis = lists:map(fun(Mod) ->
+ {ok, Answer} = cover:analyze(Mod, coverage, line),
+ {ok, File} = analyze_to_file(Mod, State, Task),
+ {Mod, process(Answer), File}
+ end,
+ Mods),
+ true = code:set_path(OldPath),
+ Analysis.
+
+restore_cover_paths(State) ->
+ lists:foreach(fun(App) ->
+ AppDir = rebar_app_info:out_dir(App),
+ _ = code:add_path(filename:join([AppDir, "ebin"]))
+ end, rebar_state:project_apps(State)),
+ _ = code:add_path(filename:join([rebar_dir:base_dir(State), "ebin"])),
+ ok.
analyze_to_file(Mod, State, Task) ->
CoverDir = cover_dir(State),
@@ -319,8 +331,7 @@ write_coverdata(State, Task) ->
ExportFile = filename:join([DataDir, atom_to_list(Task) ++ ".coverdata"]),
case cover:export(ExportFile) of
ok ->
- ?DEBUG("Cover data written to ~p.", [ExportFile]),
- ok;
+ ?DEBUG("Cover data written to ~p.", [ExportFile]);
{error, Reason} ->
?WARN("Cover data export failed: ~p", [Reason])
end.
@@ -333,7 +344,8 @@ verbose(State) ->
end.
cover_dir(State) ->
- rebar_state:get(State, cover_data_dir, filename:join(["_build", "cover"])).
+ rebar_state:get(State, cover_data_dir, filename:join([rebar_dir:base_dir(State),
+ "cover"])).
cover_opts(_State) ->
[{reset, $r, "reset", boolean, help(reset)},