From ad2f30ccb90fd160a318d10e25e22c6fd4ce2537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 2 Jul 2012 12:14:05 +0300 Subject: [PATCH] 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. --- src/rebar_eunit.erl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 21228df..42c6fdd 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -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