From b77d3e5083e281101a2e7820388bb7aa51143ddf Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Tue, 10 Mar 2015 09:31:04 -0700 Subject: modify `ct` provider to copy selected directories and compile them alongside their source (ie, if `some_tests` is a directory that contains test suites beams resulting from compiling them will be placed in `some_tests` in the appropriate `_build` directory --- src/rebar_prv_cover.erl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/rebar_prv_cover.erl') diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl index 13c12d1..39aa212 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. @@ -269,7 +274,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 +282,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). @@ -298,13 +303,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 -- cgit v1.1 From 471b35085b9eba80e11bf248c188a18525973526 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Fri, 3 Apr 2015 14:53:37 -0700 Subject: add default test paths in the `shell` and `cover` providers --- src/rebar_prv_cover.erl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/rebar_prv_cover.erl') diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl index 39aa212..0ee6742 100644 --- a/src/rebar_prv_cover.erl +++ b/src/rebar_prv_cover.erl @@ -156,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) -> @@ -290,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. -- cgit v1.1