diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mock_pkg_resource.erl | 11 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 85 | ||||
-rw-r--r-- | test/rebar_deps_SUITE.erl | 2 | ||||
-rw-r--r-- | test/rebar_dialyzer_SUITE.erl | 19 | ||||
-rw-r--r-- | test/rebar_dir_SUITE.erl | 99 | ||||
-rw-r--r-- | test/rebar_disable_app_SUITE.erl | 49 | ||||
-rw-r--r-- | test/rebar_hooks_SUITE.erl | 97 | ||||
-rw-r--r-- | test/rebar_install_deps_SUITE.erl | 34 | ||||
-rw-r--r-- | test/rebar_pkg_SUITE.erl | 8 | ||||
-rw-r--r-- | test/rebar_plugins_SUITE.erl | 201 | ||||
-rw-r--r-- | test/rebar_release_SUITE.erl | 21 | ||||
-rw-r--r-- | test/rebar_src_dirs_SUITE.erl (renamed from test/rebar_extra_src_dirs_SUITE.erl) | 95 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 58 | ||||
-rw-r--r-- | test/rebar_upgrade_SUITE.erl | 118 | ||||
-rw-r--r-- | test/rebar_utils_SUITE.erl | 17 |
15 files changed, 816 insertions, 98 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl index e94ea93..eda863b 100644 --- a/test/mock_pkg_resource.erl +++ b/test/mock_pkg_resource.erl @@ -15,7 +15,7 @@ mock() -> mock([]). %% Specific config options are explained in each of the private functions. -spec mock(Opts) -> ok when Opts :: [Option], - Option :: {update, [App]} + Option :: {upgrade, [App]} | {cache_dir, string()} | {default_vsn, Vsn} | {override_vsn, [{App, Vsn}]} @@ -73,6 +73,7 @@ mock_vsn(_Opts) -> %% into a `rebar.config' file to describe dependencies. mock_download(Opts) -> Deps = proplists:get_value(pkgdeps, Opts, []), + Config = proplists:get_value(config, Opts, []), meck:expect( ?MOD, download, fun (Dir, {pkg, AppBin, Vsn}, _) -> @@ -83,7 +84,7 @@ mock_download(Opts) -> Dir, App, binary_to_list(Vsn), [kernel, stdlib] ++ [element(1,D) || D <- AppDeps] ), - rebar_test_utils:create_config(Dir, [{deps, AppDeps}]), + rebar_test_utils:create_config(Dir, [{deps, AppDeps}]++Config), TarApp = App++"-"++binary_to_list(Vsn)++".tar", Tarball = filename:join([Dir, TarApp]), Contents = filename:join([Dir, "contents.tar.gz"]), @@ -120,7 +121,6 @@ mock_pkg_index(Opts) -> meck:expect(rebar_packages, get_packages, fun(_State) -> {Dict, Digraph} end). - %%%%%%%%%%%%%%% %%% Helpers %%% %%%%%%%%%%%%%%% @@ -151,15 +151,14 @@ find_parts([{AppName, Deps}|Rest], Skip, Acc) -> true -> find_parts(Rest, Skip, Acc); false -> AccNew = dict:store(AppName, - [{<<"deps">>,Deps}, {<<"link">>,<<"undef">>}], + Deps, Acc), find_parts(Rest, Skip, AccNew) end. to_graph_parts(Dict) -> LastUpdated = os:timestamp(), - dict:fold(fun(K,V,{Ks,Vs}) -> - {_,Deps} = lists:keyfind(<<"deps">>, 1, V), + dict:fold(fun(K,Deps,{Ks,Vs}) -> {[{K,LastUpdated}|Ks], [{K,{list_to_binary(atom_to_list(DK)), list_to_binary(DV)}} || {DK,DV} <- Deps] ++ Vs} diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index bdab075..8dca46c 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -18,9 +18,9 @@ deps_in_path/1, delete_beam_if_source_deleted/1, checkout_priority/1, - compile_plugins/1, highest_version_of_pkg_dep/1, - parse_transform_test/1]). + parse_transform_test/1, + erl_first_files_test/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -47,8 +47,8 @@ all() -> build_all_srcdirs, recompile_when_hrl_changes, recompile_when_opts_change, dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted, - deps_in_path, checkout_priority, compile_plugins, highest_version_of_pkg_dep, - parse_transform_test]. + deps_in_path, checkout_priority, highest_version_of_pkg_dep, + parse_transform_test, erl_first_files_test]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -163,9 +163,10 @@ recompile_when_hrl_changes(Config) -> ModTime = [filelib:last_modified(filename:join([EbinDir, F])) || F <- Files, filename:extension(F) == ".beam"], + timer:sleep(1000), - os:cmd("touch " ++ HeaderFile), + rebar_file_utils:touch(HeaderFile), rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), @@ -274,9 +275,9 @@ delete_beam_if_source_deleted(Config) -> rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), - SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]), + _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]), ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))), - file:delete(filename:join(SrcDir, "not_a_real_src_" ++ Name ++ ".erl")), + file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])), rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), @@ -307,6 +308,7 @@ deps_in_path(Config) -> ?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 @@ -397,35 +399,6 @@ checkout_priority(Config) -> ?assertEqual(Vsn2, proplists:get_value(vsn, DepProps)), ?assertEqual(Vsn2, proplists:get_value(vsn, PkgProps)). -%% Tests that compiling a project installs and compiles the plugins of deps -compile_plugins(Config) -> - AppDir = ?config(apps, Config), - - 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_"), - PluginName = rebar_test_utils:create_random_name("plugin1_"), - mock_git_resource:mock([{config, [{plugins, [ - {list_to_atom(PluginName), Vsn} - ]}]}]), - mock_pkg_resource:mock([ - {pkgdeps, [{{iolist_to_binary(PluginName), 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}}} - ]}]), - {ok, RConf} = file:consult(RConfFile), - - %% Build with deps. - rebar_test_utils:run_and_check( - Config, RConf, ["compile"], - {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]} - ). highest_version_of_pkg_dep(Config) -> AppDir = ?config(apps, Config), @@ -472,3 +445,43 @@ parse_transform_test(Config) -> EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])). + +erl_first_files_test(Config) -> + AppDir = ?config(apps, Config), + RebarConfig = [{erl_opts, [{parse_transform, mark_time}]}, + {erl_first_files, ["src/mark_time.erl", + "src/b.erl", + "src/d.erl", + "src/a.erl"]}], + + 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]), + rebar_test_utils:write_src_file(AppDir, "a.erl"), + rebar_test_utils:write_src_file(AppDir, "b.erl"), + rebar_test_utils:write_src_file(AppDir, "d.erl"), + rebar_test_utils:write_src_file(AppDir, "e.erl"), + + ExtraSrc = <<"-module(mark_time). " + "-export([parse_transform/2]). " + "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> " + " [Form, {attribute,1,number, os:timestamp()} | Forms];" + "parse_transform([Form|Forms], Options) -> " + " [Form | parse_transform(Forms, Options)].">>, + + ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}), + + EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), + true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])), + + code:load_abs(filename:join([EbinDir, "a"])), + code:load_abs(filename:join([EbinDir, "b"])), + code:load_abs(filename:join([EbinDir, "d"])), + code:load_abs(filename:join([EbinDir, "e"])), + A = proplists:get_value(number, a:module_info(attributes)), + B = proplists:get_value(number, b:module_info(attributes)), + D = proplists:get_value(number, d:module_info(attributes)), + E = proplists:get_value(number, e:module_info(attributes)), + ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])). diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index 6b902a5..afd487e 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -215,7 +215,7 @@ newly_added_dep(Config) -> {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_file(LockFile)), + rebar_config:consult_lock_file(LockFile)), %% a should now be installed and c should not change rebar_test_utils:run_and_check( diff --git a/test/rebar_dialyzer_SUITE.erl b/test/rebar_dialyzer_SUITE.erl index 724d8f0..1160d2d 100644 --- a/test/rebar_dialyzer_SUITE.erl +++ b/test/rebar_dialyzer_SUITE.erl @@ -25,15 +25,16 @@ end_per_suite(_Config) -> init_per_testcase(Testcase, Config) -> PrivDir = ?config(priv_dir, Config), Prefix = ec_cnv:to_list(Testcase), - Plt = filename:join(PrivDir, Prefix ++ ".project.plt"), - BasePlt = Prefix ++ "base.plt", - RebarConfig = [{dialyzer_plt, Plt}, - {dialyzer_base_plt, BasePlt}, - {dialyzer_base_plt_dir, PrivDir}, - {dialyzer_base_plt_apps, [erts]}], - [{plt, Plt}, - {base_plt, filename:join(PrivDir, BasePlt)}, - {rebar_config, RebarConfig} | + BasePrefix = Prefix ++ "_base", + Opts = [{plt_prefix, Prefix}, + {plt_location, PrivDir}, + {base_plt_prefix, BasePrefix}, + {base_plt_location, PrivDir}, + {base_plt_apps, [erts]}], + Suffix = "_" ++ rebar_utils:otp_release() ++ "_plt", + [{plt, filename:join(PrivDir, Prefix ++ Suffix)}, + {base_plt, filename:join(PrivDir, BasePrefix ++ Suffix)}, + {rebar_config, [{dialyzer, Opts}]} | rebar_test_utils:init_rebar_state(Config)]. all() -> diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl new file mode 100644 index 0000000..a3c5052 --- /dev/null +++ b/test/rebar_dir_SUITE.erl @@ -0,0 +1,99 @@ +-module(rebar_dir_SUITE). + +-export([all/0, init_per_testcase/2, end_per_testcase/2]). + +-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]). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-include_lib("kernel/include/file.hrl"). + + +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]. + +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. + +end_per_testcase(_, _Config) -> ok. + +default_src_dirs(Config) -> + {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), + + [] = rebar_dir:src_dirs(State), + ["src"] = rebar_dir:src_dirs(State, ["src"]). + +default_extra_src_dirs(Config) -> + {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), + + [] = rebar_dir:extra_src_dirs(State), + ["src"] = rebar_dir:extra_src_dirs(State, ["src"]). + +default_all_src_dirs(Config) -> + {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), + + [] = rebar_dir:all_src_dirs(State), + ["src", "test"] = rebar_dir:all_src_dirs(State, ["src"], ["test"]). + +src_dirs(Config) -> + RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz"] = rebar_dir:src_dirs(State). + +extra_src_dirs(Config) -> + RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(State). + +all_src_dirs(Config) -> + RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}, {extra_src_dirs, ["baz", "qux"]}]}], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz", "qux"] = rebar_dir:all_src_dirs(State). + +profile_src_dirs(Config) -> + RebarConfig = [ + {erl_opts, [{src_dirs, ["foo", "bar"]}]}, + {profiles, [ + {more, [{erl_opts, [{src_dirs, ["baz", "qux"]}]}]} + ]} + ], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), + + R = lists:sort(["foo", "bar", "baz", "qux"]), + R = lists:sort(rebar_dir:src_dirs(State)). + +profile_extra_src_dirs(Config) -> + RebarConfig = [ + {erl_opts, [{extra_src_dirs, ["foo", "bar"]}]}, + {profiles, [ + {more, [{erl_opts, [{extra_src_dirs, ["baz", "qux"]}]}]} + ]} + ], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), + + R = lists:sort(["foo", "bar", "baz", "qux"]), + R = lists:sort(rebar_dir:extra_src_dirs(State)). + +profile_all_src_dirs(Config) -> + RebarConfig = [ + {erl_opts, [{src_dirs, ["foo"]}, {extra_src_dirs, ["bar"]}]}, + {profiles, [ + {more, [{erl_opts, [{src_dirs, ["baz"]}, {extra_src_dirs, ["qux"]}]}]} + ]} + ], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), + + R = lists:sort(["foo", "bar", "baz", "qux"]), + R = lists:sort(rebar_dir:all_src_dirs(State)). diff --git a/test/rebar_disable_app_SUITE.erl b/test/rebar_disable_app_SUITE.erl new file mode 100644 index 0000000..dd71ffb --- /dev/null +++ b/test/rebar_disable_app_SUITE.erl @@ -0,0 +1,49 @@ +-module(rebar_disable_app_SUITE). +-compile(export_all). +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +-define(MOD(Name), + io_lib:format("-module(~s).~n-export([x/0]).~nx() -> ok.~n", [Name])). + +all() -> [disable_app]. + +init_per_testcase(_, Config) -> + rebar_test_utils:init_rebar_state(Config). + +end_per_testcase(_, _Config) -> + ok. + +disable_app(Config) -> + AppDir = ?config(apps, Config), + + Name1 = create_random_app(AppDir, "app1_"), + Name2 = create_random_app(AppDir, "app2_"), + + RebarConfig = [{excluded_apps, [list_to_atom(Name1)]}], + %RebarConfig = [], + + rebar_test_utils:run_and_check( + Config, RebarConfig, ["compile"], + {ok, [{app, Name2}]}), + + App1 = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin", Name1 ++ ".app"]), + ?assertEqual(filelib:is_file(App1), false), + + App2 = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin", Name2 ++ ".app"]), + ?assertEqual(filelib:is_file(App2), true). + +%% +%% Utils +%% +create_random_app(AppDir, Prefix) -> + Name = rebar_test_utils:create_random_name(Prefix), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_empty_app(filename:join([AppDir, "apps", Name]), Name, Vsn, [kernel, stdlib]), + + ModName = rebar_test_utils:create_random_name("mod1_"), + Mod = filename:join([AppDir, "apps", Name, "src", ModName ++ ".erl"]), + ok = filelib:ensure_dir(Mod), + Src = ?MOD(ModName), + ok = ec_file:write(Mod, Src), + Name. diff --git a/test/rebar_hooks_SUITE.erl b/test/rebar_hooks_SUITE.erl index 642798f..85ca0e5 100644 --- a/test/rebar_hooks_SUITE.erl +++ b/test/rebar_hooks_SUITE.erl @@ -4,8 +4,13 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, + end_per_testcase/2, all/0, - build_and_clean_app/1]). + build_and_clean_app/1, + escriptize_artifacts/1, + run_hooks_once/1, + run_hooks_for_plugins/1, + deps_hook_namespace/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -18,13 +23,17 @@ init_per_suite(Config) -> Config. end_per_suite(_Config) -> - ok. + meck:unload(). init_per_testcase(_, Config) -> rebar_test_utils:init_rebar_state(Config). +end_per_testcase(_, _Config) -> + catch meck:unload(). + all() -> - [build_and_clean_app]. + [build_and_clean_app, run_hooks_once, escriptize_artifacts, + run_hooks_for_plugins, deps_hook_namespace]. %% Test post provider hook cleans compiled project app, leaving it invalid build_and_clean_app(Config) -> @@ -36,3 +45,85 @@ build_and_clean_app(Config) -> rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name, valid}]}), rebar_test_utils:run_and_check(Config, [{provider_hooks, [{post, [{compile, clean}]}]}], ["compile"], {ok, [{app, Name, invalid}]}). + +escriptize_artifacts(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + Artifact = "bin/"++Name, + RConfFile = + rebar_test_utils:create_config(AppDir, + [ + {escript_name, list_to_atom(Name)} + ,{artifacts, [Artifact]} + ]), + {ok, RConf} = file:consult(RConfFile), + + try rebar_test_utils:run_and_check(Config, RConf, ["compile"], return) + catch + {error, + {rebar_prv_compile, + {missing_artifact, Artifact}}} -> + ok + end, + rebar_test_utils:run_and_check(Config, RConf++[{provider_hooks, [{post, [{compile, escriptize}]}]}], + ["compile"], {ok, [{app, Name, valid} + ,{file, filename:join([AppDir, "_build/default/", Artifact])}]}). + +run_hooks_once(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + RebarConfig = [{pre_hooks, [{compile, "mkdir blah"}]}], + rebar_test_utils:create_config(AppDir, RebarConfig), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name, valid}]}). + +deps_hook_namespace(Config) -> + mock_git_resource:mock([{deps, [{some_dep, "0.0.1"}]}]), + Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", []}]), + TopDeps = rebar_test_utils:top_level_deps(Deps), + + RebarConfig = [ + {deps, TopDeps}, + {overrides, [ + {override, some_dep, [ + {provider_hooks, [ + {pre, [ + {compile, clean} + ]} + ]} + ]} + ]} + ], + rebar_test_utils:run_and_check( + Config, RebarConfig, ["compile"], + {ok, [{dep, "some_dep"}]} + ). + +run_hooks_for_plugins(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + PluginName = rebar_test_utils:create_random_name("plugin1_"), + mock_git_resource:mock([{config, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]}]}]), + + RConfFile = rebar_test_utils:create_config(AppDir, + [{plugins, [ + {list_to_atom(PluginName), + {git, "http://site.com/user/"++PluginName++".git", + {tag, Vsn}}} + ]}]), + {ok, RConf} = file:consult(RConfFile), + + rebar_test_utils:run_and_check(Config, RConf, ["compile"], {ok, [{app, Name, valid}, + {plugin, PluginName}, + {file, filename:join([AppDir, "_build", "default", "plugins", PluginName, "randomfile"])}]}). diff --git a/test/rebar_install_deps_SUITE.erl b/test/rebar_install_deps_SUITE.erl index d1a1118..dca6308 100644 --- a/test/rebar_install_deps_SUITE.erl +++ b/test/rebar_install_deps_SUITE.erl @@ -48,10 +48,10 @@ end_per_testcase(_, Config) -> Config. format_expected_deps(Deps) -> - [case Dep of - {N,V} -> {dep, N, V}; - N -> {dep, N} - end || Dep <- Deps]. + lists:append([case Dep of + {N,V} -> [{dep, N, V}, {lock, N, V}]; + N -> [{dep, N}, {lock, N}] + end || Dep <- Deps]). %% format: %% {Spec, @@ -200,7 +200,7 @@ circular_skip(Config) -> run(Config). fail_conflict(Config) -> {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), rebar_test_utils:run_and_check( - Config, RebarConfig, ["install_deps"], ?config(expect, Config) + Config, RebarConfig, ["lock"], ?config(expect, Config) ), check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)). @@ -209,7 +209,7 @@ default_profile(Config) -> AppDir = ?config(apps, Config), {ok, Apps} = Expect = ?config(expect, Config), rebar_test_utils:run_and_check( - Config, RebarConfig, ["as", "profile", "install_deps"], Expect + Config, RebarConfig, ["as", "profile", "lock"], Expect ), check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)), BuildDir = filename:join([AppDir, "_build"]), @@ -221,18 +221,30 @@ default_profile(Config) -> || {dep, App} <- Apps], %% A second run to another profile also links default to the right spot rebar_test_utils:run_and_check( - Config, RebarConfig, ["as", "other", "install_deps"], Expect + Config, RebarConfig, ["as", "other", "lock"], Expect ), [?assertMatch({ok, #file_info{type=directory}}, % somehow symlinks return dirs file:read_file_info(filename:join([BuildDir, "other", "lib", App]))) || {dep, App} <- Apps]. nondefault_profile(Config) -> + %% The dependencies here are saved directly to the {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), AppDir = ?config(apps, Config), - {ok, Apps} = Expect = ?config(expect, Config), + {ok, AppLocks} = ?config(expect, Config), + try + rebar_test_utils:run_and_check( + Config, RebarConfig, ["as", "nondef", "lock"], {ok, AppLocks} + ), + error(generated_locks) + catch + error:generated_locks -> error(generated_locks); + _:_ -> ok + end, + Apps = [App || App = {dep, _} <- AppLocks], + Expect = {ok, Apps}, rebar_test_utils:run_and_check( - Config, RebarConfig, ["as", "nondef", "install_deps"], Expect + Config, RebarConfig, ["as", "nondef", "lock"], Expect ), check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)), BuildDir = filename:join([AppDir, "_build"]), @@ -244,7 +256,7 @@ nondefault_profile(Config) -> || {dep, App} <- Apps], %% A second run to another profile doesn't link dependencies rebar_test_utils:run_and_check( - Config, RebarConfig, ["as", "other", "install_deps"], Expect + Config, RebarConfig, ["as", "other", "lock"], Expect ), [?assertMatch({error, enoent}, file:read_file_info(filename:join([BuildDir, "default", "lib", App]))) @@ -254,7 +266,7 @@ nondefault_profile(Config) -> run(Config) -> {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), rebar_test_utils:run_and_check( - Config, RebarConfig, ["install_deps"], ?config(expect, Config) + Config, RebarConfig, ["lock"], ?config(expect, Config) ), check_warnings(warning_calls(), ?config(warnings, Config), ?config(deps_type, Config)). diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl index 95eb6f6..85bd6f0 100644 --- a/test/rebar_pkg_SUITE.erl +++ b/test/rebar_pkg_SUITE.erl @@ -61,7 +61,7 @@ init_per_testcase(good_disconnect=Name, Config0) -> copy_to_cache(Pkg, Config), meck:unload(httpc), meck:new(httpc, [passthrough, unsticky]), - meck:expect(httpc, request, fun(_, _, _, _) -> {error, econnrefused} end), + meck:expect(httpc, request, fun(_, _, _, _, _) -> {error, econnrefused} end), Config; init_per_testcase(bad_disconnect=Name, Config0) -> Pkg = {<<"goodpkg">>, <<"1.0.0">>}, @@ -71,7 +71,7 @@ init_per_testcase(bad_disconnect=Name, Config0) -> Config = mock_config(Name, Config1), meck:unload(httpc), meck:new(httpc, [passthrough, unsticky]), - meck:expect(httpc, request, fun(_, _, _, _) -> {error, econnrefused} end), + meck:expect(httpc, request, fun(_, _, _, _, _) -> {error, econnrefused} end), Config. end_per_testcase(_, Config) -> @@ -186,9 +186,9 @@ mock_config(Name, Config) -> {ok, PkgContents} = file:read_file(filename:join(?config(data_dir, Config), PkgFile)), meck:new(httpc, [passthrough, unsticky]), meck:expect(httpc, request, - fun(get, {_Url, _Opts}, _, _) when GoodCache -> + fun(get, {_Url, _Opts}, _, _, _) when GoodCache -> {ok, {{Vsn, 304, <<"Not Modified">>}, [{"etag", ?good_etag}], <<>>}}; - (get, {_Url, _Opts}, _, _) -> + (get, {_Url, _Opts}, _, _, _) -> {ok, {{Vsn, 200, <<"OK">>}, [{"etag", ?good_etag}], PkgContents}} end), [{cache_root, CacheRoot}, diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl new file mode 100644 index 0000000..adfeafe --- /dev/null +++ b/test/rebar_plugins_SUITE.erl @@ -0,0 +1,201 @@ +-module(rebar_plugins_SUITE). + +-export([suite/0, + init_per_suite/1, + end_per_suite/1, + init_per_testcase/2, + end_per_testcase/2, + all/0, + compile_plugins/1, + compile_global_plugins/1, + complex_plugins/1, + upgrade/1]). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-include_lib("kernel/include/file.hrl"). + +suite() -> + []. + +init_per_suite(Config) -> + Config. + +end_per_suite(_Config) -> + ok. + +init_per_testcase(_, Config) -> + rebar_test_utils:init_rebar_state(Config). + +end_per_testcase(_, _Config) -> + catch meck:unload(). + +all() -> + [compile_plugins, compile_global_plugins, complex_plugins, upgrade]. + +%% Tests that compiling a project installs and compiles the plugins of deps +compile_plugins(Config) -> + AppDir = ?config(apps, Config), + + 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_"), + PluginName = rebar_test_utils:create_random_name("plugin1_"), + + Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Plugins)}]), + + mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]}, + {config, [{plugins, [ + {list_to_atom(PluginName), + {git, "http://site.com/user/"++PluginName++".git", + {tag, Vsn}}}]}]}]), + + RConfFile = + rebar_test_utils:create_config(AppDir, + [{deps, [ + list_to_atom(DepName) + ]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]} + ). + +%% Tests that compiling a project installs and compiles the global plugins +compile_global_plugins(Config) -> + AppDir = ?config(apps, Config), + GlobalDir = filename:join(AppDir, "global"), + GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]), + GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]), + + meck:new(rebar_dir, [passthrough]), + meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end), + meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + DepName = rebar_test_utils:create_random_name("dep1_"), + PluginName = rebar_test_utils:create_random_name("plugin1_"), + + mock_git_resource:mock([{deps, [{list_to_atom(PluginName), Vsn}, + {list_to_atom(PluginName), Vsn2}, + {{iolist_to_binary(DepName), iolist_to_binary(Vsn)}, []}]}]), + + + rebar_test_utils:create_config(GlobalConfigDir, + [{plugins, [ + {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn}}} + ]}]), + RConfFile = + rebar_test_utils:create_config(AppDir, + [{deps, [ + {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}} + ]}, + {plugins, [ + {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}} + ]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Runs global plugin install + rebar3:init_config(), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, + {global_plugin, PluginName, Vsn}, + {plugin, PluginName, Vsn2}, + {dep, DepName}]} + ), + + meck:unload(rebar_dir). + +%% Tests installing of plugin with transitive deps +complex_plugins(Config) -> + AppDir = ?config(apps, Config), + + meck:new(rebar_dir, [passthrough]), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + DepName = rebar_test_utils:create_random_name("dep1_"), + DepName2 = rebar_test_utils:create_random_name("dep2_"), + DepName3 = rebar_test_utils:create_random_name("dep3_"), + PluginName = rebar_test_utils:create_random_name("plugin1_"), + + Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn2, [{DepName2, Vsn, + [{DepName3, Vsn, []}]}]} + ,{DepName, Vsn, []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]), + + RConfFile = + rebar_test_utils:create_config(AppDir, + [{deps, [ + {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}} + ]}, + {plugins, [ + {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}} + ]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, + {plugin, PluginName, Vsn2}, + {plugin, DepName2}, + {plugin, DepName3}, + {dep, DepName}]} + ), + + meck:unload(rebar_dir). + +upgrade(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + PkgName = rebar_test_utils:create_random_name("pkg1_"), + mock_git_resource:mock([]), + mock_pkg_resource:mock([ + {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}, + {{iolist_to_binary(PkgName), <<"0.0.1">>}, []}, + {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]} + ]), + + RConfFile = rebar_test_utils:create_config(AppDir, [{plugins, [list_to_atom(PkgName)]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {plugin, PkgName, <<"0.1.1">>}]} + ), + + catch mock_pkg_resource:unmock(), + mock_pkg_resource:mock([ + {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}, + {{iolist_to_binary(PkgName), <<"0.0.1">>}, []}, + {{iolist_to_binary(PkgName), <<"0.1.3">>}, []}, + {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]}, + {upgrade, [PkgName]} + ]), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["plugins", "upgrade", PkgName], + {ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]} + ). diff --git a/test/rebar_release_SUITE.erl b/test/rebar_release_SUITE.erl index 3809106..1ef0771 100644 --- a/test/rebar_release_SUITE.erl +++ b/test/rebar_release_SUITE.erl @@ -6,7 +6,8 @@ all() -> [release, dev_mode_release, profile_dev_mode_override_release, - tar]. + tar, + extend_release]. init_per_testcase(Case, Config0) -> Config = rebar_test_utils:init_rebar_state(Config0), @@ -90,3 +91,21 @@ tar(Config) -> ["tar"], {ok, [{release, list_to_atom(Name), Vsn, false}, {tar, Name, Vsn}]} ). + +%% Test that the order of release config args is not lost. If it is extend would fail. +extend_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)]}, + {release, {extended, Vsn, {extend, list_to_atom(Name)}}, + []}, + {lib_dirs, [AppDir]}]}])), + rebar_test_utils:run_and_check( + Config, RebarConfig, + ["release", "-n", "extended"], + {ok, [{release, extended, Vsn, false}]} + ). diff --git a/test/rebar_extra_src_dirs_SUITE.erl b/test/rebar_src_dirs_SUITE.erl index a00bb2d..1804fbf 100644 --- a/test/rebar_extra_src_dirs_SUITE.erl +++ b/test/rebar_src_dirs_SUITE.erl @@ -1,4 +1,4 @@ --module(rebar_extra_src_dirs_SUITE). +-module(rebar_src_dirs_SUITE). -export([suite/0, init_per_suite/1, @@ -6,9 +6,15 @@ init_per_testcase/2, end_per_testcase/2, all/0, + src_dirs_at_root/1, + extra_src_dirs_at_root/1, + src_dirs_in_erl_opts/1, + extra_src_dirs_in_erl_opts/1, + src_dirs_at_root_and_in_erl_opts/1, + extra_src_dirs_at_root_and_in_erl_opts/1, build_basic_app/1, build_multi_apps/1, - src_dir_takes_precedence/1]). + src_dir_takes_precedence_over_extra/1]). -include_lib("common_test/include/ct.hrl"). @@ -27,7 +33,88 @@ init_per_testcase(_, Config) -> end_per_testcase(_, _Config) -> ok. all() -> - [build_basic_app, build_multi_apps, src_dir_takes_precedence]. + [src_dirs_at_root, extra_src_dirs_at_root, + src_dirs_in_erl_opts, extra_src_dirs_in_erl_opts, + src_dirs_at_root_and_in_erl_opts, extra_src_dirs_at_root_and_in_erl_opts, + build_basic_app, build_multi_apps, src_dir_takes_precedence_over_extra]. + +src_dirs_at_root(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + RebarConfig = [{src_dirs, ["foo", "bar", "baz"]}], + + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz"] = rebar_dir:src_dirs(State, []). + +extra_src_dirs_at_root(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + RebarConfig = [{extra_src_dirs, ["foo", "bar", "baz"]}], + + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(State, []). + +src_dirs_in_erl_opts(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}], + + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz"] = rebar_dir:src_dirs(State, []). + +extra_src_dirs_in_erl_opts(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}], + + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(State, []). + +src_dirs_at_root_and_in_erl_opts(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}], + + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["baz", "qux", "foo", "bar"] = rebar_dir:src_dirs(State, []). + +extra_src_dirs_at_root_and_in_erl_opts(Config) -> + AppDir = ?config(apps, Config), + + 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]), + + RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar"]}]}, {extra_src_dirs, ["baz", "qux"]}], + + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["baz", "qux", "foo", "bar"] = rebar_dir:extra_src_dirs(State, []). build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -118,7 +205,7 @@ build_multi_apps(Config) -> Mods2 = proplists:get_value(modules, KVs2), false = lists:member(extra2, Mods2). -src_dir_takes_precedence(Config) -> +src_dir_takes_precedence_over_extra(Config) -> AppDir = ?config(apps, Config), Name = rebar_test_utils:create_random_name("app1_"), diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 2cdc58b..4943d4b 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -4,7 +4,7 @@ -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_eunit_app/4, create_empty_app/4, create_config/2]). --export([create_random_name/1, create_random_vsn/0]). +-export([create_random_name/1, create_random_vsn/0, write_src_file/2]). %%%%%%%%%%%%%% %%% Public %%% @@ -70,7 +70,8 @@ run_and_check(Config, RebarConfig, Command, Expect) -> %% - src/<file>.app.src %% And returns a `rebar_app_info' object. create_app(AppDir, Name, Vsn, Deps) -> - write_src_file(AppDir, Name), + write_src_file(AppDir, Name ++ ".erl"), + write_src_file(AppDir, "not_a_real_src_" ++ Name ++ ".erl"), write_app_src_file(AppDir, Name, Vsn, Deps), rebar_app_info:new(Name, Vsn, AppDir, Deps). @@ -104,16 +105,22 @@ create_config(AppDir, Contents) -> %% @doc Util to create a random variation of a given name. create_random_name(Name) -> - random:seed(os:timestamp()), + random_seed(), Name ++ erlang:integer_to_list(random:uniform(1000000)). %% @doc Util to create a random variation of a given version. create_random_vsn() -> - random:seed(os:timestamp()), + random_seed(), lists:flatten([erlang:integer_to_list(random:uniform(100)), ".", erlang:integer_to_list(random:uniform(100)), ".", erlang:integer_to_list(random:uniform(100))]). +random_seed() -> + <<A:32, B:32, C:32>> = crypto:rand_bytes(12), + random:seed({A,B,C}). + + + expand_deps(_, []) -> []; expand_deps(git, [{Name, Deps} | Rest]) -> Dep = {Name, ".*", {git, "https://example.org/user/"++Name++".git", "master"}}, @@ -160,9 +167,10 @@ top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) -> check_results(AppDir, Expected) -> BuildDirs = filelib:wildcard(filename:join([AppDir, "_build", "*", "lib"])), PluginDirs = filelib:wildcard(filename:join([AppDir, "_build", "*", "plugins"])), + GlobalPluginDirs = filelib:wildcard(filename:join([AppDir, "global", "plugins"])), CheckoutsDir = filename:join([AppDir, "_checkouts"]), LockFile = filename:join([AppDir, "rebar.lock"]), - Locks = lists:flatten(rebar_config:consult_file(LockFile)), + Locks = lists:flatten(rebar_config:consult_lock_file(LockFile)), InvalidApps = rebar_app_discover:find_apps(BuildDirs, invalid), ValidApps = rebar_app_discover:find_apps(BuildDirs, valid), @@ -176,10 +184,12 @@ check_results(AppDir, Expected) -> CheckoutsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Checkouts], Plugins = rebar_app_discover:find_apps(PluginDirs, all), PluginsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Plugins], + GlobalPlugins = rebar_app_discover:find_apps(GlobalPluginDirs, all), + GlobalPluginsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- GlobalPlugins], lists:foreach( fun({app, Name}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("App Name: ~p", [Name]), case lists:keyfind(Name, 1, DepsNames) of false -> error({app_not_found, Name}); @@ -187,7 +197,7 @@ check_results(AppDir, Expected) -> ok end ; ({app, Name, invalid}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("Invalid Name: ~p", [Name]), case lists:keyfind(Name, 1, InvalidDepsNames) of false -> error({app_not_found, Name}); @@ -195,7 +205,7 @@ check_results(AppDir, Expected) -> ok end ; ({app, Name, valid}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("Valid Name: ~p", [Name]), case lists:keyfind(Name, 1, ValidDepsNames) of false -> error({app_not_found, Name}); @@ -203,13 +213,13 @@ check_results(AppDir, Expected) -> ok end ; ({checkout, Name}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("Checkout Name: ~p", [Name]), ?assertNotEqual(false, lists:keyfind(Name, 1, CheckoutsNames)) ; ({dep, Name}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("Dep Name: ~p", [Name]), ?assertNotEqual(false, lists:keyfind(Name, 1, DepsNames)) ; ({dep, Name, Vsn}) -> - ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]), + ct:pal("Dep Name: ~p, Vsn: ~p", [Name, Vsn]), case lists:keyfind(Name, 1, DepsNames) of false -> error({dep_not_found, Name}); @@ -218,22 +228,34 @@ check_results(AppDir, Expected) -> iolist_to_binary(rebar_app_info:original_vsn(App))) end ; ({plugin, Name}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("Plugin Name: ~p", [Name]), ?assertNotEqual(false, lists:keyfind(Name, 1, PluginsNames)) ; ({plugin, Name, Vsn}) -> - ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]), + ct:pal("Plugin Name: ~p, Vsn: ~p", [Name, Vsn]), case lists:keyfind(Name, 1, PluginsNames) of false -> - error({dep_not_found, Name}); + error({plugin_not_found, Name}); + {Name, App} -> + ?assertEqual(iolist_to_binary(Vsn), + iolist_to_binary(rebar_app_info:original_vsn(App))) + end + ; ({global_plugin, Name}) -> + ct:pal("Global Plugin Name: ~p", [Name]), + ?assertNotEqual(false, lists:keyfind(Name, 1, GlobalPluginsNames)) + ; ({global_plugin, Name, Vsn}) -> + ct:pal("Global Plugin Name: ~p, Vsn: ~p", [Name, Vsn]), + case lists:keyfind(Name, 1, GlobalPluginsNames) of + false -> + error({global_plugin_not_found, Name}); {Name, App} -> ?assertEqual(iolist_to_binary(Vsn), iolist_to_binary(rebar_app_info:original_vsn(App))) end ; ({lock, Name}) -> - ct:pal("Name: ~p", [Name]), + ct:pal("Lock Name: ~p", [Name]), ?assertNotEqual(false, lists:keyfind(iolist_to_binary(Name), 1, Locks)) ; ({lock, Name, Vsn}) -> - ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]), + ct:pal("Lock Name: ~p, Vsn: ~p", [Name, Vsn]), case lists:keyfind(iolist_to_binary(Name), 1, Locks) of false -> error({lock_not_found, Name}); @@ -282,9 +304,9 @@ check_results(AppDir, Expected) -> end, Expected). write_src_file(Dir, Name) -> - Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]), + Erl = filename:join([Dir, "src", Name]), ok = filelib:ensure_dir(Erl), - ok = ec_file:write(Erl, erl_src_file("not_a_real_src_" ++ Name ++ ".erl")). + ok = ec_file:write(Erl, erl_src_file(Name)). write_eunitized_src_file(Dir, Name) -> Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]), diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl index 1dc0af2..79cf29e 100644 --- a/test/rebar_upgrade_SUITE.erl +++ b/test/rebar_upgrade_SUITE.erl @@ -3,14 +3,14 @@ -include_lib("eunit/include/eunit.hrl"). -compile(export_all). -all() -> [{group, git}, {group, pkg}]. +all() -> [{group, git}, {group, pkg}, novsn_pkg]. 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, - delete_d, promote]}, + delete_d, promote, stable_lock, fwd_lock]}, {git, [], [{group, all}]}, {pkg, [], [{group, all}]}]. @@ -31,6 +31,26 @@ init_per_group(_, Config) -> end_per_group(_, Config) -> Config. +init_per_testcase(novsn_pkg, Config0) -> + Config = rebar_test_utils:init_rebar_state(Config0, "novsn_pkg_"), + AppDir = ?config(apps, Config), + RebarConf = rebar_test_utils:create_config(AppDir, [{deps, [fakeapp]}]), + + Deps = [{{<<"fakeapp">>, <<"1.0.0">>}, []}], + UpDeps = [{{<<"fakeapp">>, <<"1.1.0">>}, []}], + Upgrades = ["fakeapp"], + + [{rebarconfig, RebarConf}, + {mock, fun() -> + catch mock_pkg_resource:unmock(), + mock_pkg_resource:mock([{pkgdeps, Deps}, {upgrade, []}]) + end}, + {mock_update, fun() -> + catch mock_pkg_resource:unmock(), + mock_pkg_resource:mock([{pkgdeps, UpDeps}, {upgrade, Upgrades}]) + end}, + {expected, {ok, [{dep, "fakeapp", "1.1.0"}, {lock, "fakeapp", "1.1.0"}]}} + | Config]; init_per_testcase(Case, Config) -> DepsType = ?config(deps_type, Config), {Deps, UpDeps, ToUp, Expectations} = upgrades(Case), @@ -361,7 +381,30 @@ upgrades(promote) -> {"C", "3", []} ], ["A","B","C","D"], - {"C", [{"A","1"},{"C","3"},{"B","1"},{"D","1"}]}}. + {"C", [{"A","1"},{"C","3"},{"B","1"},{"D","1"}]}}; +upgrades(stable_lock) -> + {[{"A", "1", [{"C", "1", []}]}, + {"B", "1", [{"D", "1", []}]} + ], % lock after this + [{"A", "2", [{"C", "2", []}]}, + {"B", "2", [{"D", "2", []}]} + ], + [], + %% Run a regular lock and no app should be upgraded + {"any", [{"A","1"},{"C","1"},{"B","1"},{"D","1"}]}}; +upgrades(fwd_lock) -> + {[{"A", "1", [{"C", "1", []}]}, + {"B", "1", [{"D", "1", []}]} + ], + [{"A", "2", [{"C", "2", []}]}, + {"B", "2", [{"D", "2", []}]} + ], + ["A","B","C","D"], + %% For this one, we should build, rewrite the lock + %% file to include the result post-upgrade, and then + %% run a regular lock to see that the lock file is respected + %% in deps. + {"any", [{"A","2"},{"C","2"},{"B","2"},{"D","2"}]}}. %% TODO: add a test that verifies that unlocking files and then %% running the upgrade code is enough to properly upgrade things. @@ -435,6 +478,46 @@ delete_d(Config) -> ?assertNotEqual([], [1 || {"App ~ts is no longer needed and can be deleted.", [<<"D">>]} <- Infos]). + +stable_lock(Config) -> + apply(?config(mock, Config), []), + {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), + %% Install dependencies before re-mocking for an upgrade + rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}), + {App, Unlocks} = ?config(expected, Config), + ct:pal("Upgrades: ~p -> ~p", [App, Unlocks]), + Expectation = case Unlocks of + {error, Term} -> {error, Term}; + _ -> {ok, Unlocks} + end, + apply(?config(mock_update, Config), []), + 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, ["lock", App], Expectation + ). + +fwd_lock(Config) -> + apply(?config(mock, Config), []), + {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), + %% Install dependencies before re-mocking for an upgrade + rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}), + {App, Unlocks} = ?config(expected, Config), + ct:pal("Upgrades: ~p -> ~p", [App, Unlocks]), + Expectation = case Unlocks of + {error, Term} -> {error, Term}; + _ -> {ok, Unlocks} + end, + rewrite_locks(Expectation, Config), + apply(?config(mock_update, Config), []), + 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, ["lock", App], Expectation + ). + run(Config) -> apply(?config(mock, Config), []), {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), @@ -453,3 +536,32 @@ run(Config) -> rebar_test_utils:run_and_check( Config, NewRebarConfig, ["upgrade", App], Expectation ). + +novsn_pkg(Config) -> + apply(?config(mock, Config), []), + {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), + %% Install dependencies before re-mocking for an upgrade + rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}), + Expectation = ?config(expected, Config), + apply(?config(mock_update, Config), []), + rebar_test_utils:run_and_check( + Config, RebarConfig, ["upgrade"], Expectation + ), + ok. + +rewrite_locks({ok, Expectations}, Config) -> + AppDir = ?config(apps, Config), + LockFile = filename:join([AppDir, "rebar.lock"]), + {ok, [Locks]} = file:consult(LockFile), + ExpLocks = [{list_to_binary(Name), Vsn} + || {lock, Name, Vsn} <- Expectations], + NewLocks = lists:foldl( + fun({App, {pkg, Name, _}, Lvl}, Acc) -> + Vsn = list_to_binary(proplists:get_value(App,ExpLocks)), + [{App, {pkg, Name, Vsn}, Lvl} | Acc] + ; ({App, {git, URL, {ref, _}}, Lvl}, Acc) -> + Vsn = proplists:get_value(App,ExpLocks), + [{App, {git, URL, {ref, Vsn}}, Lvl} | Acc] + end, [], Locks), + ct:pal("rewriting locks from ~p to~n~p", [Locks, NewLocks]), + file:write_file(LockFile, io_lib:format("~p.~n", [NewLocks])). diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index e9b32e2..f04ab63 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -21,7 +21,8 @@ task_with_flag_with_trailing_comma/1, task_with_flag_with_commas/1, task_with_multiple_flags/1, - special_task_do/1]). + special_task_do/1, + sh_does_not_miss_messages/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -29,7 +30,8 @@ all() -> - [{group, args_to_tasks}]. + [{group, args_to_tasks}, + sh_does_not_miss_messages]. groups() -> [{args_to_tasks, [], [empty_arglist, @@ -118,3 +120,14 @@ special_task_do(_Config) -> "do", "bar,", "baz"]). +sh_does_not_miss_messages(_Config) -> + Source = "~nmain(_) ->~n io:format(\"donotmissme\").~n", + file:write_file("do_not_miss_messages", io_lib:format(Source,[])), + {ok, "donotmissme"} = rebar_utils:sh("escript do_not_miss_messages", []), + AnyMessageRemained = + receive + What -> What + after 100 -> + false + end, + AnyMessageRemained = false. |