diff options
-rw-r--r-- | test/mock_git_resource.erl | 3 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 36 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 15 |
3 files changed, 51 insertions, 3 deletions
diff --git a/test/mock_git_resource.erl b/test/mock_git_resource.erl index 9c799fd..d8f747b 100644 --- a/test/mock_git_resource.erl +++ b/test/mock_git_resource.erl @@ -99,6 +99,7 @@ mock_vsn(Opts) -> %% into a `rebar.config' file to describe dependencies. mock_download(Opts) -> Deps = proplists:get_value(deps, Opts, []), + Config = proplists:get_value(config, Opts, []), Default = proplists:get_value(default_vsn, Opts, "0.0.0"), Overrides = proplists:get_value(override_vsn, Opts, []), meck:expect( @@ -112,7 +113,7 @@ mock_download(Opts) -> Dir, App, 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), {ok, 'WHATEVER'} end). diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 8564754..ede1a52 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -15,7 +15,8 @@ dont_recompile_when_opts_dont_change/1, dont_recompile_yrl_or_xrl/1, deps_in_path/1, - checkout_priority/1]). + checkout_priority/1, + compile_plugins/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -41,7 +42,7 @@ all() -> build_checkout_apps, build_checkout_deps, build_all_srcdirs, recompile_when_opts_change, dont_recompile_when_opts_dont_change, - dont_recompile_yrl_or_xrl, deps_in_path, checkout_priority]. + dont_recompile_yrl_or_xrl, deps_in_path, checkout_priority, compile_plugins]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -332,3 +333,34 @@ 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), + PluginsDir = filename:join([?config(base_dir, Config), "default", "plugins"]), + + 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}]} + ). diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 2eb14ac..d245c82 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -158,6 +158,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"])), CheckoutsDir = filename:join([AppDir, "_checkouts"]), LockFile = filename:join([AppDir, "rebar.lock"]), Locks = lists:flatten(rebar_config:consult_file(LockFile)), @@ -172,6 +173,8 @@ check_results(AppDir, Expected) -> DepsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Deps], Checkouts = rebar_app_discover:find_apps([CheckoutsDir], all), 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], lists:foreach( fun({app, Name}) -> @@ -213,6 +216,18 @@ check_results(AppDir, Expected) -> ?assertEqual(iolist_to_binary(Vsn), iolist_to_binary(rebar_app_info:original_vsn(App))) end + ; ({plugin, Name}) -> + ct:pal("Name: ~p", [Name]), + ?assertNotEqual(false, lists:keyfind(Name, 1, PluginsNames)) + ; ({plugin, Name, Vsn}) -> + ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]), + case lists:keyfind(Name, 1, PluginsNames) of + false -> + error({dep_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]), ?assertNotEqual(false, lists:keyfind(iolist_to_binary(Name), 1, Locks)) |