From c996e9878b76567b06c83e41bebbe783cced19b5 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 29 Apr 2014 18:36:33 +0900 Subject: [PATCH] Make sure that eunit/qc_compile_opts works fix #245 --- THANKS | 1 + inttest/eunit/eunit_rt.erl | 48 +++++++++++++++++++ inttest/eunit/eunit_src/bar.erl | 6 +++ inttest/eunit/rebar-eunit_compile_opts.config | 1 + inttest/eunit/src/foo.erl | 10 ++++ src/rebar_erlc_compiler.erl | 19 ++++---- 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 inttest/eunit/eunit_rt.erl create mode 100644 inttest/eunit/eunit_src/bar.erl create mode 100644 inttest/eunit/rebar-eunit_compile_opts.config create mode 100644 inttest/eunit/src/foo.erl diff --git a/THANKS b/THANKS index 753d0dc..66d7b25 100644 --- a/THANKS +++ b/THANKS @@ -122,3 +122,4 @@ Oliver Ferrigni Dave Thomas Evgeniy Khramtsov YeJun Su +Yuki Ito diff --git a/inttest/eunit/eunit_rt.erl b/inttest/eunit/eunit_rt.erl new file mode 100644 index 0000000..47f3331 --- /dev/null +++ b/inttest/eunit/eunit_rt.erl @@ -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]). diff --git a/inttest/eunit/eunit_src/bar.erl b/inttest/eunit/eunit_src/bar.erl new file mode 100644 index 0000000..6a80dac --- /dev/null +++ b/inttest/eunit/eunit_src/bar.erl @@ -0,0 +1,6 @@ +-module(bar). + +-include_lib("eunit/include/eunit.hrl"). + +bar_test() -> + ?assert(true). diff --git a/inttest/eunit/rebar-eunit_compile_opts.config b/inttest/eunit/rebar-eunit_compile_opts.config new file mode 100644 index 0000000..13b2d94 --- /dev/null +++ b/inttest/eunit/rebar-eunit_compile_opts.config @@ -0,0 +1 @@ +{eunit_compile_opts, [{src_dirs, ["eunit_src"]}]}. diff --git a/inttest/eunit/src/foo.erl b/inttest/eunit/src/foo.erl new file mode 100644 index 0000000..a4c91ba --- /dev/null +++ b/inttest/eunit/src/foo.erl @@ -0,0 +1,10 @@ +-module(foo). + +-ifdef(TEST). + +-include_lib("eunit/include/eunit.hrl"). + +foo_test() -> + ?assert(true). + +-endif. diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 75d47fb..1a7cf01 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -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,