Sfoglia il codice sorgente

move definition of 'EUNIT' macro to eunit provider

add definition of 'COMMON_TEST' macro to eunit provider
pull/1108/head
alisdair sullivan 9 anni fa
parent
commit
0bd5e230d2
4 ha cambiato i file con 103 aggiunte e 12 eliminazioni
  1. +19
    -1
      src/rebar_prv_common_test.erl
  2. +19
    -1
      src/rebar_prv_eunit.erl
  3. +28
    -4
      test/rebar_ct_SUITE.erl
  4. +37
    -6
      test/rebar_eunit_SUITE.erl

+ 19
- 1
src/rebar_prv_common_test.erl Vedi File

@ -329,9 +329,27 @@ include_files(Opts, Tests) ->
Is = lists:map(fun(I) -> {i, I} end, Includes),
case append(Is, ErlOpts) of
{error, _} = Error -> Error;
NewIncludes -> rebar_opts:set(Opts, erl_opts, NewIncludes)
NewIncludes -> ct_macro(rebar_opts:set(Opts, erl_opts, NewIncludes))
end.
ct_macro(Opts) ->
ErlOpts = opts(Opts, erl_opts, []),
NewOpts = safe_define_ct_macro(ErlOpts),
rebar_opts:set(Opts, erl_opts, NewOpts).
safe_define_ct_macro(Opts) ->
%% defining a compile macro twice results in an exception so
%% make sure 'COMMON_TEST' is only defined once
case test_defined(Opts) of
true -> Opts;
false -> [{d, 'COMMON_TEST'}|Opts]
end.
test_defined([{d, 'COMMON_TEST'}|_]) -> true;
test_defined([{d, 'COMMON_TEST', true}|_]) -> true;
test_defined([_|Rest]) -> test_defined(Rest);
test_defined([]) -> false.
append({error, _} = Error, _) -> Error;
append(_, {error, _} = Error) -> Error;
append(A, B) -> A ++ B.

+ 19
- 1
src/rebar_prv_eunit.erl Vedi File

@ -244,9 +244,27 @@ first_files(Opts) ->
EUnitFirstFiles = opts(Opts, eunit_first_files, []),
case append(EUnitFirstFiles, FirstFiles) of
{error, _} = Error -> Error;
NewFirstFiles -> rebar_opts:set(Opts, erl_first_files, NewFirstFiles)
NewFirstFiles -> eunit_macro(rebar_opts:set(Opts, erl_first_files, NewFirstFiles))
end.
eunit_macro(Opts) ->
ErlOpts = opts(Opts, erl_opts, []),
NewOpts = safe_define_eunit_macro(ErlOpts),
rebar_opts:set(Opts, erl_opts, NewOpts).
safe_define_eunit_macro(Opts) ->
%% defining a compile macro twice results in an exception so
%% make sure 'EUNIT' is only defined once
case test_defined(Opts) of
true -> Opts;
false -> [{d, 'EUNIT'}|Opts]
end.
test_defined([{d, 'EUNIT'}|_]) -> true;
test_defined([{d, 'EUNIT', true}|_]) -> true;
test_defined([_|Rest]) -> test_defined(Rest);
test_defined([]) -> false.
append({error, _} = Error, _) -> Error;
append(_, {error, _} = Error) -> Error;
append(A, B) -> A ++ B.

+ 28
- 4
test/rebar_ct_SUITE.erl Vedi File

