Fix cover crash if src_dirs is not default

Make sure files from erl_opts->src_dirs are copied to .eunit for cover
inspection.

Without this patch cover failed to find source files which were in
src_dirs, and threw the following exception:

ERROR: eunit failed while processing
/path/to/project:
{'EXIT',{{badmatch,{error,no_source_code_found}},
         [{rebar_eunit,'-cover_analyze/3-fun-0-',1,
                       [{file,"src/rebar_eunit.erl"},{line,280}]},
          {lists,foreach,2,[{file,"lists.erl"},{line,1262}]},
          {rebar_eunit,cover_analyze,3,
                       [{file,"src/rebar_eunit.erl"},{line,279}]},
          {rebar_eunit,eunit,2,[{file,"src/rebar_eunit.erl"},{line,140}]},
          {rebar_core,run_modules,4,[{file,"src/rebar_core.erl"},{line,425}]},
          {rebar_core,execute,5,[{file,"src/rebar_core.erl"},{line,359}]},
          {rebar_core,process_dir0,6,[{file,"src/rebar_core.erl"},{line,223}]},
          {rebar_core,process_dir,4,
                      [{file,"src/rebar_core.erl"},{line,130}]}]}}

Now all source files are copied to .eunit.
This commit is contained in:
Motiejus Jakštys 2012-07-02 12:14:05 +03:00 committed by Tuncer Ayaz
parent 394c0f43f8
commit ad2f30ccb9

View file

@ -84,8 +84,17 @@ eunit(Config, _AppFile) ->
%% 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\$"),
%% for source files. Also copy files from src_dirs.
ErlOpts = rebar_utils:erl_opts(Config),
SrcErls = lists:foldl(
fun(Dir, Acc) ->
lists:append(Acc, rebar_utils:find_files(Dir, ".*\\.erl\$"))
end,
[],
rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts))
),
?DEBUG("SrcErls: ~s\n", [SrcErls]),
%% If it is not the first time rebar eunit is executed, there will be source
%% files already present in ?EUNIT_DIR. Since some SCMs (like Perforce) set