summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2015-03-08 15:57:50 -0500
committerTristan Sloughter <tristan.sloughter@gmail.com>2015-03-08 15:57:50 -0500
commitd020c0089d932741d9618e790601c23d9dcab3f5 (patch)
tree63fada6a4f9828b9b6d839848c76cc37e738b3d3
parent963f9754233b53933e7febda350666400f439fdd (diff)
parentb0300f1b2f1c366510463e3a110694e225f69ae3 (diff)
Merge pull request #251 from talentdeficit/compile_from_build
symlink extra test dirs and compile from there instead of from root project
-rw-r--r--src/rebar_otp_app.erl2
-rw-r--r--src/rebar_prv_common_test.erl37
-rw-r--r--src/rebar_prv_eunit.erl17
3 files changed, 36 insertions, 20 deletions
diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl
index 2b5f682..a93defc 100644
--- a/src/rebar_otp_app.erl
+++ b/src/rebar_otp_app.erl
@@ -159,7 +159,7 @@ validate_name(AppName, File) ->
ebin_modules(App, Dir) ->
Beams = lists:sort(rebar_utils:beams(filename:join(Dir, "ebin"))),
- F = fun(Beam) -> not lists:prefix(filename:join([rebar_app_info:dir(App), "test"]),
+ F = fun(Beam) -> not lists:prefix(filename:join([rebar_app_info:out_dir(App), "test"]),
beam_src(Beam))
end,
Filtered = lists:filter(F, Beams),
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 2fa2e28..c49f4c5 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -369,28 +369,37 @@ compile_tests(State, TestApps, InDirs) ->
AppState ->
AppState
end,
- ok = rebar_erlc_compiler:compile(replace_src_dirs(S, InDirs),
+ ok = rebar_erlc_compiler:compile(replace_src_dirs(S, ["test"]),
ec_cnv:to_list(rebar_app_info:out_dir(AppInfo)))
end,
lists:foreach(F, TestApps),
- compile_bare_tests(State, TestApps, InDirs).
+ compile_extra_tests(State, TestApps, InDirs).
-compile_bare_tests(State, TestApps, InDirs) ->
+%% extra directories containing tests can be passed to ct via the `dir` option
+compile_extra_tests(State, TestApps, InDirs) ->
F = fun(App) -> rebar_app_info:dir(App) == rebar_dir:get_cwd() end,
- case lists:filter(F, TestApps) of
- %% compile just the `test` directory of the base dir
- [] -> rebar_erlc_compiler:compile(replace_src_dirs(State, InDirs),
- rebar_dir:get_cwd(),
- filename:join([rebar_dir:base_dir(State), "ebin"]));
+ TestDirs = case lists:filter(F, TestApps) of
+ %% add `test` to indirs if it exists at the root of the project and
+ %% it hasn't already been compiled
+ [] -> ["test"|InDirs];
%% already compiled `./test` so do nothing
- _ -> ok
- end.
-
-replace_src_dirs(State, InDirs) ->
- %% replace any `src_dirs` with just the `test` dir and any `InDirs`
+ _ -> InDirs
+ end,
+ %% symlink each of the extra dirs
+ lists:foreach(fun(Dir) ->
+ Source = filename:join([rebar_dir:get_cwd(), Dir]),
+ Target = filename:join([rebar_dir:base_dir(State), Dir]),
+ ok = rebar_file_utils:symlink_or_copy(Source, Target)
+ end, TestDirs),
+ rebar_erlc_compiler:compile(replace_src_dirs(State, TestDirs),
+ rebar_dir:base_dir(State),
+ filename:join([rebar_dir:base_dir(State), "ebin"])).
+
+replace_src_dirs(State, Dirs) ->
+ %% replace any `src_dirs` with the test dirs
ErlOpts = rebar_state:get(State, erl_opts, []),
StrippedOpts = lists:keydelete(src_dirs, 1, ErlOpts),
- rebar_state:set(State, erl_opts, [{src_dirs, ["test"|InDirs]}|StrippedOpts]).
+ rebar_state:set(State, erl_opts, [{src_dirs, Dirs}|StrippedOpts]).
maybe_cover_compile(State, Opts) ->
State1 = case proplists:get_value(cover, Opts, false) of
diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl
index 1540471..8763344 100644
--- a/src/rebar_prv_eunit.erl
+++ b/src/rebar_prv_eunit.erl
@@ -140,15 +140,22 @@ compile_tests(State, TestApps) ->
ec_cnv:to_list(rebar_app_info:out_dir(AppInfo)))
end,
lists:foreach(F, TestApps),
- compile_bare_tests(State, TestApps).
+ case filelib:is_dir(filename:join([rebar_dir:get_cwd(), "test"])) of
+ true -> compile_bare_tests(State, TestApps);
+ false -> ok
+ end.
compile_bare_tests(State, TestApps) ->
F = fun(App) -> rebar_app_info:dir(App) == rebar_dir:get_cwd() end,
case lists:filter(F, TestApps) of
- %% compile just the `test` directory of the base dir
- [] -> rebar_erlc_compiler:compile(replace_src_dirs(State),
- rebar_dir:get_cwd(),
- filename:join([rebar_dir:base_dir(State), "ebin"]));
+ %% compile and link just the `test` directory of the base dir
+ [] ->
+ Source = filename:join([rebar_dir:get_cwd(), "test"]),
+ Target = filename:join([rebar_dir:base_dir(State), "test"]),
+ ok = rebar_file_utils:symlink_or_copy(Source, Target),
+ rebar_erlc_compiler:compile(replace_src_dirs(State),
+ rebar_dir:base_dir(State),
+ filename:join([rebar_dir:base_dir(State), "ebin"]));
%% already compiled `./test` so do nothing
_ -> ok
end.