@ -6,8 +6,10 @@
end_per_group/2]).
-export([basic_app_default_dirs/1,
basic_app_default_beams/1,
basic_app_ct_macro/1,
multi_app_default_dirs/1,
multi_app_default_beams/1,
multi_app_ct_macro/1,
single_app_dir/1,
single_extra_dir/1,
single_unmanaged_dir/1,
@ -65,9 +67,11 @@ all() -> [{group, basic_app},
misspecified_ct_first_files].
groups() -> [{basic_app, [], [basic_app_default_dirs,
basic_app_default_beams]},
basic_app_default_beams,
basic_app_ct_macro]},
{multi_app, [], [multi_app_default_dirs,
multi_app_default_beams]},
multi_app_default_beams,
multi_app_ct_macro]},
{dirs_and_suites, [], [single_app_dir,
single_extra_dir,
single_unmanaged_dir,
@ -121,7 +125,7 @@ init_per_group(basic_app, Config) ->
{ok, T} = Tests,
Opts = rebar_prv_common_test:translate_paths(NewState, T),
[{result, Opts}, {appnames, [Name]}|C];
[{result, Opts}, {appnames, [Name]}, {compile_state, NewState}|C];
init_per_group(multi_app, Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_"),
@ -156,7 +160,7 @@ init_per_group(multi_app, Config) ->
{ok, T} = Tests,
Opts = rebar_prv_common_test:translate_paths(NewState, T),
[{result, Opts}, {appnames, [Name1, Name2]}|C];
[{result, Opts}, {appnames, [Name1, Name2]}, {compile_state, NewState}|C];
init_per_group(dirs_and_suites, Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_"),
@ -255,6 +259,15 @@ basic_app_default_beams(Config) ->
true = filelib:is_file(File).
basic_app_ct_macro(Config) ->
State = ?config(compile_state, Config),
[App] = rebar_state:project_apps(State),
Opts = rebar_app_info:opts(App),
ErlOpts = dict:fetch(erl_opts, Opts),
true = lists:member({d, 'COMMON_TEST'}, ErlOpts).
multi_app_default_dirs(Config) ->
AppDir = ?config(apps, Config),
[Name1, Name2] = ?config(appnames, Config),
@ -296,6 +309,16 @@ multi_app_default_beams(Config) ->
true = filelib:is_file(File2),
true = filelib:is_file(File3).
multi_app_ct_macro(Config) ->
State = ?config(compile_state, Config),
Apps = rebar_state:project_apps(State),
lists:foreach(fun(App) ->
Opts = rebar_app_info:opts(App),
ErlOpts = dict:fetch(erl_opts, Opts),
true = lists:member({d, 'COMMON_TEST'}, ErlOpts)
end, Apps).
single_app_dir(Config) ->
AppDir = ?config(apps, Config),
[Name1, _Name2] = ?config(appnames, Config),
@ -1158,6 +1181,7 @@ misspecified_ct_first_files(Config) ->
{badconfig, {"Value `~p' of option `~p' must be a list", {some_file, ct_first_files}}} = Error.
%% helper for generating test data
test_suite(Name) ->
io_lib:format("-module(~ts_SUITE).\n"

+ 37
- 6
test/rebar_eunit_SUITE.erl Vedi File

@ -2,8 +2,12 @@
-export([all/0, groups/0]).
-export([init_per_suite/1, init_per_group/2, end_per_group/2]).
-export([basic_app_compiles/1, basic_app_files/1, basic_app_exports/1, basic_app_testset/1]).
-export([multi_app_compiles/1, multi_app_files/1, multi_app_exports/1, multi_app_testset/1]).
-export([basic_app_compiles/1, basic_app_files/1]).
-export([basic_app_exports/1, basic_app_testset/1]).
-export([basic_app_eunit_macro/1]).
-export([multi_app_compiles/1, multi_app_files/1]).
-export([multi_app_exports/1, multi_app_testset/1]).
-export([multi_app_eunit_macro/1]).
-export([eunit_tests/1, eunit_opts/1, eunit_first_files/1]).
-export([single_application_arg/1, multi_application_arg/1, missing_application_arg/1]).
-export([single_module_arg/1, multi_module_arg/1, missing_module_arg/1]).
@ -27,9 +31,15 @@ all() ->
groups() ->
[{basic_app, [sequence], [basic_app_compiles, {group, basic_app_results}]},
{basic_app_results, [], [basic_app_files, basic_app_exports, basic_app_testset]},
{basic_app_results, [], [basic_app_files,
basic_app_exports,
basic_app_testset,
basic_app_eunit_macro]},
{multi_app, [sequence], [multi_app_compiles, {group, multi_app_results}]},
{multi_app_results, [], [multi_app_files, multi_app_exports, multi_app_testset]},
{multi_app_results, [], [multi_app_files,
multi_app_exports,
multi_app_testset,
multi_app_eunit_macro]},
{cmd_line_args, [], [eunit_tests, eunit_opts, eunit_first_files,
single_application_arg, multi_application_arg, missing_application_arg,
single_module_arg, multi_module_arg, missing_module_arg,
@ -160,7 +170,16 @@ basic_app_testset(Config) ->
{module, basic_app_tests_helper}]},
Set = rebar_prv_eunit:prepare_tests(Result).
basic_app_eunit_macro(_Config) ->
Macro = fun(Mod) ->
begin
Path = code:which(Mod),
{ok, {Mod, [{compile_info, CompileInfo}]}} = beam_lib:chunks(Path, [compile_info]),
Opts = proplists:get_value(options, CompileInfo, []),
true = lists:member({d, 'EUNIT'}, Opts)
end
end,
lists:foreach(Macro, [basic_app, basic_app_tests, basic_app_tests_helper]).
%% === tests for multiple applications in the `apps' directory of a project ===
@ -220,7 +239,19 @@ multi_app_testset(Config) ->
{module, multi_app_tests_helper}]},
Set = rebar_prv_eunit:prepare_tests(Result).
multi_app_eunit_macro(_Config) ->
Macro = fun(Mod) ->
begin
Path = code:which(Mod),
{ok, {Mod, [{compile_info, CompileInfo}]}} = beam_lib:chunks(Path, [compile_info]),
Opts = proplists:get_value(options, CompileInfo, []),
true = lists:member({d, 'EUNIT'}, Opts)
end
end,
lists:foreach(Macro, [multi_app_bar, multi_app_bar_tests,
multi_app_baz, multi_app_baz_tests,
multi_app_tests, multi_app_tests_helper,
multi_app_bar_tests_helper, multi_app_baz_tests_helper]).
%% === tests for command line arguments ===

Caricamento…
Annulla
Salva