summaryrefslogtreecommitdiff
path: root/test/rebar_test_utils.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/rebar_test_utils.erl')
-rw-r--r--test/rebar_test_utils.erl58
1 files changed, 40 insertions, 18 deletions
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 2cdc58b..4943d4b 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -4,7 +4,7 @@
-export([init_rebar_state/1, init_rebar_state/2, run_and_check/4]).
-export([expand_deps/2, flat_deps/1, flat_pkgdeps/1, top_level_deps/1]).
-export([create_app/4, create_eunit_app/4, create_empty_app/4, create_config/2]).
--export([create_random_name/1, create_random_vsn/0]).
+-export([create_random_name/1, create_random_vsn/0, write_src_file/2]).
%%%%%%%%%%%%%%
%%% Public %%%
@@ -70,7 +70,8 @@ run_and_check(Config, RebarConfig, Command, Expect) ->
%% - src/<file>.app.src
%% And returns a `rebar_app_info' object.
create_app(AppDir, Name, Vsn, Deps) ->
- write_src_file(AppDir, Name),
+ write_src_file(AppDir, Name ++ ".erl"),
+ write_src_file(AppDir, "not_a_real_src_" ++ Name ++ ".erl"),
write_app_src_file(AppDir, Name, Vsn, Deps),
rebar_app_info:new(Name, Vsn, AppDir, Deps).
@@ -104,16 +105,22 @@ create_config(AppDir, Contents) ->
%% @doc Util to create a random variation of a given name.
create_random_name(Name) ->
- random:seed(os:timestamp()),
+ random_seed(),
Name ++ erlang:integer_to_list(random:uniform(1000000)).
%% @doc Util to create a random variation of a given version.
create_random_vsn() ->
- random:seed(os:timestamp()),
+ 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))]).
+random_seed() ->
+ <<A:32, B:32, C:32>> = crypto:rand_bytes(12),
+ random:seed({A,B,C}).
+
+
+
expand_deps(_, []) -> [];
expand_deps(git, [{Name, Deps} | Rest]) ->
Dep = {Name, ".*", {git, "https://example.org/user/"++Name++".git", "master"}},
@@ -160,9 +167,10 @@ 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)),
+ Locks = lists:flatten(rebar_config:consult_lock_file(LockFile)),
InvalidApps = rebar_app_discover:find_apps(BuildDirs, invalid),
ValidApps = rebar_app_discover:find_apps(BuildDirs, valid),
@@ -176,10 +184,12 @@ 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}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("App Name: ~p", [Name]),
case lists:keyfind(Name, 1, DepsNames) of
false ->
error({app_not_found, Name});
@@ -187,7 +197,7 @@ check_results(AppDir, Expected) ->
ok
end
; ({app, Name, invalid}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("Invalid Name: ~p", [Name]),
case lists:keyfind(Name, 1, InvalidDepsNames) of
false ->
error({app_not_found, Name});
@@ -195,7 +205,7 @@ check_results(AppDir, Expected) ->
ok
end
; ({app, Name, valid}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("Valid Name: ~p", [Name]),
case lists:keyfind(Name, 1, ValidDepsNames) of
false ->
error({app_not_found, Name});
@@ -203,13 +213,13 @@ check_results(AppDir, Expected) ->
ok
end
; ({checkout, Name}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("Checkout Name: ~p", [Name]),
?assertNotEqual(false, lists:keyfind(Name, 1, CheckoutsNames))
; ({dep, Name}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("Dep Name: ~p", [Name]),
?assertNotEqual(false, lists:keyfind(Name, 1, DepsNames))
; ({dep, Name, Vsn}) ->
- ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]),
+ ct:pal("Dep Name: ~p, Vsn: ~p", [Name, Vsn]),
case lists:keyfind(Name, 1, DepsNames) of
false ->
error({dep_not_found, Name});
@@ -218,22 +228,34 @@ check_results(AppDir, Expected) ->
iolist_to_binary(rebar_app_info:original_vsn(App)))
end
; ({plugin, Name}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("Plugin Name: ~p", [Name]),
?assertNotEqual(false, lists:keyfind(Name, 1, PluginsNames))
; ({plugin, Name, Vsn}) ->
- ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]),
+ ct:pal("Plugin 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("Global Plugin Name: ~p", [Name]),
+ ?assertNotEqual(false, lists:keyfind(Name, 1, GlobalPluginsNames))
+ ; ({global_plugin, Name, Vsn}) ->
+ ct:pal("Global Plugin 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)))
end
; ({lock, Name}) ->
- ct:pal("Name: ~p", [Name]),
+ ct:pal("Lock Name: ~p", [Name]),
?assertNotEqual(false, lists:keyfind(iolist_to_binary(Name), 1, Locks))
; ({lock, Name, Vsn}) ->
- ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]),
+ ct:pal("Lock Name: ~p, Vsn: ~p", [Name, Vsn]),
case lists:keyfind(iolist_to_binary(Name), 1, Locks) of
false ->
error({lock_not_found, Name});
@@ -282,9 +304,9 @@ check_results(AppDir, Expected) ->
end, Expected).
write_src_file(Dir, Name) ->
- Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]),
+ Erl = filename:join([Dir, "src", Name]),
ok = filelib:ensure_dir(Erl),
- ok = ec_file:write(Erl, erl_src_file("not_a_real_src_" ++ Name ++ ".erl")).
+ ok = ec_file:write(Erl, erl_src_file(Name)).
write_eunitized_src_file(Dir, Name) ->
Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]),