Sfoglia il codice sorgente

symlink extra test dirs and compile from there instead of from

root project
pull/251/head
alisdair sullivan 10 anni fa
parent
commit
b0300f1b2f
3 ha cambiato i file con 36 aggiunte e 20 eliminazioni
  1. +1
    -1
      src/rebar_otp_app.erl
  2. +23
    -14
      src/rebar_prv_common_test.erl
  3. +12
    -5
      src/rebar_prv_eunit.erl

+ 1
- 1
src/rebar_otp_app.erl Vedi File

@ -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),

+ 23
- 14
src/rebar_prv_common_test.erl Vedi File

@ -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

+ 12
- 5
src/rebar_prv_eunit.erl Vedi File

@ -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.

Caricamento…
Annulla
Salva