Skip to content

Commit

Permalink
Add LFE support to eunit command (bug 952)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncer Ayaz committed Jan 26, 2011
1 parent a8066b3 commit c1c5172
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/rebar_eunit.erl
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions src/rebar_lfe_compiler.erl
Expand Up @@ -30,6 +30,8 @@

-export([compile/2]).

-export([dotlfe_compile/3]).

-include("rebar.hrl").

%% ===================================================================
Expand All @@ -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" ++
Expand All @@ -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
Expand Down

0 comments on commit c1c5172

Please sign in to comment.