diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rebar_compile_SUITE.erl | 33 | ||||
-rw-r--r-- | test/rebar_ct_SUITE.erl | 19 | ||||
-rw-r--r-- | test/rebar_deps_SUITE.erl | 34 | ||||
-rw-r--r-- | test/rebar_dir_SUITE.erl | 38 | ||||
-rw-r--r-- | test/rebar_eunit_SUITE.erl | 820 | ||||
-rw-r--r-- | test/rebar_eunit_SUITE_data/basic_app.zip | bin | 0 -> 1735 bytes | |||
-rwxr-xr-x | test/rebar_eunit_SUITE_data/deflate | 15 | ||||
-rwxr-xr-x | test/rebar_eunit_SUITE_data/inflate | 15 | ||||
-rw-r--r-- | test/rebar_eunit_SUITE_data/multi_app.zip | bin | 0 -> 5482 bytes | |||
-rw-r--r-- | test/rebar_file_utils_SUITE.erl | 24 | ||||
-rw-r--r-- | test/rebar_profiles_SUITE.erl | 4 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 2 | ||||
-rw-r--r-- | test/rebar_upgrade_SUITE.erl | 32 |
13 files changed, 610 insertions, 426 deletions
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index f726943..7750924 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -25,7 +25,8 @@ only_default_transitive_deps/1, clean_all/1, override_deps/1, - profile_override_deps/1]). + profile_override_deps/1, + build_more_sources/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -54,7 +55,7 @@ all() -> dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted, deps_in_path, checkout_priority, highest_version_of_pkg_dep, parse_transform_test, erl_first_files_test, mib_test, only_default_transitive_deps, - clean_all, override_deps, profile_override_deps]. + clean_all, override_deps, profile_override_deps, build_more_sources]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -631,3 +632,31 @@ profile_override_deps(Config) -> Config, RebarConfig, ["as", "a", "compile"], {ok, [{dep, "some_dep"},{dep_not_exist, "other_dep"}]} ). + +build_more_sources(Config) -> + AppDir = ?config(apps, Config), + + ASrc = <<"-module(a_src).\n-export([ok/0]).\nok() -> ok.\n">>, + BSrc = <<"-module(b_src).\n-export([ok/0]).\nok() -> ok.\n">>, + CSrc = <<"-module(c_src).\n-export([ok/0]).\nok() -> ok.\n">>, + + ok = filelib:ensure_dir(filename:join([AppDir, "more", "dummy"])), + ok = filelib:ensure_dir(filename:join([AppDir, "ebin", "dummy"])), + ok = file:write_file(filename:join([AppDir, "more", "a_src.erl"]), ASrc), + ok = file:write_file(filename:join([AppDir, "more", "b_src.erl"]), BSrc), + ok = file:write_file(filename:join([AppDir, "more", "c_src.erl"]), CSrc), + + Opts = dict:new(), + + rebar_erlc_compiler:compile(Opts, + filename:join([AppDir, "more"]), + filename:join([AppDir, "ebin"]), + [filename:join([AppDir, "more", "a_src.erl"]), + filename:join([AppDir, "more", "b_src.erl"]), + filename:join([AppDir, "more", "c_src.erl"])]), + + EbinDir = filename:join([AppDir, "ebin"]), + true = filelib:is_file(filename:join([EbinDir, "a_src.beam"])), + true = filelib:is_file(filename:join([EbinDir, "b_src.beam"])), + true = filelib:is_file(filename:join([EbinDir, "c_src.beam"])). + diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl index 0a86127..95a411f 100644 --- a/test/rebar_ct_SUITE.erl +++ b/test/rebar_ct_SUITE.erl @@ -17,13 +17,15 @@ multi_suite/1, all_suite/1, single_dir_and_single_suite/1, - symlinked_dir_overwritten_fix/1]). + symlinked_dir_overwritten_fix/1, + data_dir_correct/1]). -include_lib("common_test/include/ct.hrl"). all() -> [{group, basic_app}, {group, multi_app}, - {group, dirs_and_suites}]. + {group, dirs_and_suites}, + {group, data_dirs}]. groups() -> [{basic_app, [], [basic_app_default_dirs, basic_app_default_beams]}, @@ -38,7 +40,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs, multi_suite, all_suite, single_dir_and_single_suite, - symlinked_dir_overwritten_fix]}]. + symlinked_dir_overwritten_fix]}, + {data_dirs, [], [data_dir_correct]}]. init_per_group(basic_app, Config) -> C = rebar_test_utils:init_rebar_state(Config, "ct_"), @@ -139,7 +142,8 @@ init_per_group(dirs_and_suites, Config) -> ok = filelib:ensure_dir(Suite3), ok = file:write_file(Suite3, test_suite("extras")), - [{appnames, [Name1, Name2]}|C]. + [{appnames, [Name1, Name2]}|C]; +init_per_group(_, Config) -> Config. end_per_group(_Group, _Config) -> ok. @@ -544,7 +548,14 @@ symlinked_dir_overwritten_fix(Config) -> {ok, _} = rebar_test_utils:run_and_check(Config, [], ["as", "test", "compile"], return). +%% this test probably only fails when this suite is run via rebar3 with the --cover flag +data_dir_correct(Config) -> + DataDir = ?config(data_dir, Config), + Parts = filename:split(DataDir), + ["rebar_ct_SUITE_data","test","rebar","lib","test","_build"|_] = lists:reverse(Parts). + +%% helper for generating test data test_suite(Name) -> io_lib:format("-module(~ts_SUITE).\n" "-compile(export_all).\n" diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index fd86226..fcc46c3 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -3,7 +3,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [sub_app_deps, newly_added_dep, http_proxy_settings, https_proxy_settings, {group, git}, {group, pkg}]. +all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, {group, git}, {group, pkg}]. groups() -> [{all, [], [flat, pick_highest_left, pick_highest_right, @@ -29,6 +29,8 @@ init_per_group(_, Config) -> end_per_group(_, Config) -> Config. +init_per_testcase(newly_added_after_empty_lock, Config) -> + rebar_test_utils:init_rebar_state(Config); init_per_testcase(newly_added_dep, Config) -> rebar_test_utils:init_rebar_state(Config); init_per_testcase(sub_app_deps, Config) -> @@ -252,6 +254,36 @@ newly_added_dep(Config) -> Config, RebarConfig3, ["compile"], {ok, [{app, Name}, {dep, "a"}, {dep, "b", "1.0.0"}, {dep, "c", "1.0.0"}]}). +newly_added_after_empty_lock(Config) -> + AppDir = ?config(apps, Config), + Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]), + {SrcDeps, _} = rebar_test_utils:flat_deps(Deps), + mock_git_resource:mock([{deps, SrcDeps}]), + + Name = rebar_test_utils:create_random_name("app_"), + Vsn = rebar_test_utils:create_random_vsn(), + + SubAppsDir = filename:join([AppDir, "apps", Name]), + rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]), + + TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [])), + {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])), + rebar_test_utils:run_and_check( + Config, RebarConfig, ["compile"], + {ok, []}), + + %% Add a and c to top level + TopDeps2 = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}])), + {ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])), + LockFile = filename:join(AppDir, "rebar.lock"), + RebarConfig3 = rebar_config:merge_locks(RebarConfig2, + rebar_config:consult_lock_file(LockFile)), + + %% a should now be installed and c should not change + rebar_test_utils:run_and_check( + Config, RebarConfig3, ["compile"], + {ok, [{app, Name}, {dep, "a", "1.0.0"}]}). + http_proxy_settings(_Config) -> %% Load config diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 6fbc081..a9e44db 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -5,6 +5,7 @@ -export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]). -export([src_dirs/1, extra_src_dirs/1, all_src_dirs/1]). -export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]). +-export([retarget_path/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -13,16 +14,22 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs, src_dirs, extra_src_dirs, all_src_dirs, - profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs]. + profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs, + retarget_path]. init_per_testcase(_, Config) -> C = rebar_test_utils:init_rebar_state(Config), AppDir = ?config(apps, C), - Name = rebar_test_utils:create_random_name("app1_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), - C. + Name1 = rebar_test_utils:create_random_name("app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]), + + Name2 = rebar_test_utils:create_random_name("app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]), + + [{app_one, Name1}, {app_two, Name2}] ++ C. end_per_testcase(_, _Config) -> ok. @@ -97,3 +104,24 @@ profile_all_src_dirs(Config) -> R = lists:sort(["foo", "bar", "baz", "qux"]), R = lists:sort(rebar_dir:all_src_dirs(rebar_state:opts(State))). + +retarget_path(Config) -> + {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), + + BaseDir = rebar_dir:base_dir(State), + + Name1 = ?config(app_one, Config), + Name2 = ?config(app_two, Config), + + ?assertEqual(filename:join([BaseDir, "lib", Name1, "test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name1, "test"]))), + ?assertEqual(filename:join([BaseDir, "lib", Name2, "test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name2, "test"]))), + ?assertEqual(filename:join([BaseDir, "lib", Name1, "more_test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name1, "more_test"]))), + ?assertEqual(filename:join([BaseDir, "test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "test"]))), + ?assertEqual(filename:join([BaseDir, "some_other_dir"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "some_other_dir"]))), + ?assertEqual("/somewhere/outside/the/project", + rebar_dir:retarget_path(State, "/somewhere/outside/the/project")).
\ No newline at end of file diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index d2dac1d..903bd96 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -1,464 +1,472 @@ -module(rebar_eunit_SUITE). --export([suite/0, - init_per_suite/1, - end_per_suite/1, - init_per_testcase/2, - all/0]). --export([test_basic_app/1, - test_multi_app/1, - test_profile/1, - test_basic_exports/1, - test_multi_exports/1, - test_basic_defines/1, - test_multi_defines/1, - test_single_app_flag/1, - test_multiple_app_flag/1, - test_nonexistent_app_flag/1, - test_single_suite_flag/1, - test_suite_in_app_flag/1, - test_suite_in_wrong_app_flag/1, - test_nonexistent_suite_flag/1, - test_single_file_flag/1, - test_multiple_file_flag/1, - test_nonexistent_file_flag/1]). +-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([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]). +-export([single_suite_arg/1, multi_suite_arg/1, missing_suite_arg/1]). +-export([single_file_arg/1, multi_file_arg/1, missing_file_arg/1]). +-export([single_dir_arg/1, multi_dir_arg/1, missing_dir_arg/1]). +-export([multiple_arg_composition/1, multiple_arg_errors/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("kernel/include/file.hrl"). -suite() -> - []. - +all() -> + [{group, basic_app}, {group, multi_app}, {group, cmd_line_args}]. + +groups() -> + [{basic_app, [sequence], [basic_app_compiles, {group, basic_app_results}]}, + {basic_app_results, [], [basic_app_files, basic_app_exports, basic_app_testset]}, + {multi_app, [sequence], [multi_app_compiles, {group, multi_app_results}]}, + {multi_app_results, [], [multi_app_files, multi_app_exports, multi_app_testset]}, + {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, + single_suite_arg, multi_suite_arg, missing_suite_arg, + single_file_arg, multi_file_arg, missing_file_arg, + single_dir_arg, multi_dir_arg, missing_dir_arg, + multiple_arg_composition, multiple_arg_errors]}]. + +%% this just unzips the example apps used by tests to the priv dir for later use init_per_suite(Config) -> + PrivDir = ?config(priv_dir, Config), + DataDir = ?config(data_dir, Config), + {ok, Cwd} = file:get_cwd(), + file:set_cwd(PrivDir), + ok = ec_file:copy(filename:join([DataDir, "basic_app.zip"]), filename:join([PrivDir, "basic_app.zip"])), + {ok, _} = zip:extract(filename:join([PrivDir, "basic_app.zip"])), + ok = ec_file:copy(filename:join([DataDir, "multi_app.zip"]), filename:join([PrivDir, "multi_app.zip"])), + {ok, _} = zip:extract(filename:join([PrivDir, "multi_app.zip"])), + file:set_cwd(Cwd), Config. -end_per_suite(_Config) -> - ok. +init_per_group(basic_app, Config) -> + GroupState = rebar_test_utils:init_rebar_state(Config, "basic_app_"), -init_per_testcase(_, Config) -> - rebar_test_utils:init_rebar_state(Config, "eunit_"). + AppDir = ?config(apps, GroupState), + PrivDir = ?config(priv_dir, GroupState), -all() -> - [test_basic_app, test_multi_app, test_profile, - test_basic_exports, test_multi_exports, - test_basic_defines, test_multi_defines, - test_single_app_flag, test_multiple_app_flag, test_nonexistent_app_flag, - test_single_suite_flag, test_suite_in_app_flag, - test_suite_in_wrong_app_flag, test_nonexistent_suite_flag, - test_single_file_flag, test_multiple_file_flag, test_nonexistent_file_flag]. - -test_basic_app(Config) -> + AppDirs = ["src", "include", "test"], + + lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "basic_app", F]), + filename:join([AppDir, F]), + [recursive]) end, AppDirs), + + RebarConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, [{d, eunit_compile_define}]}], + + {ok, State} = rebar_test_utils:run_and_check(GroupState, RebarConfig, ["as", "test", "lock"], return), + + [{result, State}|GroupState]; +init_per_group(multi_app, Config) -> + GroupState = rebar_test_utils:init_rebar_state(Config, "multi_app_"), + + AppDir = ?config(apps, GroupState), + PrivDir = ?config(priv_dir, GroupState), + + AppDirs = ["apps", "test"], + + lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "multi_app", F]), + filename:join([AppDir, F]), + [recursive]) end, AppDirs), + + RebarConfig = [{erl_opts, [{d, config_define}]}, {eunit_compile_opts, [{d, eunit_compile_define}]}], + + {ok, State} = rebar_test_utils:run_and_check(GroupState, RebarConfig, ["as", "test", "lock"], return), + + [{result, State}|GroupState]; +init_per_group(cmd_line_args, Config) -> + GroupState = rebar_test_utils:init_rebar_state(Config, "cmd_line_args_"), + + AppDir = ?config(apps, GroupState), + PrivDir = ?config(priv_dir, GroupState), + + AppDirs = ["apps", "test"], + + lists:foreach(fun(F) -> ec_file:copy(filename:join([PrivDir, "multi_app", F]), + filename:join([AppDir, F]), + [recursive]) end, AppDirs), + + RebarConfig = [{erl_opts, [{d, config_define}]}, + {eunit_compile_opts, [{d, eunit_compile_define}]}, + %% test set not supported by cmd line args + {eunit_tests, [{test, multi_app_bar, sanity_test}, + {test, multi_app_baz, sanity_test}]}, + {eunit_opts, [verbose]}, + {eunit_first_files, [filename:join(["apps", "multi_app_bar", "test", "multi_app_bar_tests_helper.erl"]), + filename:join(["apps", "multi_app_baz", "test", "multi_app_baz_tests_helper.erl"])]}], + + {ok, State} = rebar_test_utils:run_and_check(GroupState, RebarConfig, ["eunit"], return), + + [{result, State}|GroupState]; +init_per_group(_, Config) -> Config. + +end_per_group(_, Config) -> Config. + + + +%% === tests for a single application at the root of a project === + +%% check that project compiles properly +basic_app_compiles(Config) -> AppDir = ?config(apps, Config), + State = ?config(result, Config), - Name = rebar_test_utils:create_random_name("basic_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), + {ok, _} = rebar_prv_eunit:do(State), - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}). + rebar_test_utils:check_results(AppDir, [{app, "basic_app"}], "*"). -test_multi_app(Config) -> +%% check that all files expected to be present are present +basic_app_files(Config) -> AppDir = ?config(apps, Config), - Name1 = rebar_test_utils:create_random_name("multi_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit"], - {ok, [{app, Name1}, {app, Name2}]}). - -test_profile(Config) -> + lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "basic_app", "ebin", F])) end, + ["basic_app.app", "basic_app.beam", "basic_app_tests.beam", "basic_app_tests_helper.beam"]). + +%% check that the correct tests are exported from modules for project +%% note that this implies `TEST` is set correctly +basic_app_exports(_Config) -> + Tests = fun(Mod) -> + begin + Path = code:which(Mod), + {ok, {Mod, [{exports, Ex}]}} = beam_lib:chunks(Path, [exports]), + true = lists:member({sanity_test, 0}, Ex) + end + end, + Helpers = fun(Mod) -> + begin + Path = code:which(Mod), + {ok, {Mod, [{exports, Ex}]}} = beam_lib:chunks(Path, [exports]), + true = lists:member({help, 0}, Ex) + end + end, + lists:foreach(Tests, [basic_app, basic_app_tests]), + lists:foreach(Helpers, [basic_app_tests_helper]). + +%% check that the correct tests are schedule to run for project +basic_app_testset(Config) -> + Result = ?config(result, Config), + + {ok, [{application, basic_app}]} = rebar_prv_eunit:prepare_tests(Result). + + + +%% === tests for multiple applications in the `apps' directory of a project === + +%% check that project compiles properly +multi_app_compiles(Config) -> AppDir = ?config(apps, Config), + State = ?config(result, Config), - Name = rebar_test_utils:create_random_name("profile_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + {ok, _} = rebar_prv_eunit:do(State), - RebarConfig = [{erl_opts, [{d, some_define}]}, - {profiles, [{test, [{erl_opts, [debug_info]}]}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["as", "test", "eunit"], - {ok, [{app, Name}]}). + rebar_test_utils:check_results(AppDir, [{app, "multi_app_bar"}, {app, "multi_app_baz"}], "*"). -test_basic_exports(Config) -> +%% check that all files expected to be present are present +multi_app_files(Config) -> AppDir = ?config(apps, Config), - Name = rebar_test_utils:create_random_name("basic_exports_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit"], - {ok, [{app, Name}]}), - - App = list_to_atom("not_a_real_src_" ++ Name), - Suite = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), - AppExports = App:module_info(exports), - SuiteExports = Suite:module_info(exports), - AppExpect = [{some_test_, 0}], - SuiteExpect = [{some_test_, 0}, {define_test_, 0}], - lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports) end, AppExpect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports) end, SuiteExpect). - -test_multi_exports(Config) -> + lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", F])) end, + ["multi_app_bar.app", "multi_app_bar.beam", "multi_app_bar_tests.beam", "multi_app_bar_tests_helper.beam"]), + lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin", F])) end, + ["multi_app_baz.app", "multi_app_baz.beam", "multi_app_baz_tests.beam", "multi_app_baz_tests_helper.beam"]), + lists:foreach(fun(F) -> true = ec_file:exists(filename:join([AppDir, "_build", "test", "test", F])) end, + ["multi_app_tests.beam", "multi_app_tests_helper.beam"]). + +%% check that the correct tests are exported from modules for project +%% note that this implies `TEST` is set correctly +multi_app_exports(_Config) -> + Tests = fun(Mod) -> + begin + Ex = Mod:module_info(exports), + true = lists:member({sanity_test, 0}, Ex) + end + end, + Helpers = fun(Mod) -> + begin + Ex = Mod:module_info(exports), + true = lists:member({help, 0}, Ex) + end + end, + lists:foreach(Tests, [multi_app_bar, multi_app_bar_tests, + multi_app_baz, multi_app_baz_tests, + multi_app_tests]), + lists:foreach(Helpers, [multi_app_bar_tests_helper, multi_app_baz_tests_helper, multi_app_tests_helper]). + +%% check that the correct tests are schedule to run for project +multi_app_testset(Config) -> AppDir = ?config(apps, Config), + Result = ?config(result, Config), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit"], - {ok, [{app, Name1}, {app, Name2}]}), - - App1 = list_to_atom("not_a_real_src_" ++ Name1), - Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), - AppExports1 = App1:module_info(exports), - SuiteExports1 = Suite1:module_info(exports), - App2 = list_to_atom("not_a_real_src_" ++ Name2), - Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), - AppExports2 = App2:module_info(exports), - SuiteExports2 = Suite2:module_info(exports), - AppExpect = [{some_test_, 0}], - SuiteExpect = [{some_test_, 0}, {define_test_, 0}], - lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports1) end, AppExpect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports1) end, SuiteExpect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports2) end, AppExpect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports2) end, SuiteExpect). - -test_basic_defines(Config) -> - AppDir = ?config(apps, Config), + Set = {ok, [{application, multi_app_bar}, {application, multi_app_baz}, {dir, filename:join([AppDir, "_build", "test", "test"])}]}, + Set = rebar_prv_eunit:prepare_tests(Result). - Name = rebar_test_utils:create_random_name("basic_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}), - App = list_to_atom("not_a_real_src_" ++ Name), - Suite = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), - AppOpts = proplists:get_value(options, App:module_info(compile), []), - SuiteOpts = proplists:get_value(options, Suite:module_info(compile), []), - Expect = [{d, some_define}], - lists:foreach(fun(E) -> true = lists:member(E, AppOpts) end, Expect), - lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts) end, Expect). +%% === tests for command line arguments === -test_multi_defines(Config) -> - AppDir = ?config(apps, Config), +%% no explicit test for cmd line args taking precedence over the rebar.config since +%% almost every single test implies it - Name1 = rebar_test_utils:create_random_name("multi_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit"], - {ok, [{app, Name1}, {app, Name2}]}), - - App1 = list_to_atom("not_a_real_src_" ++ Name1), - Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), - AppOpts1 = proplists:get_value(options, App1:module_info(compile), []), - SuiteOpts1 = proplists:get_value(options, Suite1:module_info(compile), []), - App2 = list_to_atom("not_a_real_src_" ++ Name2), - Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), - AppOpts2 = proplists:get_value(options, App2:module_info(compile), []), - SuiteOpts2 = proplists:get_value(options, Suite2:module_info(compile), []), - Expect = [{d, some_define}], - lists:foreach(fun(E) -> true = lists:member(E, AppOpts1) end, Expect), - lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts1) end, Expect), - lists:foreach(fun(E) -> true = lists:member(E, AppOpts2) end, Expect), - lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts2) end, Expect). - -test_single_app_flag(Config) -> - AppDir = ?config(apps, Config), +%% check tests in the rebar.config are run if no cmd line opts are specified +eunit_tests(Config) -> + State = ?config(result, Config), + + Expect = {ok, [{test, multi_app_bar, sanity_test}, {test, multi_app_baz, sanity_test}]}, + Expect = rebar_prv_eunit:prepare_tests(State). + +%% check eunit_opts from the rebar.config are respected +eunit_opts(Config) -> + State = ?config(result, Config), + + Apps = rebar_state:project_apps(State), + lists:foreach(fun(App) -> [verbose] = rebar_app_info:get(App, eunit_opts) end, + Apps). + +%% check eunit_first_files from the rebar.config are respected +eunit_first_files(Config) -> + State = ?config(result, Config), + + FirstFiles = [filename:join(["apps", "multi_app_bar", "test", "multi_app_bar_tests_helper.erl"]), + filename:join(["apps", "multi_app_baz", "test", "multi_app_baz_tests_helper.erl"])], + + Apps = rebar_state:project_apps(State), + lists:foreach(fun(App) -> FirstFiles = rebar_app_info:get(App, eunit_first_files) end, + Apps). + +%% check that the --application cmd line opt generates the correct test set +single_application_arg(Config) -> + S = ?config(result, Config), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=multi_app_bar"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{application, multi_app_bar}]} = rebar_prv_eunit:prepare_tests(State). + +multi_application_arg(Config) -> + S = ?config(result, Config), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=multi_app_bar,multi_app_baz"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{application, multi_app_bar}, {application, multi_app_baz}]} = rebar_prv_eunit:prepare_tests(State). + +%% check that an invalid --application cmd line opt generates an error +missing_application_arg(Config) -> + S = ?config(result, Config), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=missing_app"]), + State = rebar_state:command_parsed_args(S, Args), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - BareSuite = io_lib:format("-module(all_tests).\n" - "-compile(export_all).\n" - "-include_lib(\"eunit/include/eunit.hrl\").\n" - "some_test_() -> ?_assert(true).\n" - "define_test_() -> ?_assertEqual(true, ?some_define).\n", []), - FileName = filename:join([AppDir, "test", "all_tests.erl"]), - ok = filelib:ensure_dir(FileName), - ok = ec_file:write(FileName, BareSuite), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--app=" ++ Name1], - {ok, [{app, Name1}, {app, Name2}]}), - - Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), - {module, Suite1} = code:ensure_loaded(Suite1), - Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), - {error, nofile} = code:ensure_loaded(Suite2), - {error, nofile} = code:ensure_loaded(all_tests). - -test_multiple_app_flag(Config) -> + Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Application `missing_app' not found in project."]}}}, + Error = rebar_prv_eunit:prepare_tests(State). + +%% check that the --module cmd line opt generates the correct test set +single_module_arg(Config) -> AppDir = ?config(apps, Config), + S = ?config(result, Config), + + %% necessary to fix paths + Path = code:get_path(), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--module=multi_app_bar"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{module, multi_app_bar}]} = rebar_prv_eunit:prepare_tests(State), + + %% restore path + code:set_path(Path). - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - BareSuite = io_lib:format("-module(all_tests).\n" - "-compile(export_all).\n" - "-include_lib(\"eunit/include/eunit.hrl\").\n" - "some_test_() -> ?_assert(true).\n" - "define_test_() -> ?_assertEqual(true, ?some_define).\n", []), - FileName = filename:join([AppDir, "test", "all_tests.erl"]), - ok = filelib:ensure_dir(FileName), - ok = ec_file:write(FileName, BareSuite), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--app=" ++ Name1 ++ "," ++ Name2], - {ok, [{app, Name1}, {app, Name2}]}), - - Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), - {module, Suite1} = code:ensure_loaded(Suite1), - Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), - {module, Suite2} = code:ensure_loaded(Suite2), - {error, nofile} = code:ensure_loaded(all_tests). - -test_nonexistent_app_flag(Config) -> +multi_module_arg(Config) -> AppDir = ?config(apps, Config), + S = ?config(result, Config), + + %% necessary to fix paths + Path = code:get_path(), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin"])]), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--module=multi_app_bar,multi_app_baz"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{module, multi_app_bar}, {module, multi_app_baz}]} = rebar_prv_eunit:prepare_tests(State), + + %% restore path + code:set_path(Path). + +%% check that an invalid --module cmd line opt generates an error +missing_module_arg(Config) -> + S = ?config(result, Config), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - {error, {_, Error}} = rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--app=not_a_real_app"], - return), - - Error = {error_running_tests, "Application `not_a_real_app' not found in project."}. - -test_single_suite_flag(Config) -> + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--module=missing_app"]), + State = rebar_state:command_parsed_args(S, Args), + + Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Module `missing_app' not found in project."]}}}, + Error = rebar_prv_eunit:prepare_tests(State). + +%% check that the --suite cmd line opt generates the correct test set +single_suite_arg(Config) -> AppDir = ?config(apps, Config), + S = ?config(result, Config), + + %% necessary to fix paths + Path = code:get_path(), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--suite=multi_app_bar"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{module, multi_app_bar}]} = rebar_prv_eunit:prepare_tests(State), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--suite=not_a_real_src_" ++ Name1], - {ok, [{app, Name1}, {app, Name2}]}), - - Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), - {module, Suite1} = code:ensure_loaded(Suite1). - -test_suite_in_app_flag(Config) -> + %% restore path + code:set_path(Path). + +multi_suite_arg(Config) -> AppDir = ?config(apps, Config), + S = ?config(result, Config), + + %% necessary to fix paths + Path = code:get_path(), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin"])]), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--suite=multi_app_bar,multi_app_baz"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{module, multi_app_bar}, {module, multi_app_baz}]} = rebar_prv_eunit:prepare_tests(State), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", - "--app=" ++ Name1, - "--suite=not_a_real_src_" ++ Name1], - {ok, [{app, Name1}, {app, Name2}]}), - - Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), - {module, Suite1} = code:ensure_loaded(Suite1), - Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), - {error, nofile} = code:ensure_loaded(Suite2). - -test_suite_in_wrong_app_flag(Config) -> + %% restore path + code:set_path(Path). + +%% check that an invalid --suite cmd line opt generates an error +missing_suite_arg(Config) -> + S = ?config(result, Config), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--suite=missing_app"]), + State = rebar_state:command_parsed_args(S, Args), + + Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Module `missing_app' not found in project."]}}}, + Error = rebar_prv_eunit:prepare_tests(State). + +%% check that the --file cmd line opt generates the correct test set +single_file_arg(Config) -> + S = ?config(result, Config), AppDir = ?config(apps, Config), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - {error, {_, Error}} = rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", - "--app=" ++ Name1, - "--suite=not_a_real_src_" ++ Name2], - return), - - Error = {error_running_tests, "Module `not_a_real_src_" ++ - Name2 ++ - "' not found in applications."}. - -test_nonexistent_suite_flag(Config) -> + Path = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", "multi_app_bar.beam"]), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--file=" ++ Path]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{file, Path}]} = rebar_prv_eunit:prepare_tests(State). + +multi_file_arg(Config) -> + S = ?config(result, Config), AppDir = ?config(apps, Config), - Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), - Vsn1 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name1]), - Name1, - Vsn1, - [kernel, stdlib]), - Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), - Vsn2 = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(filename:join([AppDir,"apps",Name2]), - Name2, - Vsn2, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - {error, {_, Error}} = rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--suite=not_a_real_module"], - return), - - Error = {error_running_tests, "Module `not_a_real_module' not found in applications."}. - -test_single_file_flag(Config) -> + BarPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", "multi_app_bar.beam"]), + BazPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin", "multi_app_baz.beam"]), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--file=" ++ BarPath ++ "," ++ BazPath]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{file, BarPath}, {file, BazPath}]} = rebar_prv_eunit:prepare_tests(State). + +%% check that an invalid --file cmd line opt generates an error +missing_file_arg(Config) -> + S = ?config(result, Config), AppDir = ?config(apps, Config), - Name = rebar_test_utils:create_random_name("single_file_flag_app_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), + Path = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin", "missing_app.beam"]), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--file=" ++ Path]), + State = rebar_state:command_parsed_args(S, Args), + + Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["File `" ++ Path ++"' not found."]}}}, + Error = rebar_prv_eunit:prepare_tests(State). - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--file=not_a_real_src_" ++ Name ++ "_tests.beam"], - {ok, [{app, Name}]}), +%% check that the --dir cmd line opt generates the correct test set +single_dir_arg(Config) -> + S = ?config(result, Config), + AppDir = ?config(apps, Config), + + Path = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"]), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--dir=" ++ Path]), + State = rebar_state:command_parsed_args(S, Args), - File = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), - {module, File} = code:ensure_loaded(File). + {ok, [{dir, Path}]} = rebar_prv_eunit:prepare_tests(State). -test_multiple_file_flag(Config) -> +multi_dir_arg(Config) -> + S = ?config(result, Config), AppDir = ?config(apps, Config), - Name = rebar_test_utils:create_random_name("multiple_file_flag_app_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), + BarPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"]), + BazPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_baz", "ebin"]), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--dir=" ++ BarPath ++ "," ++ BazPath]), + State = rebar_state:command_parsed_args(S, Args), - RebarConfig = [{erl_opts, [{d, some_define}]}], - rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--file=not_a_real_src_" ++ Name ++ "_tests.beam,not_a_real_src_" ++ Name ++ ".beam"], - {ok, [{app, Name}]}), + {ok, [{dir, BarPath}, {dir, BazPath}]} = rebar_prv_eunit:prepare_tests(State). - File1 = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), - {module, File1} = code:ensure_loaded(File1), +%% check that an invalid --dir cmd line opt generates an error +missing_dir_arg(Config) -> + S = ?config(result, Config), + AppDir = ?config(apps, Config), - File2 = list_to_atom("not_a_real_src_" ++ Name), - {module, File2} = code:ensure_loaded(File2). + Path = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin"]), + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--dir=" ++ Path]), + State = rebar_state:command_parsed_args(S, Args), -test_nonexistent_file_flag(Config) -> + Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Directory `" ++ Path ++"' not found."]}}}, + Error = rebar_prv_eunit:prepare_tests(State). + +%% check that multiple args are composed +multiple_arg_composition(Config) -> + S = ?config(result, Config), AppDir = ?config(apps, Config), - Name = rebar_test_utils:create_random_name("nonexistent_file_flag_app_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_eunit_app(AppDir, - Name, - Vsn, - [kernel, stdlib]), - - RebarConfig = [{erl_opts, [{d, some_define}]}], - {error, {rebar_prv_eunit, _Error}} = rebar_test_utils:run_and_check(Config, - RebarConfig, - ["eunit", "--file=" ++ filename:join(["some_path", "not_a_real_file.erl"])], - return). + %% necessary to fix paths + Path = code:get_path(), + code:add_paths([filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"])]), + FilePath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin", "multi_app_bar.beam"]), + DirPath = filename:join([AppDir, "_build", "test", "lib", "multi_app_bar", "ebin"]), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=multi_app_bar", + "--module=multi_app_bar", + "--suite=multi_app_bar", + "--file=" ++ FilePath, + "--dir=" ++ DirPath]), + State = rebar_state:command_parsed_args(S, Args), + + Expect = [{application, multi_app_bar}, + {dir, DirPath}, + {file, FilePath}, + {module, multi_app_bar}, + {module, multi_app_bar}], + + {ok, Expect} = rebar_prv_eunit:prepare_tests(State), + + %% restore path + code:set_path(Path). + +%% check that multiple errors are reported +multiple_arg_errors(Config) -> + S = ?config(result, Config), + AppDir = ?config(apps, Config), + + FilePath = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin", "missing_app.beam"]), + DirPath = filename:join([AppDir, "_build", "test", "lib", "missing_app", "ebin"]), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--application=missing_app", + "--module=missing_app", + "--suite=missing_app", + "--file=" ++ FilePath, + "--dir=" ++ DirPath]), + State = rebar_state:command_parsed_args(S, Args), + + Expect = ["Application `missing_app' not found in project.", + "Directory `" ++ DirPath ++ "' not found.", + "File `" ++ FilePath ++ "' not found.", + "Module `missing_app' not found in project.", + "Module `missing_app' not found in project."], + + {error, {rebar_prv_eunit, {eunit_test_errors, Expect}}} = rebar_prv_eunit:prepare_tests(State). diff --git a/test/rebar_eunit_SUITE_data/basic_app.zip b/test/rebar_eunit_SUITE_data/basic_app.zip Binary files differnew file mode 100644 index 0000000..0eaa0af --- /dev/null +++ b/test/rebar_eunit_SUITE_data/basic_app.zip diff --git a/test/rebar_eunit_SUITE_data/deflate b/test/rebar_eunit_SUITE_data/deflate new file mode 100755 index 0000000..368228f --- /dev/null +++ b/test/rebar_eunit_SUITE_data/deflate @@ -0,0 +1,15 @@ +#!/usr/bin/env escript + +main(["basic_app"]) -> + case filelib:is_dir("basic_app") of + true -> zip:create("basic_app.zip", ["basic_app"]), halt(0); + false -> io:format("unable to locate basic_app directory~n", []), halt(1) + end; +main(["multi_app"]) -> + case filelib:is_dir("multi_app") of + true -> zip:create("multi_app.zip", ["multi_app"]), halt(0); + false -> io:format("unable to locate multi_app directory~n", []), halt(1) + end, + halt(0); +main(_) -> + io:format("usage: deflate basic_app | multi_app~n", []), halt(1).
\ No newline at end of file diff --git a/test/rebar_eunit_SUITE_data/inflate b/test/rebar_eunit_SUITE_data/inflate new file mode 100755 index 0000000..d402f80 --- /dev/null +++ b/test/rebar_eunit_SUITE_data/inflate @@ -0,0 +1,15 @@ +#!/usr/bin/env escript + +main(["basic_app"]) -> + case filelib:is_file("basic_app.zip") of + true -> zip:unzip("basic_app.zip"), halt(0); + false -> io:format("unable to locate basic_app.zip~n", []), halt(1) + end; +main(["multi_app"]) -> + case filelib:is_file("multi_app.zip") of + true -> zip:unzip("multi_app.zip"), halt(0); + false -> io:format("unable to locate multi_app.zip~n", []), halt(1) + end, + halt(0); +main(_) -> + io:format("usage: inflate basic_app | multi_app~n", []), halt(1).
\ No newline at end of file diff --git a/test/rebar_eunit_SUITE_data/multi_app.zip b/test/rebar_eunit_SUITE_data/multi_app.zip Binary files differnew file mode 100644 index 0000000..36bf9a6 --- /dev/null +++ b/test/rebar_eunit_SUITE_data/multi_app.zip diff --git a/test/rebar_file_utils_SUITE.erl b/test/rebar_file_utils_SUITE.erl index 03a2d54..4324a5f 100644 --- a/test/rebar_file_utils_SUITE.erl +++ b/test/rebar_file_utils_SUITE.erl @@ -10,7 +10,9 @@ multi_tmpdir/1, reset_nonexistent_dir/1, reset_empty_dir/1, - reset_dir/1]). + reset_dir/1, + path_from_ancestor/1, + canonical_path/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -19,7 +21,8 @@ all() -> [{group, tmpdir}, - {group, reset_dir}]. + {group, reset_dir}, + path_from_ancestor, canonical_path]. groups() -> [{tmpdir, [], [raw_tmpdir, empty_tmpdir, simple_tmpdir, multi_tmpdir]}, @@ -84,3 +87,20 @@ reset_dir(Config) -> ok = rebar_file_utils:reset_dir(TmpDir), ?assert(filelib:is_dir(TmpDir)), {ok, []} = file:list_dir(TmpDir). + +path_from_ancestor(_Config) -> + ?assertEqual({ok, "foo/bar/baz"}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/")), + ?assertEqual({ok, "bar/baz"}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/foo")), + ?assertEqual({ok, "bar"}, rebar_file_utils:path_from_ancestor("foo/bar", "foo")), + ?assertEqual({ok, "bar"}, rebar_file_utils:path_from_ancestor("foo/bar/", "foo/")), + ?assertEqual({error, badparent}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/qux")), + ?assertEqual({error, badparent}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/foo/bar/baz/qux")). + +canonical_path(_Config) -> + ?assertEqual(filename:nativename("/"), rebar_file_utils:canonical_path("/")), + ?assertEqual(filename:nativename("/"), rebar_file_utils:canonical_path("/../../..")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/bar/..")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/../foo")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/.")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/./.")), + ?assertEqual("/foo/bar", rebar_file_utils:canonical_path("/foo/./bar")).
\ No newline at end of file diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index d4c10c5..a31a4c9 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -375,8 +375,8 @@ test_profile_applied_at_completion(Config) -> ["eunit"], return), - Opts = rebar_state:opts(State), - ErlOpts = dict:fetch(erl_opts, Opts), + [App] = rebar_state:project_apps(State), + ErlOpts = rebar_app_info:get(App, erl_opts), true = lists:member({d, 'TEST'}, ErlOpts). test_profile_applied_before_compile(Config) -> diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 8d1d408..ca5e91a 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -1,7 +1,7 @@ -module(rebar_test_utils). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). --export([init_rebar_state/1, init_rebar_state/2, run_and_check/4]). +-export([init_rebar_state/1, init_rebar_state/2, run_and_check/4, check_results/3]). -export([expand_deps/2, flat_deps/1, top_level_deps/1]). -export([create_app/4, create_eunit_app/4, create_empty_app/4, create_config/2, package_app/3]). diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl index 54f16da..cfe1d8a 100644 --- a/test/rebar_upgrade_SUITE.erl +++ b/test/rebar_upgrade_SUITE.erl @@ -9,7 +9,7 @@ groups() -> [{all, [], [top_a, top_b, top_c, top_d1, top_d2, top_e, pair_a, pair_b, pair_ab, pair_c, pair_all, triplet_a, triplet_b, triplet_c, - tree_a, tree_b, tree_c, tree_c2, tree_ac, tree_all, + tree_a, tree_b, tree_c, tree_c2, tree_cj, tree_ac, tree_all, delete_d, promote, stable_lock, fwd_lock, compile_upgrade_parity]}, {git, [], [{group, all}]}, @@ -327,6 +327,25 @@ upgrades(tree_c2) -> {"C", [{"A","1"}, "D", "J", "E", {"B","1"}, "F", "G", {"C","1"}, "H", {"I", "2"}, "K"]}}; +upgrades(tree_cj) -> + {[{"A", "1", [{"D",[{"J", "1",[]}]}, + {"E",[{"I","1",[]}]}]}, + {"B", "1", [{"F",[]}, + {"G",[]}]}, + {"C", "1", [{"H",[]}, + {"I","1",[]}]} + ], + [{"A", "1", [{"D",[{"J", "2", []}]}, + {"E",[{"I","1",[]}]}]}, + {"B", "1", [{"F",[]}, + {"G",[]}]}, + {"C", "1", [{"H",[]}, + {"I","1",[]}]} + ], + ["C","J"], + {"C", [{"A","1"}, "D", {"J", "1"}, "E", {"I","1"}, + {"B","1"}, "F", "G", + {"C","1"}, "H"]}}; upgrades(tree_ac) -> {[{"A", "1", [{"D",[{"J",[]}]}, {"E",[{"I","1",[]}]}]}, @@ -481,6 +500,7 @@ tree_a(Config) -> run(Config). tree_b(Config) -> run(Config). tree_c(Config) -> run(Config). tree_c2(Config) -> run(Config). +tree_cj(Config) -> run(Config). tree_ac(Config) -> run(Config). tree_all(Config) -> run(Config). promote(Config) -> run(Config). @@ -561,13 +581,19 @@ run(Config) -> {error, Term} -> {error, Term}; _ -> {ok, Unlocks} end, - apply(?config(mock_update, Config), []), + + meck:new(rebar_prv_upgrade, [passthrough]), + meck:expect(rebar_prv_upgrade, do, fun(S) -> + apply(?config(mock_update, Config), []), + meck:passthrough([S]) + end), NewRebarConf = rebar_test_utils:create_config(?config(apps, Config), [{deps, ?config(next_top_deps, Config)}]), {ok, NewRebarConfig} = file:consult(NewRebarConf), rebar_test_utils:run_and_check( Config, NewRebarConfig, ["upgrade", App], Expectation - ). + ), + meck:unload(rebar_prv_upgrade). novsn_pkg(Config) -> apply(?config(mock, Config), []), |