From 00a183e3a882d68789917dc134754461ff8514d9 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 4 Apr 2015 13:37:20 -0500 Subject: test building of deps plugins --- test/mock_git_resource.erl | 3 ++- test/rebar_compile_SUITE.erl | 36 ++++++++++++++++++++++++++++++++++-- test/rebar_test_utils.erl | 15 +++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) (limited to 'test') 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)) -- cgit v1.1 From 38de29ae424ecc2dd0ccee4c1ee4bf3a5bb021da Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 4 Apr 2015 16:08:25 -0500 Subject: move resource modules list to rebar_state, no longer static --- test/rebar_resource_SUITE.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/rebar_resource_SUITE.erl b/test/rebar_resource_SUITE.erl index 95263c7..15f14db 100644 --- a/test/rebar_resource_SUITE.erl +++ b/test/rebar_resource_SUITE.erl @@ -12,7 +12,10 @@ groups() -> {hg, [], [{group, all}]}]. init_per_group(all, Config) -> - Config; + State = rebar_state:resources(rebar_state:new(), [{git, rebar_git_resource}, + {pkg, rebar_pkg_resource}, + {hg, rebar_hg_resource}]), + [{state, State} | Config]; init_per_group(Name, Config) -> [{type, Name}, {resource, {Name, "https://example.org/user/app", "vsn"}} | Config]. @@ -33,4 +36,5 @@ end_per_testcase(_, Config) -> change_type_upgrade(Config) -> ?assert(rebar_fetch:needs_update(?config(path, Config), - ?config(resource, Config))). + ?config(resource, Config), + ?config(state, Config))). -- cgit v1.1