diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rebar_deps_SUITE.erl | 34 | ||||
-rw-r--r-- | test/rebar_dialyzer_SUITE.erl | 73 | ||||
-rw-r--r-- | test/rebar_dir_SUITE.erl | 38 | ||||
-rw-r--r-- | test/rebar_file_utils_SUITE.erl | 24 | ||||
-rw-r--r-- | test/rebar_localfs_resource.erl | 38 |
5 files changed, 197 insertions, 10 deletions
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index fd86226..fcc46c3 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -3,7 +3,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [sub_app_deps, newly_added_dep, http_proxy_settings, https_proxy_settings, {group, git}, {group, pkg}]. +all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, {group, git}, {group, pkg}]. groups() -> [{all, [], [flat, pick_highest_left, pick_highest_right, @@ -29,6 +29,8 @@ init_per_group(_, Config) -> end_per_group(_, Config) -> Config. +init_per_testcase(newly_added_after_empty_lock, Config) -> + rebar_test_utils:init_rebar_state(Config); init_per_testcase(newly_added_dep, Config) -> rebar_test_utils:init_rebar_state(Config); init_per_testcase(sub_app_deps, Config) -> @@ -252,6 +254,36 @@ newly_added_dep(Config) -> Config, RebarConfig3, ["compile"], {ok, [{app, Name}, {dep, "a"}, {dep, "b", "1.0.0"}, {dep, "c", "1.0.0"}]}). +newly_added_after_empty_lock(Config) -> + AppDir = ?config(apps, Config), + Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}]), + {SrcDeps, _} = rebar_test_utils:flat_deps(Deps), + mock_git_resource:mock([{deps, SrcDeps}]), + + Name = rebar_test_utils:create_random_name("app_"), + Vsn = rebar_test_utils:create_random_vsn(), + + SubAppsDir = filename:join([AppDir, "apps", Name]), + rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]), + + TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [])), + {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])), + rebar_test_utils:run_and_check( + Config, RebarConfig, ["compile"], + {ok, []}), + + %% Add a and c to top level + TopDeps2 = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}])), + {ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])), + LockFile = filename:join(AppDir, "rebar.lock"), + RebarConfig3 = rebar_config:merge_locks(RebarConfig2, + rebar_config:consult_lock_file(LockFile)), + + %% a should now be installed and c should not change + rebar_test_utils:run_and_check( + Config, RebarConfig3, ["compile"], + {ok, [{app, Name}, {dep, "a", "1.0.0"}]}). + http_proxy_settings(_Config) -> %% Load config diff --git a/test/rebar_dialyzer_SUITE.erl b/test/rebar_dialyzer_SUITE.erl index 3158e8f..31e02d9 100644 --- a/test/rebar_dialyzer_SUITE.erl +++ b/test/rebar_dialyzer_SUITE.erl @@ -7,7 +7,8 @@ all/0, update_base_plt/1, update_app_plt/1, - build_release_plt/1]). + build_release_plt/1, + plt_apps_option/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -38,7 +39,7 @@ init_per_testcase(Testcase, Config) -> rebar_test_utils:init_rebar_state(Config)]. all() -> - [update_base_plt, update_app_plt, build_release_plt]. + [update_base_plt, update_app_plt, build_release_plt, plt_apps_option]. update_base_plt(Config) -> AppDir = ?config(apps, Config), @@ -130,6 +131,58 @@ build_release_plt(Config) -> {ok, PltFiles} = plt_files(Plt), ?assertEqual(ErtsFiles, PltFiles). +plt_apps_option(Config) -> + AppDir = ?config(apps, Config), + RebarConfig = ?config(rebar_config, Config), + Plt = ?config(plt, Config), + State = ?config(state, Config), + + %% Create applications + Name1 = rebar_test_utils:create_random_name("app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([AppDir,"deps",Name1]), Name1, Vsn1, + []), + App1 = ec_cnv:to_atom(Name1), + + Name2 = rebar_test_utils:create_random_name("app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([AppDir,"deps",Name2]), Name2, Vsn2, + [App1]), % App2 depends on App1 + App2 = ec_cnv:to_atom(Name2), + + Name3 = rebar_test_utils:create_random_name("app3_"), % the project application + Vsn3 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name3, Vsn3, + [App2]), % App3 depends on App2 + + %% Dependencies settings + State1 = rebar_state:add_resource(State, {localfs, rebar_localfs_resource}), + Config1 = [{state, State1} | Config], + RebarConfig1 = merge_config( + [{deps, + [ + {App1, {localfs, filename:join([AppDir,"deps",Name1])}}, + {App2, {localfs, filename:join([AppDir,"deps",Name2])}} + ]}], + RebarConfig), + + %% Dialyzer: plt_apps = top_level_deps (default) + rebar_test_utils:run_and_check(Config1, RebarConfig1, ["dialyzer"], + {ok, [{app, Name3}]}), + + %% NOTE: `erts` is included in `base_plt_apps` + {ok, PltFiles1} = plt_files(Plt), + ?assertEqual([App2, erts], get_apps_from_beam_files(PltFiles1)), + + %% Dialyzer: plt_apps = all_deps + RebarConfig2 = merge_config([{dialyzer, [{plt_apps, all_deps}]}], + RebarConfig1), + rebar_test_utils:run_and_check(Config1, RebarConfig2, ["dialyzer"], + {ok, [{app, Name3}]}), + + {ok, PltFiles2} = plt_files(Plt), + ?assertEqual([App1, App2, erts], get_apps_from_beam_files(PltFiles2)). + %% Helpers erts_files() -> @@ -157,3 +210,19 @@ alter_plt(Plt) -> {init_plt, Plt}, {files, [code:which(dialyzer)]}]), ok. + +-spec merge_config(Config, Config) -> Config when + Config :: [{term(), term()}]. +merge_config(NewConfig, OldConfig) -> + dict:to_list( + rebar_opts:merge_opts(dict:from_list(NewConfig), + dict:from_list(OldConfig))). + +-spec get_apps_from_beam_files(string()) -> [atom()]. +get_apps_from_beam_files(BeamFiles) -> + lists:usort( + [begin + AppNameVsn = filename:basename(filename:dirname(filename:dirname(File))), + [AppName | _] = string:tokens(AppNameVsn ++ "-", "-"), + ec_cnv:to_atom(AppName) + end || File <- BeamFiles]). diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 6fbc081..a9e44db 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -5,6 +5,7 @@ -export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]). -export([src_dirs/1, extra_src_dirs/1, all_src_dirs/1]). -export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]). +-export([retarget_path/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -13,16 +14,22 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs, src_dirs, extra_src_dirs, all_src_dirs, - profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs]. + profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs, + retarget_path]. init_per_testcase(_, Config) -> C = rebar_test_utils:init_rebar_state(Config), AppDir = ?config(apps, C), - Name = rebar_test_utils:create_random_name("app1_"), - Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), - C. + Name1 = rebar_test_utils:create_random_name("app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([AppDir,"apps",Name1]), Name1, Vsn1, [kernel, stdlib]), + + Name2 = rebar_test_utils:create_random_name("app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]), + + [{app_one, Name1}, {app_two, Name2}] ++ C. end_per_testcase(_, _Config) -> ok. @@ -97,3 +104,24 @@ profile_all_src_dirs(Config) -> R = lists:sort(["foo", "bar", "baz", "qux"]), R = lists:sort(rebar_dir:all_src_dirs(rebar_state:opts(State))). + +retarget_path(Config) -> + {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), + + BaseDir = rebar_dir:base_dir(State), + + Name1 = ?config(app_one, Config), + Name2 = ?config(app_two, Config), + + ?assertEqual(filename:join([BaseDir, "lib", Name1, "test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name1, "test"]))), + ?assertEqual(filename:join([BaseDir, "lib", Name2, "test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name2, "test"]))), + ?assertEqual(filename:join([BaseDir, "lib", Name1, "more_test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "apps", Name1, "more_test"]))), + ?assertEqual(filename:join([BaseDir, "test"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "test"]))), + ?assertEqual(filename:join([BaseDir, "some_other_dir"]), + rebar_dir:retarget_path(State, filename:join([rebar_dir:root_dir(State), "some_other_dir"]))), + ?assertEqual("/somewhere/outside/the/project", + rebar_dir:retarget_path(State, "/somewhere/outside/the/project")).
\ No newline at end of file diff --git a/test/rebar_file_utils_SUITE.erl b/test/rebar_file_utils_SUITE.erl index 03a2d54..0f444d5 100644 --- a/test/rebar_file_utils_SUITE.erl +++ b/test/rebar_file_utils_SUITE.erl @@ -10,7 +10,9 @@ multi_tmpdir/1, reset_nonexistent_dir/1, reset_empty_dir/1, - reset_dir/1]). + reset_dir/1, + path_from_ancestor/1, + canonical_path/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -19,7 +21,8 @@ all() -> [{group, tmpdir}, - {group, reset_dir}]. + {group, reset_dir}, + path_from_ancestor, canonical_path]. groups() -> [{tmpdir, [], [raw_tmpdir, empty_tmpdir, simple_tmpdir, multi_tmpdir]}, @@ -84,3 +87,20 @@ reset_dir(Config) -> ok = rebar_file_utils:reset_dir(TmpDir), ?assert(filelib:is_dir(TmpDir)), {ok, []} = file:list_dir(TmpDir). + +path_from_ancestor(_Config) -> + ?assertEqual({ok, "foo/bar/baz"}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/")), + ?assertEqual({ok, "bar/baz"}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/foo")), + ?assertEqual({ok, "bar"}, rebar_file_utils:path_from_ancestor("foo/bar", "foo")), + ?assertEqual({ok, "bar"}, rebar_file_utils:path_from_ancestor("foo/bar/", "foo/")), + ?assertEqual({error, badparent}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/qux")), + ?assertEqual({error, badparent}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/foo/bar/baz/qux")). + +canonical_path(_Config) -> + ?assertEqual("/", rebar_file_utils:canonical_path("/")), + ?assertEqual("/", rebar_file_utils:canonical_path("/../../..")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/bar/..")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/../foo")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/.")), + ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/./.")), + ?assertEqual("/foo/bar", rebar_file_utils:canonical_path("/foo/./bar")).
\ No newline at end of file diff --git a/test/rebar_localfs_resource.erl b/test/rebar_localfs_resource.erl new file mode 100644 index 0000000..d60421e --- /dev/null +++ b/test/rebar_localfs_resource.erl @@ -0,0 +1,38 @@ +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et +%% +%% @doc A localfs custom resource (for testing purposes only) +%% +%% ``` +%% {deps, [ +%% %% Application files are copied from "/path/to/app_name" +%% {app_name, {localfs, "/path/to/app_name", undefined}} +%% ]}. +%% ''' +-module(rebar_localfs_resource). + +-behaviour(rebar_resource). + +-export([lock/2 + ,download/3 + ,needs_update/2 + ,make_vsn/1]). + +-include_lib("eunit/include/eunit.hrl"). + +lock(AppDir, {localfs, Path, _Ref}) -> + lock(AppDir, {localfs, Path}); +lock(_AppDir, {localfs, Path}) -> + {localfs, Path, undefined}. + +needs_update(_AppDir, _Resource) -> + false. + +download(AppDir, {localfs, Path, _Ref}, State) -> + download(AppDir, {localfs, Path}, State); +download(AppDir, {localfs, Path}, _State) -> + ok = rebar_file_utils:cp_r(filelib:wildcard(Path ++ "/*"), AppDir), + {ok, undefined}. + +make_vsn(_AppDir) -> + {plain, "undefined"}. |