diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/rebar_compile_SUITE.erl | 57 | ||||
| -rw-r--r-- | test/rebar_dir_SUITE.erl | 99 | ||||
| -rw-r--r-- | test/rebar_test_utils.erl | 17 | 
3 files changed, 170 insertions, 3 deletions
| diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index bdab075..2dc57c5 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -19,6 +19,7 @@           delete_beam_if_source_deleted/1,           checkout_priority/1,           compile_plugins/1, +         compile_global_plugins/1,           highest_version_of_pkg_dep/1,           parse_transform_test/1]). @@ -47,8 +48,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, compile_plugins, compile_global_plugins, +     highest_version_of_pkg_dep, parse_transform_test].  build_basic_app(Config) ->      AppDir = ?config(apps, Config), @@ -427,6 +428,58 @@ compile_plugins(Config) ->          {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). +  highest_version_of_pkg_dep(Config) ->      AppDir = ?config(apps, Config), 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_test_utils.erl b/test/rebar_test_utils.erl index 2cdc58b..c4dc663 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -160,6 +160,7 @@ 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)), @@ -176,6 +177,8 @@ 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}) -> @@ -224,7 +227,19 @@ check_results(AppDir, Expected) ->                  ct:pal("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("Name: ~p", [Name]), +                ?assertNotEqual(false, lists:keyfind(Name, 1, GlobalPluginsNames)) +        ;  ({global_plugin, Name, Vsn}) -> +                ct:pal("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))) | 
