diff options
author | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2015-01-08 15:50:15 -0800 |
---|---|---|
committer | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2015-01-08 16:10:35 -0800 |
commit | 16c31097c2616d1fb0038b065956c1f6442e339c (patch) | |
tree | 8a5a847df28fb5ef2b0d2ace4a795ed9a808c47e /src | |
parent | 853efc50770b9c79795184575420212da7f7ddf7 (diff) |
add support for a bare `test` directory when using `apps` libdirs
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_prv_common_test.erl | 28 | ||||
-rw-r--r-- | src/rebar_prv_eunit.erl | 31 |
2 files changed, 50 insertions, 9 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 46d3240..7a52c92 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -51,6 +51,7 @@ do(State) -> TestState = test_state(S, InDirs, OutDir), ok = rebar_erlc_compiler:compile(TestState, AppDir) end, TestApps), + ok = maybe_compile_extra_tests(TestApps, State, InDirs, OutDir), Path = code:get_path(), true = code:add_patha(OutDir), CTOpts = resolve_ct_opts(State, Opts, OutDir), @@ -283,10 +284,17 @@ test_state(State, InDirs, OutDir) -> ErlOpts = rebar_state:get(State, common_test_compile_opts, []) ++ rebar_utils:erl_opts(State), TestOpts = [{outdir, OutDir}] ++ - [{src_dirs, ["src", "test"] ++ InDirs}] ++ - ErlOpts, + add_test_dir(ErlOpts, InDirs), first_files(rebar_state:set(State, erl_opts, TestOpts)). +add_test_dir(Opts, InDirs) -> + %% if no src_dirs are set we have to specify `src` or it won't + %% be built + case proplists:append_values(src_dirs, Opts) of + [] -> [{src_dirs, ["src", "test"|InDirs]}]; + _ -> [{src_dirs, ["test"|InDirs]}] + end. + first_files(State) -> BaseFirst = rebar_state:get(State, erl_first_files, []), CTFirst = rebar_state:get(State, common_test_first_files, []), @@ -302,6 +310,22 @@ resolve_ct_opts(State, CmdLineOpts, OutDir) -> %% and disable `auto_compile` [{auto_compile, false}, {dir, OutDir}] ++ lists:keydelete(dir, 1, Opts). +maybe_compile_extra_tests(TestApps, State, InDirs, OutDir) -> + F = fun(App) -> rebar_app_info:dir(App) == rebar_dir:get_cwd() end, + case lists:filter(F, TestApps) of + %% compile just the `test` and extra test directories of the base dir + [] -> + ErlOpts = rebar_state:get(State, common_test_compile_opts, []) ++ + rebar_utils:erl_opts(State), + TestOpts = [{outdir, OutDir}] ++ + [{src_dirs, ["test"|InDirs]}] ++ + lists:keydelete(src_dirs, 1, ErlOpts), + TestState = first_files(rebar_state:set(State, erl_opts, TestOpts)), + rebar_erlc_compiler:compile(TestState, rebar_dir:get_cwd()); + %% already compiled `./test` so do nothing + _ -> ok + end. + handle_results([Result]) -> handle_results(Result); handle_results([Result|Results]) when is_list(Results) -> diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 499a04f..ee8a235 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -51,9 +51,10 @@ do(State) -> %% combine `erl_first_files` and `eunit_first_files` and adjust %% compile opts to include `eunit_compile_opts`, `{d, 'TEST'}` %% and `{src_dirs, "test"}` - TestState = first_files(test_opts(S, OutDir)), + TestState = first_files(test_state(S, OutDir)), ok = rebar_erlc_compiler:compile(TestState, AppDir) end, TestApps), + ok = maybe_compile_extra_tests(TestApps, State, OutDir), Path = code:get_path(), true = code:add_patha(OutDir), EUnitOpts = resolve_eunit_opts(State, Opts), @@ -104,12 +105,12 @@ filter_checkouts([App|Rest], Acc) -> false -> filter_checkouts(Rest, [App|Acc]) end. -test_opts(State, TmpDir) -> +test_state(State, TmpDir) -> ErlOpts = rebar_state:get(State, eunit_compile_opts, []) ++ rebar_utils:erl_opts(State), - TestOpts = [{outdir, TmpDir}] ++ - add_test_dir(ErlOpts) ++ - safe_define_test_macro(ErlOpts), + ErlOpts1 = [{outdir, TmpDir}] ++ + add_test_dir(ErlOpts), + TestOpts = safe_define_test_macro(ErlOpts1), rebar_state:set(State, erl_opts, TestOpts). add_test_dir(Opts) -> @@ -117,8 +118,8 @@ add_test_dir(Opts) -> %% be built case proplists:append_values(src_dirs, Opts) of [] -> [{src_dirs, ["src", "test"]}]; - _ -> [{src_dirs, ["test"]}] - end. + Srcs -> [{src_dirs, ["test"|Srcs]}] + end ++ lists:keydelete(src_dirs, 1, Opts). safe_define_test_macro(Opts) -> %% defining a compile macro twice results in an exception so @@ -151,6 +152,22 @@ set_verbose(Opts) -> false -> [verbose] ++ Opts end. +maybe_compile_extra_tests(TestApps, State, OutDir) -> + F = fun(App) -> rebar_app_info:dir(App) == rebar_dir:get_cwd() end, + case lists:filter(F, TestApps) of + %% compile just the `test` and extra test directories of the base dir + [] -> + ErlOpts = rebar_state:get(State, common_test_compile_opts, []) ++ + rebar_utils:erl_opts(State), + TestOpts = [{outdir, OutDir}] ++ + [{src_dirs, ["test"]}] ++ + safe_define_test_macro(lists:keydelete(src_dirs, 1, ErlOpts)), + TestState = first_files(rebar_state:set(State, erl_opts, TestOpts)), + rebar_erlc_compiler:compile(TestState, rebar_dir:get_cwd()); + %% already compiled `./test` so do nothing + _ -> ok + end. + handle_results(ok) -> ok; handle_results(error) -> {error, unknown_error}; |