diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mock_git_resource.erl | 4 | ||||
-rw-r--r-- | test/mock_pkg_resource.erl | 6 | ||||
-rw-r--r-- | test/rebar_as_SUITE.erl | 22 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 127 | ||||
-rw-r--r-- | test/rebar_eunit_SUITE.erl | 379 | ||||
-rw-r--r-- | test/rebar_new_SUITE.erl | 26 | ||||
-rw-r--r-- | test/rebar_opts_parser_SUITE.erl | 54 | ||||
-rw-r--r-- | test/rebar_profiles_SUITE.erl | 19 | ||||
-rw-r--r-- | test/rebar_release_SUITE.erl | 46 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 44 |
10 files changed, 695 insertions, 32 deletions
diff --git a/test/mock_git_resource.erl b/test/mock_git_resource.erl index 6940f54..9c799fd 100644 --- a/test/mock_git_resource.erl +++ b/test/mock_git_resource.erl @@ -55,7 +55,7 @@ mock_lock(_) -> %% should be updated on a per-name basis: `{update, ["App1", "App3"]}'. mock_update(Opts) -> ToUpdate = proplists:get_value(upgrade, Opts, []), - ct:pal("TOUp: ~p", [ToUpdate]), +% ct:pal("TOUp: ~p", [ToUpdate]), meck:expect( ?MOD, needs_update, fun(_Dir, {git, Url, _Ref}) -> @@ -110,7 +110,7 @@ mock_download(Opts) -> AppDeps = proplists:get_value({App,Vsn}, Deps, []), rebar_test_utils:create_app( Dir, App, Vsn, - [element(1,D) || D <- AppDeps] + [kernel, stdlib] ++ [element(1,D) || D <- AppDeps] ), rebar_test_utils:create_config(Dir, [{deps, AppDeps}]), {ok, 'WHATEVER'} diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl index a22d1b0..afb6fb4 100644 --- a/test/mock_pkg_resource.erl +++ b/test/mock_pkg_resource.erl @@ -78,9 +78,9 @@ mock_download(Opts) -> App = binary_to_list(AppBin), filelib:ensure_dir(Dir), AppDeps = proplists:get_value({App,Vsn}, Deps, []), - {ok, AppInfo} = rebar_test_utils:create_empty_app( - Dir, App, Vsn, - [element(1,D) || D <- AppDeps] + {ok, AppInfo} = rebar_test_utils:create_app( + Dir, App, binary_to_list(Vsn), + [kernel, stdlib] ++ [element(1,D) || D <- AppDeps] ), rebar_test_utils:create_config(Dir, [{deps, AppDeps}]), Tarball = filename:join([Dir, App++"-"++binary_to_list(Vsn)++".tar"]), diff --git a/test/rebar_as_SUITE.erl b/test/rebar_as_SUITE.erl index 864d468..1d1112b 100644 --- a/test/rebar_as_SUITE.erl +++ b/test/rebar_as_SUITE.erl @@ -11,7 +11,8 @@ as_multiple_profiles_multiple_tasks/1, as_comma_placement/1, as_comma_then_space/1, - as_dir_name/1]). + as_dir_name/1, + as_with_task_args/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -29,7 +30,7 @@ init_per_testcase(_, Config) -> all() -> [as_basic, as_multiple_profiles, as_multiple_tasks, as_multiple_profiles_multiple_tasks, as_comma_placement, as_comma_then_space, - as_dir_name]. + as_dir_name, as_with_task_args]. as_basic(Config) -> AppDir = ?config(apps, Config), @@ -118,3 +119,20 @@ as_dir_name(Config) -> true = filelib:is_dir(filename:join([AppDir, "_build", "foo+bar+baz"])). + +as_with_task_args(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("as_with_task_args_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + rebar_test_utils:run_and_check(Config, + [], + ["as", "default", "compile"], + {ok, [{app, Name}]}), + + rebar_test_utils:run_and_check(Config, + [], + ["as", "default", "clean", "-a"], + {ok, [{app, Name, invalid}]}). diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 2c5a11f..8564754 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -4,6 +4,7 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, + end_per_testcase/2, all/0, build_basic_app/1, build_release_apps/1, @@ -12,7 +13,9 @@ build_all_srcdirs/1, recompile_when_opts_change/1, dont_recompile_when_opts_dont_change/1, - dont_recompile_yrl_or_xrl/1]). + dont_recompile_yrl_or_xrl/1, + deps_in_path/1, + checkout_priority/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -30,12 +33,15 @@ end_per_suite(_Config) -> init_per_testcase(_, Config) -> rebar_test_utils:init_rebar_state(Config). +end_per_testcase(_, _Config) -> + catch meck:unload(). + all() -> [build_basic_app, build_release_apps, build_checkout_apps, build_checkout_deps, build_all_srcdirs, recompile_when_opts_change, dont_recompile_when_opts_dont_change, - dont_recompile_yrl_or_xrl]. + dont_recompile_yrl_or_xrl, deps_in_path, checkout_priority]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -88,8 +94,11 @@ build_checkout_deps(Config) -> rebar_test_utils:create_app(filename:join([CheckoutsDir,Name2]), Name2, Vsn2, [kernel, stdlib]), rebar_test_utils:create_app(filename:join([DepsDir,Name2]), Name2, Vsn1, [kernel, stdlib]), + Deps = [{list_to_atom(Name2), Vsn2, {git, "", ""}}], + {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, Deps}])), + rebar_test_utils:run_and_check( - Config, [], ["compile"], + Config, RebarConfig, ["compile"], {ok, [{app, Name1}, {checkout, Name2}]} ), ok = application:load(list_to_atom(Name2)), @@ -211,3 +220,115 @@ dont_recompile_yrl_or_xrl(Config) -> ?assert(ModTime == NewModTime). +deps_in_path(Config) -> + AppDir = ?config(apps, Config), + StartPaths = code:get_path(), + + 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]), + + DepName = rebar_test_utils:create_random_name("dep1_"), + PkgName = rebar_test_utils:create_random_name("pkg1_"), + mock_git_resource:mock([]), + mock_pkg_resource:mock([ + {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]} + ]), + + RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [ + {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}, + {list_to_atom(PkgName), Vsn} + ]}]), + {ok, RConf} = file:consult(RConfFile), + %% Make sure apps we look for are not visible + %% Hope not to find src name + ?assertEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, DepName)]]), + %% Hope not to find pkg name in there + ?assertEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, PkgName)]]), + %% Build things + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]} + ), + %% Find src name in there + ?assertNotEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, DepName)]]), + %% find pkg name in there + ?assertNotEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, PkgName)]]), + code:set_path(StartPaths), + %% Make sure apps we look for are not visible again + %% Hope not to find src name + ?assertEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, DepName)]]), + %% Hope not to find pkg name in there + ?assertEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, PkgName)]]), + %% Rebuild + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]} + ), + %% Find src name in there + ?assertNotEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, DepName)]]), + %% find pkg name in there + ?assertNotEqual([], [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, PkgName)]]). + +checkout_priority(Config) -> + AppDir = ?config(apps, Config), + CheckoutsDir = ?config(checkouts, Config), + StartPaths = code:get_path(), + + 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]), + + DepName = rebar_test_utils:create_random_name("dep1_"), + PkgName = rebar_test_utils:create_random_name("pkg1_"), + mock_git_resource:mock([]), + mock_pkg_resource:mock([ + {pkgdeps, [{{iolist_to_binary(PkgName), iolist_to_binary(Vsn)}, []}]} + ]), + + RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [ + {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}, + {list_to_atom(PkgName), Vsn} + ]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, DepName}, {dep, PkgName}]} + ), + + %% Build two checkout apps similar to dependencies to be fetched, + %% but on a different version + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([CheckoutsDir,DepName]), DepName, Vsn2, [kernel, stdlib]), + rebar_test_utils:create_app(filename:join([CheckoutsDir,PkgName]), PkgName, Vsn2, [kernel, stdlib]), + + %% Rebuild and make sure the checkout apps are in path + code:set_path(StartPaths), + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {checkout, DepName}, {checkout, PkgName}]} + ), + + [DepPath] = [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, DepName)]], + [PkgPath] = [Path || Path <- code:get_path(), + {match, _} <- [re:run(Path, PkgName)]], + + {ok, [DepApp]} = file:consult(filename:join([DepPath, DepName ++ ".app"])), + {ok, [PkgApp]} = file:consult(filename:join([PkgPath, PkgName ++ ".app"])), + + {application, _, DepProps} = DepApp, + {application, _, PkgProps} = PkgApp, + + ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)), + ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)). diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index d2d8608..4ec92f2 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -4,8 +4,21 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, - all/0, - test_basic_app/1]). + 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]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -24,14 +37,372 @@ init_per_testcase(_, Config) -> rebar_test_utils:init_rebar_state(Config, "eunit_"). all() -> - [test_basic_app]. + [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_basic_app(Config) -> AppDir = ?config(apps, Config), Name = rebar_test_utils:create_random_name("basic_"), Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + 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}]}). + +test_multi_app(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,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,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) -> + AppDir = ?config(apps, 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]), + + 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}]}). + +test_basic_exports(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) -> + 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,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,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), + + 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(Expect) -> true = lists:member(Expect, AppOpts) end, Expect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts) end, Expect). + +test_multi_defines(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,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,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(Expect) -> true = lists:member(Expect, AppOpts1) end, Expect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts1) end, Expect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts2) end, Expect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts2) end, Expect). + +test_single_app_flag(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,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,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) -> + 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,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,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) -> + 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,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,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) -> + 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,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,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) -> + 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,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,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) -> + 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,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,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) -> + 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,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,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."}. diff --git a/test/rebar_new_SUITE.erl b/test/rebar_new_SUITE.erl index e382ae4..3cee6f2 100644 --- a/test/rebar_new_SUITE.erl +++ b/test/rebar_new_SUITE.erl @@ -6,7 +6,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [app, app_with_fallbacks]. +all() -> [app_git_user, app_hg_user, app_with_fallbacks]. init_per_testcase(Case, Config0) -> @@ -31,7 +31,7 @@ mock_empty_escript_templates() -> meck:new(rebar_utils, [passthrough]), meck:expect(rebar_utils, escript_foldl, fun(_,_,_) -> {ok, []} end). -app(Config) -> +app_git_user(Config) -> meck:expect(rebar_utils, sh, fun("git config --global user.name", _) -> {ok, "gitname"}; ("git config --global user.email", _) -> {ok, "git@email.com"} end), @@ -73,6 +73,28 @@ app_with_fallbacks(Config) -> {filename:join(["src", Name++"_app.erl"]), [Name]} ]). +app_hg_user(Config) -> + meck:expect(rebar_utils, sh, fun("hg showconfig ui.username", _) -> {ok, "hgname <hg@email.com>"}; + (_, _) -> {error, fallback} + end), + + Name = ?config(name, Config), + rebar_test_utils:run_and_check( + Config, [], + ["new", "test_app", Name], + {ok, []} + ), + validate_files( + Config, Name, + [{"LICENSE", ["hgname", "hg@email.com"]}, + {"README.md", [Name]}, + {".gitignore", []}, + {"rebar.config", []}, + {filename:join(["src", Name++".app.src"]), [Name]}, + {filename:join(["src", Name++"_sup.erl"]), [Name]}, + {filename:join(["src", Name++"_app.erl"]), [Name]} + ]). + validate_files(_Config, Name, Checks) -> [begin Path = filename:join([Name, File]), diff --git a/test/rebar_opts_parser_SUITE.erl b/test/rebar_opts_parser_SUITE.erl new file mode 100644 index 0000000..fc738b9 --- /dev/null +++ b/test/rebar_opts_parser_SUITE.erl @@ -0,0 +1,54 @@ +-module(rebar_opts_parser_SUITE). + +-export([all/0, init_per_testcase/2]). +-export([bad_arg_to_flag/1, missing_arg_to_flag/1]). + +-include_lib("common_test/include/ct.hrl"). + + +all() -> [bad_arg_to_flag, missing_arg_to_flag]. + +init_per_testcase(_, Config) -> + rebar_test_utils:init_rebar_state(Config, "opts_parser_"). + +bad_arg_to_flag(Config) -> + ok = meck:new(getopt), + ok = meck:expect(getopt, + parse, + fun(_, _) -> {error, {invalid_option_arg, {foo, "null"}}} end), + + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("bad_arg_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + {error, Error} = rebar_test_utils:run_and_check(Config, + [], + ["compile", "--foo=null"], + return), + + true = meck:validate(getopt), + ok = meck:unload(getopt), + + "Invalid argument null to option foo" = lists:flatten(Error). + +missing_arg_to_flag(Config) -> + ok = meck:new(getopt), + ok = meck:expect(getopt, parse, fun(_, _) -> {error, {missing_option_arg, foo}} end), + + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("missing_arg_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + {error, Error} = rebar_test_utils:run_and_check(Config, + [], + ["compile", "--foo"], + return), + + true = meck:validate(getopt), + ok = meck:unload(getopt), + + "Missing argument to option foo" = lists:flatten(Error).
\ No newline at end of file diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index a4f926e..6288053 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -100,12 +100,17 @@ profile_merges(_Config) -> {test2, "hello"}, {test3, [key3]}, {test4, "oldvalue"}, + {test5, [{key5, true}]}, + {test6, [{key6, false}]}, {profiles, [{profile1, [{test1, [{key3, 5}, key1]}]}, {profile2, [{test2, "goodbye"}, {test3, []}, - {test4, []}]}]}], + {test4, []}, + {test5, [{key5, false}]}, + {test6, [{key6, true}]} + ]}]}], State = rebar_state:new(RebarConfig), State1 = rebar_state:apply_profiles(State, [profile1, profile2]), @@ -118,7 +123,9 @@ profile_merges(_Config) -> %% Check that a newvalue of []/"" doesn't override non-string oldvalues [key3] = rebar_state:get(State1, test3), - [] = rebar_state:get(State1, test4). + [] = rebar_state:get(State1, test4), + [{key5, false}, {key5, true}] = rebar_state:get(State1, test5), + [{key6, true}, {key6, false}] = rebar_state:get(State1, test6). add_to_profile(_Config) -> RebarConfig = [{foo, true}, {bar, false}], @@ -165,7 +172,7 @@ test_profile_applied_at_completion(Config) -> Name = rebar_test_utils:create_random_name("test_profile_at_completion_"), Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:create_config(AppDir, RebarConfig), @@ -184,7 +191,7 @@ test_profile_applied_before_compile(Config) -> Name = rebar_test_utils:create_random_name("test_profile_before_compile_"), Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:create_config(AppDir, RebarConfig), @@ -199,7 +206,7 @@ test_profile_applied_before_eunit(Config) -> Name = rebar_test_utils:create_random_name("test_profile_before_eunit_"), Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:create_config(AppDir, RebarConfig), @@ -214,7 +221,7 @@ test_profile_applied_to_apps(Config) -> Name = rebar_test_utils:create_random_name("test_profile_applied_to_apps_"), Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:create_config(AppDir, RebarConfig), diff --git a/test/rebar_release_SUITE.erl b/test/rebar_release_SUITE.erl index 92219a5..3809106 100644 --- a/test/rebar_release_SUITE.erl +++ b/test/rebar_release_SUITE.erl @@ -3,7 +3,10 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [release, tar]. +all() -> [release, + dev_mode_release, + profile_dev_mode_override_release, + tar]. init_per_testcase(Case, Config0) -> Config = rebar_test_utils:init_rebar_state(Config0), @@ -33,9 +36,46 @@ release(Config) -> rebar_test_utils:run_and_check( Config, RebarConfig, ["release"], - {ok, [{release, list_to_atom(Name), Vsn}]} + {ok, [{release, list_to_atom(Name), Vsn, false}]} ). +dev_mode_release(Config) -> + AppDir = ?config(apps, Config), + Name = ?config(name, Config), + Vsn = "1.0.0", + {ok, RebarConfig} = + file:consult(rebar_test_utils:create_config(AppDir, + [{relx, [{release, {list_to_atom(Name), Vsn}, + [list_to_atom(Name)]}, + {lib_dirs, [AppDir]}, + {dev_mode, true}]}])), + rebar_test_utils:run_and_check( + Config, RebarConfig, + ["release"], + {ok, [{release, list_to_atom(Name), Vsn, true}]} + ). + + +profile_dev_mode_override_release(Config) -> + AppDir = ?config(apps, Config), + Name = ?config(name, Config), + Vsn = "1.0.0", + {ok, RebarConfig} = + file:consult(rebar_test_utils:create_config(AppDir, + [{relx, [{release, {list_to_atom(Name), Vsn}, + [list_to_atom(Name)]}, + {lib_dirs, [AppDir]}, + {dev_mode, true}]}, + {profiles, + [{ct, + [{relx, [{dev_mode, false}]}]}]}])), + rebar_test_utils:run_and_check( + Config, RebarConfig, + ["as", "ct", "release"], + {ok, [{release, list_to_atom(Name), Vsn, false}]} + ). + + tar(Config) -> AppDir = ?config(apps, Config), Name = ?config(name, Config), @@ -48,5 +88,5 @@ tar(Config) -> rebar_test_utils:run_and_check( Config, RebarConfig, ["tar"], - {ok, [{release, list_to_atom(Name), Vsn}, {tar, Name, Vsn}]} + {ok, [{release, list_to_atom(Name), Vsn, false}, {tar, Name, Vsn}]} ). diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 7c52a18..2eb14ac 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -3,7 +3,7 @@ -include_lib("eunit/include/eunit.hrl"). -export([init_rebar_state/1, init_rebar_state/2, run_and_check/4]). -export([expand_deps/2, flat_deps/1, flat_pkgdeps/1, top_level_deps/1]). --export([create_app/4, create_empty_app/4, create_config/2]). +-export([create_app/4, create_eunit_app/4, create_empty_app/4, create_config/2]). -export([create_random_name/1, create_random_vsn/0]). %%%%%%%%%%%%%% @@ -25,7 +25,8 @@ init_rebar_state(Config, Name) -> ok = ec_file:mkdir_p(CheckoutsDir), Verbosity = rebar3:log_level(), rebar_log:init(command_line, Verbosity), - State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}]), + State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])} + ,{root_dir, AppsDir}]), [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, State} | Config]. %% @doc Takes common test config, a rebar config ([] if empty), a command to @@ -69,7 +70,17 @@ run_and_check(Config, RebarConfig, Command, Expect) -> %% And returns a `rebar_app_info' object. create_app(AppDir, Name, Vsn, Deps) -> write_src_file(AppDir, Name), - write_test_file(AppDir, Name), + write_app_src_file(AppDir, Name, Vsn, Deps), + rebar_app_info:new(Name, Vsn, AppDir, Deps). + +%% @doc Creates a dummy application including: +%% - src/<file>.erl +%% - src/<file>.app.src +%% - test/<file>_tests.erl +%% And returns a `rebar_app_info' object. +create_eunit_app(AppDir, Name, Vsn, Deps) -> + write_eunitized_src_file(AppDir, Name), + write_eunit_suite_file(AppDir, Name), write_app_src_file(AppDir, Name, Vsn, Deps), rebar_app_info:new(Name, Vsn, AppDir, Deps). @@ -217,7 +228,7 @@ check_results(AppDir, Expected) -> ?assertEqual(iolist_to_binary(Vsn), iolist_to_binary(LockVsn)) end - ; ({release, Name, Vsn}) -> + ; ({release, Name, Vsn, ExpectedDevMode}) -> ct:pal("Release: ~p-~s", [Name, Vsn]), {ok, Cwd} = file:get_cwd(), try @@ -228,6 +239,15 @@ check_results(AppDir, Expected) -> {ok, RelxState2} = rlx_prv_app_discover:do(RelxState1), {ok, RelxState3} = rlx_prv_rel_discover:do(RelxState2), + LibDir = filename:join([ReleaseDir, Name, "lib"]), + {ok, RelLibs} = file:list_dir(LibDir), + IsSymLinkFun = + fun(X) -> + ec_file:is_symlink(filename:join(LibDir, X)) + end, + DevMode = lists:all(IsSymLinkFun, RelLibs), + ?assertEqual(ExpectedDevMode, DevMode), + %% throws not_found if it doesn't exist rlx_state:get_realized_release(RelxState3, Name, Vsn) catch @@ -250,10 +270,15 @@ write_src_file(Dir, Name) -> ok = filelib:ensure_dir(Erl), ok = ec_file:write(Erl, erl_src_file("not_a_real_src_" ++ Name ++ ".erl")). -write_test_file(Dir, Name) -> +write_eunitized_src_file(Dir, Name) -> + Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]), + ok = filelib:ensure_dir(Erl), + ok = ec_file:write(Erl, erl_eunitized_src_file("not_a_real_src_" ++ Name ++ ".erl")). + +write_eunit_suite_file(Dir, Name) -> Erl = filename:join([Dir, "test", "not_a_real_src_" ++ Name ++ "_tests.erl"]), ok = filelib:ensure_dir(Erl), - ok = ec_file:write(Erl, erl_test_file("not_a_real_src_" ++ Name ++ ".erl")). + ok = ec_file:write(Erl, erl_eunit_suite_file("not_a_real_src_" ++ Name ++ ".erl")). write_app_file(Dir, Name, Version, Deps) -> Filename = filename:join([Dir, "ebin", Name ++ ".app"]), @@ -268,13 +293,18 @@ write_app_src_file(Dir, Name, Version, Deps) -> erl_src_file(Name) -> io_lib:format("-module(~s).\n" "-export([main/0]).\n" + "main() -> ok.\n", [filename:basename(Name, ".erl")]). + +erl_eunitized_src_file(Name) -> + io_lib:format("-module(~s).\n" + "-export([main/0]).\n" "main() -> ok.\n" "-ifdef(TEST).\n" "-include_lib(\"eunit/include/eunit.hrl\").\n" "some_test_() -> ?_assertEqual(ok, main()).\n" "-endif.\n", [filename:basename(Name, ".erl")]). -erl_test_file(Name) -> +erl_eunit_suite_file(Name) -> BaseName = filename:basename(Name, ".erl"), io_lib:format("-module(~s_tests).\n" "-compile(export_all).\n" |