diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index f1ddead9..b1f71029 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -90,16 +90,29 @@ eunit(Config, AppFile) -> %% {eunit_compile_opts, [{src_dirs, ["test"]}]} TestErls = rebar_utils:find_files("test", ".*\\.erl\$"), + %% Obtain all the test LFE modules for inclusion in the compile stage + TestLfes = rebar_utils:find_files("test", ".*\\.lfe\$"), + + %% Obtain src/{*.erl, *.lfe} files + SrcErls = rebar_utils:find_files("src", ".*\\.erl\$"), + %% Copy source files to eunit dir for cover in case they are not directly %% in src but in a subdirectory of src. Cover only looks in cwd and ../src %% for source files. - SrcErls = rebar_utils:find_files("src", ".*\\.erl\$"), - ok = rebar_file_utils:cp_r(SrcErls ++ TestErls, ?EUNIT_DIR), + case SrcErls ++ TestErls of + [] -> + %% List can be empty in a pure LFE project + ok; + Sources -> + ok = rebar_file_utils:cp_r(Sources, ?EUNIT_DIR) + end, - %% Compile erlang code to ?EUNIT_DIR, using a tweaked config + %% Compile erlang and lfe code to ?EUNIT_DIR, using a tweaked config %% with appropriate defines for eunit, and include all the test modules %% as well. - rebar_erlc_compiler:doterl_compile(eunit_config(Config), ?EUNIT_DIR, TestErls), + EUnitConfig = eunit_config(Config), + ok = rebar_erlc_compiler:doterl_compile(EUnitConfig, ?EUNIT_DIR, TestErls), + ok = rebar_lfe_compiler:dotlfe_compile(EUnitConfig, ?EUNIT_DIR, TestLfes), %% Build a list of all the .beams in ?EUNIT_DIR -- use this for cover %% and eunit testing. Normally you can just tell cover and/or eunit to diff --git a/src/rebar_lfe_compiler.erl b/src/rebar_lfe_compiler.erl index 4451530c..bff5e413 100644 --- a/src/rebar_lfe_compiler.erl +++ b/src/rebar_lfe_compiler.erl @@ -30,6 +30,8 @@ -export([compile/2]). +-export([dotlfe_compile/3]). + -include("rebar.hrl"). %% =================================================================== @@ -41,12 +43,32 @@ compile(Config, _AppFile) -> rebar_base_compiler:run(Config, FirstFiles, "src", ".lfe", "ebin", ".beam", fun compile_lfe/3). +%% =================================================================== +%% .lfe Compilation API (externally used by only eunit) +%% =================================================================== + +dotlfe_compile(Config, OutDir, Sources) -> + FirstFiles = rebar_config:get_list(Config, lfe_first_files, []), + LfeOpts = [{outdir, OutDir}] ++ rebar_config:get(Config, lfe_opts, []) ++ + [{i, "include"}, report, return], + ?DEBUG("lfe_opts ~p~n",[LfeOpts]), + rebar_base_compiler:run(Config, FirstFiles, Sources, + fun(S, _C) -> + compile_lfe(S, LfeOpts) + end), + ok. %% =================================================================== %% Internal functions %% =================================================================== compile_lfe(Source, _Target, Config) -> + LfeOpts = rebar_config:get_list(Config, lfe_opts, []) ++ + [{i, "include"}, {outdir, "ebin"}, report, return], + ?DEBUG("lfe_opts ~p~n",[LfeOpts]), + compile_lfe(Source, LfeOpts). + +compile_lfe(Source, LfeOpts) -> case code:which(lfe_comp) of non_existing -> ?CONSOLE("~n===============================================~n" ++ @@ -57,9 +79,7 @@ compile_lfe(Source, _Target, Config) -> "===============================================~n~n", []), ?FAIL; _ -> - Opts = [{i, "include"}, {outdir, "ebin"}, report, return] ++ - rebar_config:get_list(Config, lfe_opts, []), - case lfe_comp:file(Source,Opts) of + case lfe_comp:file(Source, LfeOpts) of {ok, _, []} -> ok; _ -> ?FAIL end