diff options
Diffstat (limited to 'test')
28 files changed, 935 insertions, 63 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl index a94fe2f..f837713 100644 --- a/test/mock_pkg_resource.erl +++ b/test/mock_pkg_resource.erl @@ -22,8 +22,9 @@ mock() -> mock([]). | {not_in_index, [{App, Vsn}]} | {pkgdeps, [{{App,Vsn}, [Dep]}]}, App :: string(), - Dep :: {App, string(), {pkg, App, Vsn}}, - Vsn :: string(). + Dep :: {App, string(), {pkg, App, Vsn, Hash}}, + Vsn :: string(), + Hash :: string() | undefined. mock(Opts) -> meck:new(?MOD, [no_link]), mock_lock(Opts), @@ -51,7 +52,7 @@ mock_update(Opts) -> ToUpdate = proplists:get_value(upgrade, Opts, []), meck:expect( ?MOD, needs_update, - fun(_Dir, {pkg, App, _Vsn}) -> + fun(_Dir, {pkg, App, _Vsn, _Hash}) -> lists:member(binary_to_list(App), ToUpdate) end). @@ -66,7 +67,7 @@ mock_vsn(_Opts) -> %% @doc For each app to download, create a dummy app on disk instead. %% The configuration for this one (passed in from `mock/1') includes: %% -%% - Specify a version with `{pkg, _, Vsn}' +%% - Specify a version with `{pkg, _, Vsn, _}' %% - Dependencies for each application must be passed of the form: %% `{pkgdeps, [{"app1", [{app2, ".*", {pkg, ...}}]}]}' -- basically %% the `pkgdeps' option takes a key/value list of terms to output directly @@ -76,7 +77,7 @@ mock_download(Opts) -> Config = proplists:get_value(config, Opts, []), meck:expect( ?MOD, download, - fun (Dir, {pkg, AppBin, Vsn}, _) -> + fun (Dir, {pkg, AppBin, Vsn, _}, _) -> App = binary_to_list(AppBin), filelib:ensure_dir(Dir), AppDeps = proplists:get_value({App,Vsn}, Deps, []), diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 76a3de5..d9b75e4 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -23,6 +23,7 @@ paths_extra_dirs_in_project_root/1, clean_extra_dirs_in_project_root/1, recompile_when_hrl_changes/1, + recompile_when_included_hrl_changes/1, recompile_when_opts_change/1, dont_recompile_when_opts_dont_change/1, dont_recompile_yrl_or_xrl/1, @@ -40,7 +41,8 @@ profile_override_deps/1, deps_build_in_prod/1, include_file_relative_to_working_directory/1, - include_file_in_src/1]). + include_file_in_src/1, + always_recompile_when_erl_compiler_options_set/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -55,14 +57,19 @@ all() -> {group, basic_srcdirs}, {group, release_srcdirs}, {group, unbalanced_srcdirs}, {group, basic_extras}, {group, release_extras}, {group, unbalanced_extras}, {group, root_extras}, - recompile_when_hrl_changes, recompile_when_opts_change, + recompile_when_hrl_changes, recompile_when_included_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, highest_version_of_pkg_dep, parse_transform_test, erl_first_files_test, mib_test, umbrella_mib_first_test, only_default_transitive_deps, clean_all, override_deps, profile_override_deps, deps_build_in_prod, - include_file_relative_to_working_directory, include_file_in_src]. + include_file_relative_to_working_directory, include_file_in_src] ++ + case erlang:function_exported(os, unsetenv, 1) of + true -> [always_recompile_when_erl_compiler_options_set]; + false -> [] + end. groups() -> [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]}, @@ -642,7 +649,6 @@ recompile_when_hrl_changes(Config) -> Vsn = rebar_test_utils:create_random_vsn(), rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), - ExtraSrc = <<"-module(test_header_include).\n" "-export([main/0]).\n" "-include(\"test_header_include.hrl\").\n" @@ -660,10 +666,48 @@ recompile_when_hrl_changes(Config) -> ModTime = [filelib:last_modified(filename:join([EbinDir, F])) || F <- Files, filename:extension(F) == ".beam"], + timer:sleep(1000), + + NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>, + ok = file:write_file(HeaderFile, NewExtraHeader), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + {ok, NewFiles} = rebar_utils:list_dir(EbinDir), + NewModTime = [filelib:last_modified(filename:join([EbinDir, F])) + || F <- NewFiles, filename:extension(F) == ".beam"], + + ?assert(ModTime =/= NewModTime). + +recompile_when_included_hrl_changes(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]), + + ExtraSrc = <<"-module(test_header_include).\n" + "-export([main/0]).\n" + "-include(\"test_header_include.hrl\").\n" + "main() -> ?SOME_DEFINE.\n">>, + + ExtraHeader = <<"-define(SOME_DEFINE, true).\n">>, + ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])), + HeaderFile = filename:join([AppDir, "include", "test_header_include.hrl"]), + ok = file:write_file(filename:join([AppDir, "src", "test_header_include.erl"]), ExtraSrc), + ok = file:write_file(HeaderFile, ExtraHeader), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), + {ok, Files} = rebar_utils:list_dir(EbinDir), + ModTime = [filelib:last_modified(filename:join([EbinDir, F])) + || F <- Files, filename:extension(F) == ".beam"], timer:sleep(1000), - rebar_file_utils:touch(HeaderFile), + NewExtraHeader = <<"-define(SOME_DEFINE, false).\n">>, + ok = file:write_file(HeaderFile, NewExtraHeader), rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), @@ -1265,3 +1309,44 @@ include_file_in_src(Config) -> rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}). + +always_recompile_when_erl_compiler_options_set(Config) -> + %% save existing env to restore after test + ExistingEnv = os:getenv("ERL_COMPILER_OPTIONS"), + + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("erl_compiler_options_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + true = os:unsetenv("ERL_COMPILER_OPTIONS"), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), + + {ok, Files} = rebar_utils:list_dir(EbinDir), + ModTime = [filelib:last_modified(filename:join([EbinDir, F])) + || F <- Files, filename:extension(F) == ".beam"], + + timer:sleep(1000), + + true = os:putenv("ERL_COMPILER_OPTIONS", "[{d, some_macro}]"), + + rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), + + {ok, NewFiles} = rebar_utils:list_dir(EbinDir), + NewModTime = [filelib:last_modified(filename:join([EbinDir, F])) + || F <- NewFiles, filename:extension(F) == ".beam"], + + ?assert(ModTime =/= NewModTime), + + %% restore existing env + case ExistingEnv of + false -> ok; + _ -> os:putenv("ERL_COMPILER_OPTIONS", ExistingEnv) + end. + + + diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl index 1da7571..c10875b 100644 --- a/test/rebar_ct_SUITE.erl +++ b/test/rebar_ct_SUITE.erl @@ -41,6 +41,7 @@ cmd_scale_timetraps/1, cmd_create_priv_dir/1, cmd_include_dir/1, + cmd_sys_config/1, cfg_opts/1, cfg_arbitrary_opts/1, cfg_test_spec/1, @@ -51,6 +52,7 @@ misspecified_ct_compile_opts/1, misspecified_ct_first_files/1]). +-include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). all() -> [{group, basic_app}, @@ -102,7 +104,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs, cmd_multiply_timetraps, cmd_scale_timetraps, cmd_create_priv_dir, - cmd_include_dir]}, + cmd_include_dir, + cmd_sys_config]}, {cover, [], [cover_compiled]}]. init_per_group(basic_app, Config) -> @@ -726,7 +729,7 @@ suite_at_app_root(Config) -> 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). + ["rebar_ct_SUITE_data","test","rebar","lib",_,"_build"|_] = lists:reverse(Parts). cmd_label(Config) -> State = ?config(result, Config), @@ -1020,7 +1023,41 @@ cmd_include_dir(Config) -> CompileOpts = proplists:get_value(options, Info), true = lists:member({i, "foo/bar/baz"}, CompileOpts), true = lists:member({i, "qux"}, CompileOpts). - + +cmd_sys_config(Config) -> + State = ?config(result, Config), + AppDir = ?config(apps, Config), + Name = ?config(name, Config), + AppName = list_to_atom(Name), + + {ok, _} = rebar_prv_common_test:prepare_tests(State), + ?assertEqual(undefined, application:get_env(AppName, key)), + + CfgFile = filename:join([AppDir, "config", "cfg_sys.config"]), + ok = filelib:ensure_dir(CfgFile), + ok = file:write_file(CfgFile, cfg_sys_config_file(AppName)), + RebarConfig = [{ct_opts, [{sys_config, CfgFile}]}], + {ok, State1} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "test", "lock"], return), + + {ok, _} = rebar_prv_common_test:prepare_tests(State1), + ?assertEqual({ok, cfg_value}, application:get_env(AppName, key)), + + Providers = rebar_state:providers(State1), + Namespace = rebar_state:namespace(State1), + CommandProvider = providers:get_provider(ct, Providers, Namespace), + GetOptSpec = providers:opts(CommandProvider), + + CmdFile = filename:join([AppDir, "config", "cmd_sys.config"]), + ok = filelib:ensure_dir(CmdFile), + ok = file:write_file(CmdFile, cmd_sys_config_file(AppName)), + {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--sys_config="++CmdFile]), + State2 = rebar_state:command_parsed_args(State1, GetOptResult), + + {ok, _} = rebar_prv_common_test:prepare_tests(State2), + + ?assertEqual({ok ,cmd_value}, application:get_env(AppName, key)). + + cfg_opts(Config) -> C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_opts_"), @@ -1181,10 +1218,15 @@ misspecified_ct_first_files(Config) -> {badconfig, {"Value `~p' of option `~p' must be a list", {some_file, ct_first_files}}} = Error. - %% helper for generating test data test_suite(Name) -> io_lib:format("-module(~ts_SUITE).\n" "-compile(export_all).\n" "all() -> [some_test].\n" "some_test(_) -> ok.\n", [Name]). + +cmd_sys_config_file(AppName) -> + io_lib:format("[{~s, [{key, cmd_value}]}].", [AppName]). + +cfg_sys_config_file(AppName) -> + io_lib:format("[{~s, [{key, cfg_value}]}].", [AppName]). diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index c95854a..24bf2a0 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -3,7 +3,11 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, semver_matching_lt, semver_matching_lte, semver_matching_gt, valid_version, {group, git}, {group, pkg}]. +all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, + http_proxy_settings, https_proxy_settings, + http_os_proxy_settings, https_os_proxy_settings, + semver_matching_lt, semver_matching_lte, semver_matching_gt, + valid_version, {group, git}, {group, pkg}]. groups() -> [{all, [], [flat, pick_highest_left, pick_highest_right, @@ -82,6 +86,47 @@ init_per_testcase(https_proxy_settings, Config) -> rebar_test_utils:create_config(GlobalConfigDir, [{https_proxy, "http://localhost:1234"} ]), + %% Add a bad value by default to show config overtakes default + os:putenv("https_proxy", "unparseable-garbage"), + rebar_test_utils:init_rebar_state(Config) + end; +init_per_testcase(http_os_proxy_settings, Config) -> + %% Create private rebar.config + Priv = ?config(priv_dir, Config), + GlobalDir = filename:join(Priv, "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), + + %% Insert proxy variables into os env, but not config + os:putenv("http_proxy", "http://localhost:1234"), + rebar_test_utils:create_config(GlobalConfigDir, []), + rebar_test_utils:init_rebar_state(Config); +init_per_testcase(https_os_proxy_settings, Config) -> + SupportsHttpsProxy = case erlang:system_info(otp_release) of + "R16"++_ -> true; + "R"++_ -> false; + _ -> true % 17 and up don't have a "R" in the version + end, + if not SupportsHttpsProxy -> + {skip, https_proxy_unsupported_before_R16}; + SupportsHttpsProxy -> + %% Create private rebar.config + Priv = ?config(priv_dir, Config), + GlobalDir = filename:join(Priv, "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), + + %% Insert proxy variables into os env, not in config + os:putenv("https_proxy", "http://localhost:1234"), + rebar_test_utils:create_config(GlobalConfigDir, []), rebar_test_utils:init_rebar_state(Config) end; init_per_testcase(Case, Config) -> @@ -97,11 +142,20 @@ init_per_testcase(Case, Config) -> | setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))]. end_per_testcase(https_proxy_settings, Config) -> + os:putenv("https_proxy", ""), meck:unload(rebar_dir), Config; end_per_testcase(http_proxy_settings, Config) -> meck:unload(rebar_dir), Config; +end_per_testcase(http_os_proxy_settings, Config) -> + os:putenv("http_proxy", ""), + meck:unload(rebar_dir), + Config; +end_per_testcase(https_os_proxy_settings, Config) -> + os:putenv("https_proxy", ""), + meck:unload(rebar_dir), + Config; end_per_testcase(_, Config) -> meck:unload(), Config. @@ -311,6 +365,23 @@ https_proxy_settings(_Config) -> ?assertEqual({ok,{{"localhost", 1234}, []}}, httpc:get_option(https_proxy, rebar)). +http_os_proxy_settings(_Config) -> + %% Load config + rebar_utils:set_httpc_options(), + rebar3:init_config(), + + %% Assert variable is right + ?assertEqual({ok,{{"localhost", 1234}, []}}, + httpc:get_option(proxy, rebar)). + +https_os_proxy_settings(_Config) -> + %% Load config + rebar_utils:set_httpc_options(), + rebar3:init_config(), + + %% Assert variable is right + ?assertEqual({ok,{{"localhost", 1234}, []}}, + httpc:get_option(https_proxy, rebar)). semver_matching_lt(_Config) -> Dep = <<"test">>, @@ -405,5 +476,5 @@ in_warnings(git, Warns, NameRaw, VsnRaw) -> in_warnings(pkg, Warns, NameRaw, VsnRaw) -> Name = iolist_to_binary(NameRaw), Vsn = iolist_to_binary(VsnRaw), - 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn}]} <- Warns, + 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn, _}]} <- Warns, AppName =:= Name, AppVsn =:= Vsn]). diff --git a/test/rebar_dialyzer_SUITE.erl b/test/rebar_dialyzer_SUITE.erl index 22a4894..e5d8c52 100644 --- a/test/rebar_dialyzer_SUITE.erl +++ b/test/rebar_dialyzer_SUITE.erl @@ -3,8 +3,14 @@ -export([suite/0, init_per_suite/1, end_per_suite/1, + init_per_group/2, + end_per_group/2, init_per_testcase/2, all/0, + groups/0, + empty_base_plt/1, + empty_app_plt/1, + empty_app_succ_typings/1, update_base_plt/1, update_app_plt/1, build_release_plt/1, @@ -23,6 +29,14 @@ init_per_suite(Config) -> end_per_suite(_Config) -> ok. +init_per_group(empty, Config) -> + [{base_plt_apps, []} | Config]; +init_per_group(_Group, Config) -> + [{base_plt_apps, [erts]} | Config]. + +end_per_group(_Group, _Config) -> + ok. + init_per_testcase(Testcase, Config) -> PrivDir = ?config(priv_dir, Config), Prefix = ec_cnv:to_list(Testcase), @@ -31,7 +45,7 @@ init_per_testcase(Testcase, Config) -> {plt_location, PrivDir}, {base_plt_prefix, BasePrefix}, {base_plt_location, PrivDir}, - {base_plt_apps, [erts]}], + {base_plt_apps, ?config(base_plt_apps, Config)}], Suffix = "_" ++ rebar_utils:otp_release() ++ "_plt", [{plt, filename:join(PrivDir, Prefix ++ Suffix)}, {base_plt, filename:join(PrivDir, BasePrefix ++ Suffix)}, @@ -39,7 +53,68 @@ init_per_testcase(Testcase, Config) -> rebar_test_utils:init_rebar_state(Config)]. all() -> - [update_base_plt, update_app_plt, build_release_plt, plt_apps_option]. + [{group, empty}, {group, build_and_check}, {group, update}]. + +groups() -> + [{empty, [empty_base_plt, empty_app_plt, empty_app_succ_typings]}, + {build_and_check, [build_release_plt, plt_apps_option]}, + {update, [update_base_plt, update_app_plt]}]. + +empty_base_plt(Config) -> + AppDir = ?config(apps, Config), + RebarConfig = ?config(rebar_config, Config), + BasePlt = ?config(base_plt, Config), + Plt = ?config(plt, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [erts]), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"], + {ok, [{app, Name}]}), + + {ok, BasePltFiles} = plt_files(BasePlt), + ?assertEqual([], BasePltFiles), + + ErtsFiles = erts_files(), + {ok, PltFiles} = plt_files(Plt), + ?assertEqual(ErtsFiles, PltFiles), + + ok. + +empty_app_plt(Config) -> + AppDir = ?config(apps, Config), + RebarConfig = ?config(rebar_config, Config), + BasePlt = ?config(base_plt, Config), + Plt = ?config(plt, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, []), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"], + {ok, [{app, Name}]}), + + {ok, BasePltFiles} = plt_files(BasePlt), + ?assertEqual([], BasePltFiles), + + {ok, PltFiles} = plt_files(Plt), + ?assertEqual([], PltFiles), + + ok. + +empty_app_succ_typings(Config) -> + AppDir = ?config(apps, Config), + RebarConfig = ?config(rebar_config, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_empty_app(AppDir, Name, Vsn, []), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"], + {ok, [{app, Name}]}), + + ok. update_base_plt(Config) -> AppDir = ?config(apps, Config), diff --git a/test/rebar_edoc_SUITE.erl b/test/rebar_edoc_SUITE.erl new file mode 100644 index 0000000..fded2b0 --- /dev/null +++ b/test/rebar_edoc_SUITE.erl @@ -0,0 +1,52 @@ +-module(rebar_edoc_SUITE). +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-compile(export_all). + +all() -> [multiapp]. + +init_per_testcase(multiapp, Config) -> + application:load(rebar), + DataDir = ?config(data_dir, Config), + PrivDir = ?config(priv_dir, Config), + Name = rebar_test_utils:create_random_name("multiapp"), + AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]), + ec_file:copy(filename:join([DataDir, "foo"]), AppsDir, [recursive]), + Verbosity = rebar3:log_level(), + rebar_log:init(command_line, Verbosity), + State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])} + ,{root_dir, AppsDir}]), + [{apps, AppsDir}, {state, State}, {name, Name} | Config]. + +end_per_testcase(_, Config) -> + Config. + +multiapp(Config) -> + %% With an empty config (no `dir'), links are being processed + RebarConfig = [], + rebar_test_utils:run_and_check(Config, RebarConfig, ["edoc"], {ok, []}), + %% validate that all doc entries are generated and links work + AppsDir = ?config(apps, Config), + ct:pal("AppsDir: ~s", [AppsDir]), + ?assert(file_content_matches( + filename:join([AppsDir, "apps", "bar1", "doc", "bar1.html"]), + "barer1")), + ?assert(file_content_matches( + filename:join([AppsDir, "apps", "bar2", "doc", "bar2.html"]), + "barer2")), + %% Links are in place for types + ?assert(file_content_matches( + filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]), + "barer1")), + ?assert(file_content_matches( + filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]), + "apps/bar1/doc/bar1.html")). + + +file_content_matches(Path, Regex) -> + case file:read_file(Path) of + {ok, Bin} -> + nomatch =/= re:run(Bin, Regex); + {error, Reason} -> + Reason + end. diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1.app.src b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1.app.src new file mode 100644 index 0000000..6e7ec24 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1.app.src @@ -0,0 +1,16 @@ +{application, bar1, + [{description, "An OTP application"}, + {vsn, "0.1.0"}, + {registered, []}, + {mod, { bar1_app, []}}, + {applications, + [kernel, + stdlib + ]}, + {env,[]}, + {modules, []}, + + {maintainers, []}, + {licenses, []}, + {links, []} + ]}. diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1.erl b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1.erl new file mode 100644 index 0000000..2700aef --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1.erl @@ -0,0 +1,9 @@ +-module(bar1).
+-export([bar1/0]).
+-export_type([barer1/0]).
+
+-type barer1() :: string().
+
+% @doc Bar1 bars the bar.
+-spec bar1() -> barer1().
+bar1() -> "Barer1".
\ No newline at end of file diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1_app.erl b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1_app.erl new file mode 100644 index 0000000..414ac30 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1_app.erl @@ -0,0 +1,26 @@ +%%%------------------------------------------------------------------- +%% @doc bar1 public API +%% @end +%%%------------------------------------------------------------------- + +-module(bar1_app). + +-behaviour(application). + +%% Application callbacks +-export([start/2, stop/1]). + +%%==================================================================== +%% API +%%==================================================================== + +start(_StartType, _StartArgs) -> + bar1_sup:start_link(). + +%%-------------------------------------------------------------------- +stop(_State) -> + ok. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1_sup.erl b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1_sup.erl new file mode 100644 index 0000000..f9d6670 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar1/src/bar1_sup.erl @@ -0,0 +1,35 @@ +%%%------------------------------------------------------------------- +%% @doc bar1 top level supervisor. +%% @end +%%%------------------------------------------------------------------- + +-module(bar1_sup). + +-behaviour(supervisor). + +%% API +-export([start_link/0]). + +%% Supervisor callbacks +-export([init/1]). + +-define(SERVER, ?MODULE). + +%%==================================================================== +%% API functions +%%==================================================================== + +start_link() -> + supervisor:start_link({local, ?SERVER}, ?MODULE, []). + +%%==================================================================== +%% Supervisor callbacks +%%==================================================================== + +%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules} +init([]) -> + {ok, { {one_for_all, 0, 1}, []} }. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2.app.src b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2.app.src new file mode 100644 index 0000000..58de8bc --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2.app.src @@ -0,0 +1,16 @@ +{application, bar2, + [{description, "An OTP application"}, + {vsn, "0.1.0"}, + {registered, []}, + {mod, { bar2_app, []}}, + {applications, + [kernel, + stdlib + ]}, + {env,[]}, + {modules, []}, + + {maintainers, []}, + {licenses, []}, + {links, []} + ]}. diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2.erl b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2.erl new file mode 100644 index 0000000..c639db0 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2.erl @@ -0,0 +1,9 @@ +-module(bar2).
+-export([bar2/0]).
+-export_type([barer2/0]).
+
+-type barer2() :: string().
+
+% @doc Bar2 bars the bar2.
+-spec bar2() -> barer2().
+bar2() -> "Barer2".
\ No newline at end of file diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2_app.erl b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2_app.erl new file mode 100644 index 0000000..d0058a0 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2_app.erl @@ -0,0 +1,26 @@ +%%%------------------------------------------------------------------- +%% @doc bar2 public API +%% @end +%%%------------------------------------------------------------------- + +-module(bar2_app). + +-behaviour(application). + +%% Application callbacks +-export([start/2, stop/1]). + +%%==================================================================== +%% API +%%==================================================================== + +start(_StartType, _StartArgs) -> + bar2_sup:start_link(). + +%%-------------------------------------------------------------------- +stop(_State) -> + ok. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2_sup.erl b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2_sup.erl new file mode 100644 index 0000000..0bdaf4a --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/bar2/src/bar2_sup.erl @@ -0,0 +1,35 @@ +%%%------------------------------------------------------------------- +%% @doc bar2 top level supervisor. +%% @end +%%%------------------------------------------------------------------- + +-module(bar2_sup). + +-behaviour(supervisor). + +%% API +-export([start_link/0]). + +%% Supervisor callbacks +-export([init/1]). + +-define(SERVER, ?MODULE). + +%%==================================================================== +%% API functions +%%==================================================================== + +start_link() -> + supervisor:start_link({local, ?SERVER}, ?MODULE, []). + +%%==================================================================== +%% Supervisor callbacks +%%==================================================================== + +%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules} +init([]) -> + {ok, { {one_for_all, 0, 1}, []} }. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo.app.src b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo.app.src new file mode 100644 index 0000000..9987fd5 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo.app.src @@ -0,0 +1,17 @@ +{application, foo, + [{description, "An OTP application"}, + {vsn, "0.1.0"}, + {registered, []}, + {mod, { foo_app, []}}, + {applications, + [kernel, + stdlib, + bar1, bar2 + ]}, + {env,[]}, + {modules, []}, + + {maintainers, []}, + {licenses, []}, + {links, []} + ]}. diff --git a/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo.erl b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo.erl new file mode 100644 index 0000000..52e3d0a --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo.erl @@ -0,0 +1,19 @@ +-module(foo).
+
+-export([foo/0, bar1/0, bar2/0]).
+
+-export_type([fooer/0]).
+
+-type fooer() :: string().
+
+% @doc Foo function returns fooer.
+-spec foo() -> fooer().
+foo() -> "fooer".
+
+% @doc Bar1 function returns barer1.
+-spec bar1() -> bar1:barer1().
+bar1() -> bar1:bar1().
+
+% @doc Bar2 functions returns barer2.
+-spec bar2() -> bar2:barer2().
+bar2() -> bar2:bar2().
\ No newline at end of file diff --git a/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo_app.erl b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo_app.erl new file mode 100644 index 0000000..d0158d7 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo_app.erl @@ -0,0 +1,26 @@ +%%%------------------------------------------------------------------- +%% @doc foo public API +%% @end +%%%------------------------------------------------------------------- + +-module(foo_app). + +-behaviour(application). + +%% Application callbacks +-export([start/2, stop/1]). + +%%==================================================================== +%% API +%%==================================================================== + +start(_StartType, _StartArgs) -> + foo_sup:start_link(). + +%%-------------------------------------------------------------------- +stop(_State) -> + ok. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo_sup.erl b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo_sup.erl new file mode 100644 index 0000000..67e88b4 --- /dev/null +++ b/test/rebar_edoc_SUITE_data/foo/apps/foo/src/foo_sup.erl @@ -0,0 +1,35 @@ +%%%------------------------------------------------------------------- +%% @doc foo top level supervisor. +%% @end +%%%------------------------------------------------------------------- + +-module(foo_sup). + +-behaviour(supervisor). + +%% API +-export([start_link/0]). + +%% Supervisor callbacks +-export([init/1]). + +-define(SERVER, ?MODULE). + +%%==================================================================== +%% API functions +%%==================================================================== + +start_link() -> + supervisor:start_link({local, ?SERVER}, ?MODULE, []). + +%%==================================================================== +%% Supervisor callbacks +%%==================================================================== + +%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules} +init([]) -> + {ok, { {one_for_all, 0, 1}, []} }. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/rebar_escriptize_SUITE.erl b/test/rebar_escriptize_SUITE.erl index 1817d6b..139d5cd 100644 --- a/test/rebar_escriptize_SUITE.erl +++ b/test/rebar_escriptize_SUITE.erl @@ -5,6 +5,8 @@ end_per_suite/1, init_per_testcase/2, all/0, + escriptize_with_name/1, + escriptize_with_bad_name/1, build_and_clean_app/1]). -include_lib("common_test/include/ct.hrl"). @@ -24,7 +26,11 @@ init_per_testcase(_, Config) -> rebar_test_utils:init_rebar_state(Config). all() -> - [build_and_clean_app]. + [ + build_and_clean_app, + escriptize_with_name, + escriptize_with_bad_name + ]. %% Test escriptize builds and runs the app's escript build_and_clean_app(Config) -> @@ -35,3 +41,21 @@ build_and_clean_app(Config) -> rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), rebar_test_utils:run_and_check(Config, [], ["escriptize"], {ok, [{app, Name, valid}]}). + +escriptize_with_name(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]), + rebar_test_utils:run_and_check(Config, [{escript_main_app, Name}], ["escriptize"], + {ok, [{app, Name, valid}]}). + +escriptize_with_bad_name(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]), + rebar_test_utils:run_and_check(Config, [{escript_main_app, boogers}], ["escriptize"], + {error,{rebar_prv_escriptize, {bad_name, boogers}}}). diff --git a/test/rebar_file_utils_SUITE.erl b/test/rebar_file_utils_SUITE.erl index c1f85b3..a44a06d 100644 --- a/test/rebar_file_utils_SUITE.erl +++ b/test/rebar_file_utils_SUITE.erl @@ -12,7 +12,9 @@ reset_empty_dir/1, reset_dir/1, path_from_ancestor/1, - canonical_path/1]). + canonical_path/1, + resolve_link/1, + split_dirname/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -22,7 +24,10 @@ all() -> [{group, tmpdir}, {group, reset_dir}, - path_from_ancestor, canonical_path]. + path_from_ancestor, + canonical_path, + resolve_link, + split_dirname]. groups() -> [{tmpdir, [], [raw_tmpdir, empty_tmpdir, simple_tmpdir, multi_tmpdir]}, @@ -111,3 +116,22 @@ canonical_path(_Config) -> ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/./.")), ?assertEqual(filename:nativename(Root ++ "foo/bar"), rebar_file_utils:canonical_path("/foo/./bar")). + +resolve_link(_Config) -> + TmpDir = rebar_file_utils:system_tmpdir( + ["rebar_file_utils_SUITE", "resolve_link"]), + Link = filename:join(TmpDir, "link"), + Target = filename:join(TmpDir, "link-target"), + ec_file:remove(TmpDir, [recursive]), + ok = filelib:ensure_dir(Target), + ok = file:write_file(Target, <<>>), + ok = file:make_symlink(Target, Link), + ?assertEqual(Target, rebar_file_utils:resolve_link(Link)). + +split_dirname(_Config) -> + ?assertEqual({".", ""}, rebar_file_utils:split_dirname("")), + ?assertEqual({"/", ""}, rebar_file_utils:split_dirname("/")), + ?assertEqual({"/", "foo"}, rebar_file_utils:split_dirname("/foo")), + ?assertEqual({".", "foo"}, rebar_file_utils:split_dirname("foo")), + ?assertEqual({"/foo", "bar"}, rebar_file_utils:split_dirname("/foo/bar")), + ?assertEqual({"foo", "bar"}, rebar_file_utils:split_dirname("foo/bar")). diff --git a/test/rebar_install_deps_SUITE.erl b/test/rebar_install_deps_SUITE.erl index b8b70b3..9ff28c7 100644 --- a/test/rebar_install_deps_SUITE.erl +++ b/test/rebar_install_deps_SUITE.erl @@ -475,5 +475,5 @@ in_warnings(git, Warns, NameRaw, VsnRaw) -> in_warnings(pkg, Warns, NameRaw, VsnRaw) -> Name = iolist_to_binary(NameRaw), Vsn = iolist_to_binary(VsnRaw), - 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn}]} <- Warns, + 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn, _}]} <- Warns, AppName =:= Name, AppVsn =:= Vsn]). diff --git a/test/rebar_lock_SUITE.erl b/test/rebar_lock_SUITE.erl index 00875f7..f1ab3b5 100644 --- a/test/rebar_lock_SUITE.erl +++ b/test/rebar_lock_SUITE.erl @@ -7,7 +7,8 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [current_version, future_versions_no_attrs, future_versions_attrs]. +all() -> [current_version, + beta_version, future_versions_no_attrs, future_versions_attrs]. current_version(Config) -> %% Current version just dumps the locks as is on disk. @@ -15,9 +16,60 @@ current_version(Config) -> Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}, + {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>},2}, + {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>},1} + ], + ExpandedNull = [ + {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,undefined},3}, + {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>,undefined},2}, + {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>,undefined},1} + ], + %% Simulate a beta lockfile + file:write_file(LockFile, io_lib:format("~p.~n", [Locks])), + %% No properties fetched from a beta lockfile, expand locks + %% to undefined + ?assertEqual(ExpandedNull, + rebar_config:consult_lock_file(LockFile)), + %% Adding hash data + Hashes = [{<<"pkg1">>, <<"tarballhash">>}, + {<<"pkg3">>, <<"otherhash">>}], + ExpandedLocks = [ + {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,<<"tarballhash">>},3}, + {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>,undefined},2}, + {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>,<<"otherhash">>},1} + ], + file:write_file(LockFile, + io_lib:format("~p.~n~p.~n", + [{"1.1.0", Locks}, + [{pkg_hash, Hashes}]])), + ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)), + %% Then check that we can reverse that + ok = rebar_config:write_lock_file(LockFile, ExpandedLocks), + ?assertEqual({ok, [{"1.1.0", Locks}, [{pkg_hash, Hashes}]]}, + file:consult(LockFile)). + +beta_version(Config) -> + %% Current version just dumps the locks as is on disk. + LockFile = filename:join(?config(priv_dir, Config), "current_version"), + Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}], + ExpandedLocks = [ + {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,undefined},3} + ], file:write_file(LockFile, io_lib:format("~p.~n", [Locks])), - ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)). + ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)). future_versions_no_attrs(Config) -> %% Future versions will keep the same core attribute in there, but @@ -27,10 +79,14 @@ future_versions_no_attrs(Config) -> Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, - {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}], + {<<"pkg1">>, {pkg,<<"name">>,<<"0.1.6">>},3}], + ExpandedLocks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>, {pkg,<<"name">>,<<"0.1.6">>,undefined},3}], LockData = {"3.5.2", Locks}, file:write_file(LockFile, io_lib:format("~p.~n", [LockData])), - ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)). + ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)). future_versions_attrs(Config) -> %% Future versions will keep the same core attribute in there, but @@ -41,6 +97,16 @@ future_versions_attrs(Config) -> {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}], + ExpandedLocks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2}, + {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0}, + {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1}, + {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>, <<"tarballhash">>},3}], + Hashes = [{<<"pkg1">>, <<"tarballhash">>}], LockData = {"3.5.2", Locks}, - file:write_file(LockFile, io_lib:format("~p.~na.~n{b,c}.~n[d,e,f].~n", [LockData])), - ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)). + file:write_file(LockFile, + io_lib:format("~p.~n~p.~ngarbage.~n", + [LockData, + [{a, x}, + {pkg_hash, Hashes}, + {b, y}]])), + ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)). diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl index 6a75f32..30cc0a8 100644 --- a/test/rebar_pkg_SUITE.erl +++ b/test/rebar_pkg_SUITE.erl @@ -11,6 +11,7 @@ -define(good_checksum, <<"1C6CE379D191FBAB41B7905075E0BF87CBBE23C77CECE775C5A0B786B2244C35">>). all() -> [good_uncached, good_cached, badindexchk, badpkg, + badhash_nocache, badhash_cache, bad_to_good, good_disconnect, bad_disconnect, pkgs_provider, find_highest_matching]. @@ -58,6 +59,19 @@ init_per_testcase(badpkg=Name, Config0) -> {pkg, {<<"badpkg">>, <<"1.0.0">>}} | Config0], mock_config(Name, Config); +init_per_testcase(badhash_nocache=Name, Config0) -> + Config = [{good_cache, false}, + {pkg, {<<"goodpkg">>, <<"1.0.0">>}} + | Config0], + mock_config(Name, Config); +init_per_testcase(badhash_cache=Name, Config0) -> + Pkg = {<<"goodpkg">>, <<"1.0.0">>}, + Config1 = [{good_cache, true}, + {pkg, Pkg} + | Config0], + Config = mock_config(Name, Config1), + copy_to_cache(Pkg, Config), + Config; init_per_testcase(bad_to_good=Name, Config0) -> Config1 = [{good_cache, false}, {pkg, {<<"goodpkg">>, <<"1.0.0">>}} @@ -103,7 +117,7 @@ good_uncached(Config) -> {Pkg,Vsn} = ?config(pkg, Config), State = ?config(state, Config), ?assertEqual({ok, true}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)), + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)), Cache = ?config(cache_dir, Config), ?assert(filelib:is_regular(filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>))). @@ -116,7 +130,7 @@ good_cached(Config) -> ?assert(filelib:is_regular(CachedFile)), {ok, Content} = file:read_file(CachedFile), ?assertEqual({ok, true}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)), + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)), {ok, Content} = file:read_file(CachedFile). badindexchk(Config) -> @@ -124,7 +138,7 @@ badindexchk(Config) -> {Pkg,Vsn} = ?config(pkg, Config), State = ?config(state, Config), ?assertMatch({bad_registry_checksum, _Path}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)), + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)), %% The cached file is there for forensic purposes Cache = ?config(cache_dir, Config), ?assert(filelib:is_regular(filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>))). @@ -134,11 +148,35 @@ badpkg(Config) -> {Pkg,Vsn} = ?config(pkg, Config), State = ?config(state, Config), ?assertMatch({bad_download, _Path}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)), + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)), %% The cached file is there for forensic purposes Cache = ?config(cache_dir, Config), ?assert(filelib:is_regular(filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>))). +badhash_nocache(Config) -> + Tmp = ?config(tmp_dir, Config), + {Pkg,Vsn} = ?config(pkg, Config), + State = ?config(state, Config), + ?assertMatch({unexpected_hash, _Path, ?bad_checksum, ?good_checksum}, + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?bad_checksum}, State)), + %% The cached file is there for forensic purposes + Cache = ?config(cache_dir, Config), + ?assert(filelib:is_regular(filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>))). + +badhash_cache(Config) -> + Tmp = ?config(tmp_dir, Config), + {Pkg,Vsn} = ?config(pkg, Config), + Cache = ?config(cache_dir, Config), + State = ?config(state, Config), + CachedFile = filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>), + ?assert(filelib:is_regular(CachedFile)), + {ok, Content} = file:read_file(CachedFile), + ?assertMatch({unexpected_hash, _Path, ?bad_checksum, ?good_checksum}, + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?bad_checksum}, State)), + %% The cached file is there still, unchanged. + ?assert(filelib:is_regular(CachedFile)), + ?assertEqual({ok, Content}, file:read_file(CachedFile)). + bad_to_good(Config) -> Tmp = ?config(tmp_dir, Config), {Pkg,Vsn} = ?config(pkg, Config), @@ -148,7 +186,7 @@ bad_to_good(Config) -> ?assert(filelib:is_regular(CachedFile)), {ok, Contents} = file:read_file(CachedFile), ?assertEqual({ok, true}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)), + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)), %% Cache has refreshed ?assert({ok, Contents} =/= file:read_file(CachedFile)). @@ -161,7 +199,7 @@ good_disconnect(Config) -> ?assert(filelib:is_regular(CachedFile)), {ok, Content} = file:read_file(CachedFile), ?assertEqual({ok, true}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)), + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)), {ok, Content} = file:read_file(CachedFile). bad_disconnect(Config) -> @@ -169,7 +207,7 @@ bad_disconnect(Config) -> {Pkg,Vsn} = ?config(pkg, Config), State = ?config(state, Config), ?assertEqual({fetch_fail, Pkg, Vsn}, - rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn}, State)). + rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?good_checksum}, State)). pkgs_provider(Config) -> Config1 = rebar_test_utils:init_rebar_state(Config), diff --git a/test/rebar_pkg_alias_SUITE.erl b/test/rebar_pkg_alias_SUITE.erl index fef2310..8915357 100644 --- a/test/rebar_pkg_alias_SUITE.erl +++ b/test/rebar_pkg_alias_SUITE.erl @@ -55,7 +55,7 @@ diff_alias(Config) -> Config, RebarConfig, ["lock"], {ok, [{lock, "fakelib"},{dep, "fakelib"}]} ), - {ok, [LockData]} = file:consult(Lockfile), + {ok, [{_Vsn, LockData}|_]} = file:consult(Lockfile), ?assert(lists:any(fun({<<"fakelib">>,{pkg,<<"goodpkg">>,_},_}) -> true ; (_) -> false end, LockData)), %% An second run yields the same @@ -63,13 +63,13 @@ diff_alias(Config) -> Config, RebarConfig, ["lock"], {ok, [{lock, "fakelib"},{dep, "fakelib"}]} ), - {ok, [LockData]} = file:consult(Lockfile), + {ok, [{_Vsn, LockData}|_]} = file:consult(Lockfile), %% So does an upgrade rebar_test_utils:run_and_check( Config, RebarConfig, ["upgrade"], {ok, [{lock, "fakelib"},{dep, "fakelib"}]} ), - {ok, [LockData]} = file:consult(Lockfile). + {ok, [{_Vsn, LockData}|_]} = file:consult(Lockfile). diff_alias_vsn(Config) -> diff_alias(Config). diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 23b0178..8c177c9 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -7,6 +7,13 @@ create_config/2, create_config/3, package_app/3]). -export([create_random_name/1, create_random_vsn/0, write_src_file/2]). +%% Pick the right random module +-ifdef(rand_only). +-define(random, rand). +-else. +-define(random, random). +-endif. + %%%%%%%%%%%%%% %%% Public %%% %%%%%%%%%%%%%% @@ -126,20 +133,24 @@ create_config(_AppDir, ConfFilename, Contents) -> %% @doc Util to create a random variation of a given name. create_random_name(Name) -> random_seed(), - Name ++ erlang:integer_to_list(random:uniform(1000000)). + Name ++ erlang:integer_to_list(?random:uniform(1000000)). %% @doc Util to create a random variation of a given version. create_random_vsn() -> 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))]). + lists:flatten([erlang:integer_to_list(?random:uniform(100)), + ".", erlang:integer_to_list(?random:uniform(100)), + ".", erlang:integer_to_list(?random:uniform(100))]). +-ifdef(rand_only). +random_seed() -> + %% the rand module self-seeds + ok. +-else. random_seed() -> <<A:32, B:32, C:32>> = crypto:rand_bytes(12), random:seed({A,B,C}). - - +-endif. expand_deps(_, []) -> []; expand_deps(git, [{Name, Deps} | Rest]) -> @@ -149,21 +160,21 @@ expand_deps(git, [{Name, Vsn, Deps} | Rest]) -> Dep = {Name, Vsn, {git, "https://example.org/user/"++Name++".git", {tag, Vsn}}}, [{Dep, expand_deps(git, Deps)} | expand_deps(git, Rest)]; expand_deps(pkg, [{Name, Deps} | Rest]) -> - Dep = {pkg, Name, "0.0.0"}, + Dep = {pkg, Name, "0.0.0", undefined}, [{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)]; expand_deps(pkg, [{Name, Vsn, Deps} | Rest]) -> - Dep = {pkg, Name, Vsn}, + Dep = {pkg, Name, Vsn, undefined}, [{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)]; expand_deps(mixed, [{Name, Deps} | Rest]) -> Dep = if hd(Name) >= $a, hd(Name) =< $z -> - {pkg, string:to_upper(Name), "0.0.0"} + {pkg, string:to_upper(Name), "0.0.0", undefined} ; hd(Name) >= $A, hd(Name) =< $Z -> {Name, ".*", {git, "https://example.org/user/"++Name++".git", "master"}} end, [{Dep, expand_deps(mixed, Deps)} | expand_deps(mixed, Rest)]; expand_deps(mixed, [{Name, Vsn, Deps} | Rest]) -> Dep = if hd(Name) >= $a, hd(Name) =< $z -> - {pkg, string:to_upper(Name), Vsn} + {pkg, string:to_upper(Name), Vsn, undefined} ; hd(Name) >= $A, hd(Name) =< $Z -> {Name, Vsn, {git, "https://example.org/user/"++Name++".git", {tag, Vsn}}} end, @@ -177,7 +188,7 @@ expand_deps(mixed, [{Name, Vsn, Deps} | Rest]) -> flat_deps(Deps) -> flat_deps(Deps, [], []). flat_deps([], Src, Pkg) -> {Src, Pkg}; -flat_deps([{{pkg, Name, Vsn}, PkgDeps} | Rest], Src, Pkg) -> +flat_deps([{{pkg, Name, Vsn, undefined}, PkgDeps} | Rest], Src, Pkg) -> Current = {{iolist_to_binary(Name), iolist_to_binary(Vsn)}, top_level_deps(PkgDeps)}, {[], FlatPkgDeps} = flat_deps(PkgDeps), @@ -195,7 +206,7 @@ vsn_from_ref({git, _, {_, Vsn}}) -> Vsn; vsn_from_ref({git, _, Vsn}) -> Vsn. top_level_deps([]) -> []; -top_level_deps([{{pkg, Name, Vsn}, _} | Deps]) -> +top_level_deps([{{pkg, Name, Vsn, undefined}, _} | Deps]) -> [{list_to_atom(Name), Vsn} | top_level_deps(Deps)]; top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) -> [{list_to_atom(Name), Vsn, Ref} | top_level_deps(Deps)]. @@ -306,9 +317,10 @@ check_results(AppDir, Expected, ProfileRun) -> case lists:keyfind(iolist_to_binary(Name), 1, Locks) of false -> error({lock_not_found, Name}); - {_LockName, {pkg, _, LockVsn}, _} -> + {_LockName, {pkg, _, LockVsn, Hash}, _} -> ?assertEqual(iolist_to_binary(Vsn), - iolist_to_binary(LockVsn)); + iolist_to_binary(LockVsn)), + ?assertNotEqual(undefined, Hash); {_LockName, {_, _, {ref, LockVsn}}, _} -> ?assertEqual(iolist_to_binary(Vsn), iolist_to_binary(LockVsn)) @@ -318,9 +330,10 @@ check_results(AppDir, Expected, ProfileRun) -> case lists:keyfind(iolist_to_binary(Name), 1, Locks) of false -> error({lock_not_found, Name}); - {_LockName, {pkg, _, LockVsn}, _} -> + {_LockName, {pkg, _, LockVsn, Hash}, _} -> ?assertEqual(iolist_to_binary(Vsn), - iolist_to_binary(LockVsn)); + iolist_to_binary(LockVsn)), + ?assertNotEqual(undefined, Hash); {_LockName, {_, _, {ref, LockVsn}}, _} -> error({source_lock, {Name, LockVsn}}) end @@ -329,7 +342,7 @@ check_results(AppDir, Expected, ProfileRun) -> case lists:keyfind(iolist_to_binary(Name), 1, Locks) of false -> error({lock_not_found, Name}); - {_LockName, {pkg, _, LockVsn}, _} -> + {_LockName, {pkg, _, LockVsn, _}, _} -> error({pkg_lock, {Name, LockVsn}}); {_LockName, {_, _, {ref, LockVsn}}, _} -> ?assertEqual(iolist_to_binary(Vsn), diff --git a/test/rebar_unlock_SUITE.erl b/test/rebar_unlock_SUITE.erl index 31dca72..8dbdb3a 100644 --- a/test/rebar_unlock_SUITE.erl +++ b/test/rebar_unlock_SUITE.erl @@ -3,8 +3,14 @@ -include_lib("eunit/include/eunit.hrl"). -compile(export_all). -all() -> [unlock, unlock_all]. +all() -> [pkgunlock, unlock, unlock_all]. +init_per_testcase(pkgunlock, Config0) -> + Config = rebar_test_utils:init_rebar_state(Config0, "pkgunlock"), + Lockfile = filename:join(?config(apps, Config), "rebar.lock"), + ec_file:copy(filename:join(?config(data_dir, Config), "pkg.rebar.lock"), + Lockfile), + [{lockfile, Lockfile} | Config]; init_per_testcase(Case, Config0) -> Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)), Lockfile = filename:join(?config(apps, Config), "rebar.lock"), @@ -15,6 +21,23 @@ init_per_testcase(Case, Config0) -> end_per_testcase(_, Config) -> Config. +pkgunlock(Config) -> + Locks = read_locks(Config), + Hashes = read_hashes(Config), + rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}), + Locks = read_locks(Config), + Hashes = read_hashes(Config), + rebar_test_utils:run_and_check(Config, [], ["unlock", "bbmustache"], {ok, []}), + ?assertEqual(Locks -- ["bbmustache"], read_locks(Config)), + ?assertEqual(Hashes -- ["bbmustache"], read_hashes(Config)), + rebar_test_utils:run_and_check(Config, [], ["unlock", "cf,certifi"], {ok, []}), + ?assertEqual(Locks -- ["bbmustache","cf","certifi"], read_locks(Config)), + ?assertEqual(Hashes -- ["bbmustache","cf","certifi"], read_hashes(Config)), + rebar_test_utils:run_and_check(Config, [], ["unlock", string:join(Locks,",")], {ok, []}), + ?assertEqual({error, enoent}, read_locks(Config)), + ?assertEqual({error, enoent}, read_hashes(Config)), + ok. + unlock(Config) -> Locks = read_locks(Config), rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}), @@ -35,6 +58,20 @@ unlock_all(Config) -> read_locks(Config) -> case file:consult(?config(lockfile, Config)) of - {ok, [Locks]} -> [binary_to_list(element(1,Lock)) || Lock <- Locks]; - Other -> Other + {ok, _} -> + Locks = rebar_config:consult_lock_file(?config(lockfile, Config)), + [binary_to_list(element(1,Lock)) || Lock <- Locks]; + Other -> + Other + end. + +read_hashes(Config) -> + case file:consult(?config(lockfile, Config)) of + {ok, [{_Vsn, _Locks},Props|_]} -> + Hashes = proplists:get_value(pkg_hash, Props, []), + [binary_to_list(element(1,Hash)) || Hash <- Hashes]; + {ok, [{_Vsn, _Locks}]} -> + []; + Other -> + Other end. diff --git a/test/rebar_unlock_SUITE_data/pkg.rebar.lock b/test/rebar_unlock_SUITE_data/pkg.rebar.lock new file mode 100644 index 0000000..231e266 --- /dev/null +++ b/test/rebar_unlock_SUITE_data/pkg.rebar.lock @@ -0,0 +1,24 @@ +{"1.1.0", +[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.0.4">>},0}, + {<<"certifi">>,{pkg,<<"certifi">>,<<"0.4.0">>},0}, + {<<"cf">>,{pkg,<<"cf">>,<<"0.2.1">>},0}, + {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.2.3">>},0}, + {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"0.21.0">>},0}, + {<<"eunit_formatters">>,{pkg,<<"eunit_formatters">>,<<"0.3.1">>},0}, + {<<"getopt">>,{pkg,<<"getopt">>,<<"0.8.2">>},0}, + {<<"providers">>,{pkg,<<"providers">>,<<"1.6.0">>},0}, + {<<"relx">>,{pkg,<<"relx">>,<<"3.20.0">>},0}, + {<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.1">>},0}]}. +[ +{pkg_hash,[ + {<<"bbmustache">>, <<"7BA94F971C5AFD7B6617918A4BB74705E36CAB36EB84B19B6A1B7EE06427AA38">>}, + {<<"certifi">>, <<"A7966EFB868B179023618D29A407548F70C52466BF1849B9E8EBD0E34B7EA11F">>}, + {<<"cf">>, <<"69D0B1349FD4D7D4DC55B7F407D29D7A840BF9A1EF5AF529F1EBE0CE153FC2AB">>}, + {<<"cth_readable">>, <<"293120673DFF82F0768612C5282E35C40CACC1B6F94FE99077438FD3749D0E27">>}, + {<<"erlware_commons">>, <<"A04433071AD7D112EDEFC75AC77719DD3E6753E697AC09428FC83D7564B80B15">>}, + {<<"eunit_formatters">>, <<"7A6FC351EB5B873E2356B8852EB751E20C13A72FBCA03393CF682B8483509573">>}, + {<<"getopt">>, <<"B17556DB683000BA50370B16C0619DF1337E7AF7ECBF7D64FBF8D1D6BCE3109B">>}, + {<<"providers">>, <<"DB0E2F9043AE60C0155205FCD238D68516331D0E5146155E33D1E79DC452964A">>}, + {<<"relx">>, <<"B515B8317D25B3A1508699294C3D1FA6DC0527851DFFC87446661BCE21A36710">>}, + {<<"ssl_verify_fun">>, <<"28A4D65B7F59893BC2C7DE786DEC1E1555BD742D336043FE644AE956C3497FBE">>}]} +]. diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl index cfe1d8a..66e1fdf 100644 --- a/test/rebar_upgrade_SUITE.erl +++ b/test/rebar_upgrade_SUITE.erl @@ -11,7 +11,7 @@ groups() -> triplet_a, triplet_b, triplet_c, tree_a, tree_b, tree_c, tree_c2, tree_cj, tree_ac, tree_all, delete_d, promote, stable_lock, fwd_lock, - compile_upgrade_parity]}, + compile_upgrade_parity, umbrella_config]}, {git, [], [{group, all}]}, {pkg, [], [{group, all}]}]. @@ -66,6 +66,18 @@ end_per_testcase(_, Config) -> meck:unload(), Config. +setup_project(Case=umbrella_config, Config0, Deps, UpDeps) -> + DepsType = ?config(deps_type, Config0), + NameRoot = atom_to_list(Case)++"_"++atom_to_list(DepsType), + Config = rebar_test_utils:init_rebar_state(Config0, NameRoot++"_"), + AppDir = filename:join([?config(apps, Config), "apps", NameRoot]), + rebar_test_utils:create_app(AppDir, "Root", "0.0.0", [kernel, stdlib]), + TopDeps = rebar_test_utils:top_level_deps(Deps), + TopConf = rebar_test_utils:create_config(AppDir, [{deps, []}]), + RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]), + [{rebarconfig, TopConf}, + {rebarumbrella, RebarConf}, + {next_top_deps, rebar_test_utils:top_level_deps(UpDeps)} | Config]; setup_project(Case, Config0, Deps, UpDeps) -> DepsType = ?config(deps_type, Config0), Config = rebar_test_utils:init_rebar_state( @@ -437,7 +449,12 @@ upgrades(compile_upgrade_parity) -> [], {"", [{"A","1"}, "D", "J", "E", {"I","1"}, {"B","1"}, "F", "G", - {"C","1"}, "H"]}}. + {"C","1"}, "H"]}}; +upgrades(umbrella_config) -> + {[{"A", "1", []}], + [{"A", "2", []}], + ["A"], + {"A", [{"A","2"}]}}. %% TODO: add a test that verifies that unlocking files and then %% running the upgrade code is enough to properly upgrade things. @@ -570,9 +587,36 @@ compile_upgrade_parity(Config) -> ?assertEqual(CompileLockData1, CompileLockData2), ?assertEqual(CompileLockData1, UpgradeLockData). +umbrella_config(Config) -> + apply(?config(mock, Config), []), + {ok, TopConfig} = file:consult(?config(rebarconfig, Config)), + %% Install dependencies before re-mocking for an upgrade + rebar_test_utils:run_and_check(Config, TopConfig, ["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, + + 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(filename:dirname(?config(rebarumbrella, Config)), + [{deps, ?config(next_top_deps, Config)}]), + %% re-run from the top-level with the old config still in place; + %% detection must happen when going for umbrella apps! + rebar_test_utils:run_and_check( + Config, TopConfig, ["upgrade", App], Expectation + ), + meck:unload(rebar_prv_upgrade). + run(Config) -> apply(?config(mock, Config), []), - {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), + ConfigPath = ?config(rebarconfig, Config), + {ok, RebarConfig} = file:consult(ConfigPath), %% Install dependencies before re-mocking for an upgrade rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}), {App, Unlocks} = ?config(expected, Config), @@ -587,7 +631,7 @@ run(Config) -> apply(?config(mock_update, Config), []), meck:passthrough([S]) end), - NewRebarConf = rebar_test_utils:create_config(?config(apps, Config), + NewRebarConf = rebar_test_utils:create_config(filename:dirname(ConfigPath), [{deps, ?config(next_top_deps, Config)}]), {ok, NewRebarConfig} = file:consult(NewRebarConf), rebar_test_utils:run_and_check( @@ -610,7 +654,14 @@ novsn_pkg(Config) -> rewrite_locks({ok, Expectations}, Config) -> AppDir = ?config(apps, Config), LockFile = filename:join([AppDir, "rebar.lock"]), - {ok, [Locks]} = file:consult(LockFile), + Locks = case ?config(deps_type, Config) of + git -> + {ok, [LockData]} = file:consult(LockFile), + LockData; + pkg -> + {ok, [{_Vsn, LockData}|_]} = file:consult(LockFile), + LockData + end, ExpLocks = [{list_to_binary(Name), Vsn} || {lock, Name, Vsn} <- Expectations], NewLocks = lists:foldl( |