Merge pull request #251 from mururu/eunit_compile_opts

Make sure that eunit/qc_compile_opts works
This commit is contained in:
Jared Morrow 2014-05-19 09:14:03 -06:00
commit 93621d0d0c
6 changed files with 76 additions and 9 deletions

1
THANKS
View file

@ -122,3 +122,4 @@ Oliver Ferrigni
Dave Thomas
Evgeniy Khramtsov
YeJun Su
Yuki Ito

View file

@ -0,0 +1,48 @@
-module(eunit_rt).
-export([files/0, run/1]).
-include_lib("eunit/include/eunit.hrl").
files() ->
[{create, "ebin/foo.app", app(foo)},
{copy, "../../rebar", "rebar"},
{copy, "src", "src"},
{copy, "eunit_src", "eunit_src"},
{copy,
"rebar-eunit_compile_opts.config",
"rebar-eunit_compile_opts.config"}].
run(_Dir) ->
ifdef_test(),
eunit_compile_opts_test(),
ok.
ifdef_test() ->
{ok, Output} = retest:sh("./rebar -v eunit"),
?assert(check_output(Output, "foo_test")),
?assertMatch({ok, _}, retest:sh("./rebar clean")).
eunit_compile_opts_test() ->
{ok, Output} =
retest:sh("./rebar -v -C rebar-eunit_compile_opts.config eunit"),
?assert(check_output(Output, "bar_test")),
?assertMatch(
{ok, _},
retest:sh("./rebar -C rebar-eunit_compile_opts.config clean")).
check_output(Output, Target) ->
lists:any(fun(Line) ->
string:str(Line, Target) > 0
end, Output).
%%
%% Generate the contents of a simple .app file
%%
app(Name) ->
App = {application, Name,
[{description, atom_to_list(Name)},
{vsn, "1"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]}]},
io_lib:format("~p.\n", [App]).

View file

@ -0,0 +1,6 @@
-module(bar).
-include_lib("eunit/include/eunit.hrl").
bar_test() ->
?assert(true).

View file

@ -0,0 +1 @@
{eunit_compile_opts, [{src_dirs, ["eunit_src"]}]}.

10
inttest/eunit/src/foo.erl Normal file
View file

@ -0,0 +1,10 @@
-module(foo).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
foo_test() ->
?assert(true).
-endif.

View file

@ -134,12 +134,13 @@ test_compile(Config, Cmd, OutDir) ->
%% Obtain all the test modules for inclusion in the compile stage.
TestErls = rebar_utils:find_files("test", ".*\\.erl\$"),
ErlOpts = rebar_utils:erl_opts(Config),
{Config1, ErlOpts1} = test_compile_config_and_opts(Config, ErlOpts, Cmd),
%% 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. Also copy files from src_dirs.
ErlOpts = rebar_utils:erl_opts(Config),
SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts)),
SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts1)),
SrcErls = lists:foldl(
fun(Dir, Acc) ->
Files = rebar_utils:find_files(Dir, ".*\\.erl\$"),
@ -172,8 +173,7 @@ test_compile(Config, Cmd, OutDir) ->
%% Compile erlang code to OutDir, using a tweaked config
%% with appropriate defines for eunit, and include all the test modules
%% as well.
ok = doterl_compile(test_compile_config(Config, ErlOpts, Cmd),
OutDir, TestErls, ErlOpts),
ok = doterl_compile(Config1, OutDir, TestErls, ErlOpts1),
{ok, SrcErls}.
@ -217,21 +217,22 @@ info_help(Description) ->
{yrl_first_files, []}
]).
test_compile_config(Config, ErlOpts, Cmd) ->
test_compile_config_and_opts(Config, ErlOpts, Cmd) ->
{Config1, TriqOpts} = triq_opts(Config),
{Config2, PropErOpts} = proper_opts(Config1),
{Config3, EqcOpts} = eqc_opts(Config2),
OptsAtom = list_to_atom(Cmd ++ "_compile_opts"),
EunitOpts = rebar_config:get_list(Config3, OptsAtom, []),
TestOpts = rebar_config:get_list(Config3, OptsAtom, []),
Opts0 = [{d, 'TEST'}] ++
ErlOpts ++ EunitOpts ++ TriqOpts ++ PropErOpts ++ EqcOpts,
ErlOpts ++ TestOpts ++ TriqOpts ++ PropErOpts ++ EqcOpts,
Opts = [O || O <- Opts0, O =/= no_debug_info],
Config4 = rebar_config:set(Config3, erl_opts, Opts),
FirstFilesAtom = list_to_atom(Cmd ++ "_first_files"),
FirstErls = rebar_config:get_list(Config4, FirstFilesAtom, []),
rebar_config:set(Config4, erl_first_files, FirstErls).
Config5 = rebar_config:set(Config4, erl_first_files, FirstErls),
{Config5, Opts}.
triq_opts(Config) ->
{NewConfig, IsAvail} = is_lib_avail(Config, is_triq_avail, triq,