summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rebar_ct_SUITE.erl95
-rw-r--r--test/rebar_dir_SUITE.erl43
-rw-r--r--test/rebar_new_SUITE.erl31
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/LICENSE.dtl29
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/README.md.dtl9
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/app.erl.dtl27
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/bad_index.template13
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/gitignore.dtl18
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/otp_app.app.src.dtl12
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/rebar.config.dtl2
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/bad_index/sup.erl.dtl35
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/.gitignore19
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/module.erl.dtl2
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/tpl.template7
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/rebar.config2
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.app.src15
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.erl8
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl_prv.erl32
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/rebar.config3
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.app.src15
-rw-r--r--test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.erl13
-rw-r--r--test/rebar_pkg_SUITE.erl33
-rw-r--r--test/rebar_pkg_alias_SUITE.erl4
23 files changed, 453 insertions, 14 deletions
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 267a9ee..183a1d0 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -17,6 +17,8 @@
multi_suite/1,
all_suite/1,
single_dir_and_single_suite/1,
+ suite_at_root/1,
+ suite_at_app_root/1,
data_dir_correct/1,
cmd_label/1,
cmd_config/1,
@@ -72,7 +74,9 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
single_unmanaged_suite,
multi_suite,
all_suite,
- single_dir_and_single_suite]},
+ single_dir_and_single_suite,
+ suite_at_root,
+ suite_at_app_root]},
{data_dirs, [], [data_dir_correct]},
{ct_opts, [], [cmd_label,
cmd_config,
@@ -177,6 +181,22 @@ init_per_group(dirs_and_suites, Config) ->
ok = filelib:ensure_dir(Suite3),
ok = file:write_file(Suite3, test_suite("extras")),
+ Suite4 = filename:join([AppDir, "root_SUITE.erl"]),
+ ok = file:write_file(Suite4, test_suite("root")),
+
+ ok = file:write_file(filename:join([AppDir, "root_SUITE.hrl"]), <<>>),
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "root_SUITE_data", "dummy.txt"])),
+ ok = file:write_file(filename:join([AppDir, "root_SUITE_data", "some_data.txt"]), <<>>),
+
+ Suite5 = filename:join([AppDir, "apps", Name2, "app_root_SUITE.erl"]),
+ ok = file:write_file(Suite5, test_suite("app_root")),
+
+ ok = file:write_file(filename:join([AppDir, "apps", Name2, "app_root_SUITE.hrl"]), <<>>),
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "app_root_SUITE_data", "dummy.txt"])),
+ ok = file:write_file(filename:join([AppDir, "apps", Name2, "app_root_SUITE_data", "some_data.txt"]), <<>>),
+
{ok, State} = rebar_test_utils:run_and_check(C, [], ["as", "test", "lock"], return),
[{s, State}, {appnames, [Name1, Name2]}|C];
@@ -603,6 +623,79 @@ single_dir_and_single_suite(Config) ->
Suite = proplists:get_value(suite, Opts),
["extra_SUITE"] = Suite.
+suite_at_root(Config) ->
+ AppDir = ?config(apps, Config),
+ State = ?config(s, Config),
+
+ LibDirs = rebar_dir:lib_dirs(State),
+ State1 = rebar_app_discover:do(State, LibDirs),
+
+ Providers = rebar_state:providers(State1),
+ Namespace = rebar_state:namespace(State1),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--suite=" ++ filename:join([AppDir, "root_SUITE"])]),
+
+ State2 = rebar_state:command_parsed_args(State1, GetOptResult),
+
+ Tests = rebar_prv_common_test:prepare_tests(State2),
+ {ok, NewState} = rebar_prv_common_test:compile(State2, Tests),
+ {ok, T} = Tests,
+ Opts = rebar_prv_common_test:translate_paths(NewState, T),
+
+ Suite = proplists:get_value(suite, Opts),
+ Expected = filename:join([AppDir, "_build", "test", "extras", "root_SUITE"]),
+ [Expected] = Suite,
+
+ TestHrl = filename:join([AppDir, "_build", "test", "extras", "root_SUITE.hrl"]),
+ true = filelib:is_file(TestHrl),
+
+ TestBeam = filename:join([AppDir, "_build", "test", "extras", "root_SUITE.beam"]),
+ true = filelib:is_file(TestBeam),
+
+ DataDir = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data"]),
+ true = filelib:is_dir(DataDir),
+
+ DataFile = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data", "some_data.txt"]),
+ true = filelib:is_file(DataFile).
+
+suite_at_app_root(Config) ->
+ AppDir = ?config(apps, Config),
+ [_Name1, Name2] = ?config(appnames, Config),
+ State = ?config(s, Config),
+
+ LibDirs = rebar_dir:lib_dirs(State),
+ State1 = rebar_app_discover:do(State, LibDirs),
+
+ Providers = rebar_state:providers(State1),
+ Namespace = rebar_state:namespace(State1),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--suite=" ++ filename:join([AppDir, "apps", Name2, "app_root_SUITE"])]),
+
+ State2 = rebar_state:command_parsed_args(State1, GetOptResult),
+
+ Tests = rebar_prv_common_test:prepare_tests(State2),
+ {ok, NewState} = rebar_prv_common_test:compile(State2, Tests),
+ {ok, T} = Tests,
+ Opts = rebar_prv_common_test:translate_paths(NewState, T),
+
+ Suite = proplists:get_value(suite, Opts),
+ Expected = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE"]),
+ [Expected] = Suite,
+
+ TestHrl = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.hrl"]),
+ true = filelib:is_file(TestHrl),
+
+ TestBeam = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.beam"]),
+ true = filelib:is_file(TestBeam),
+
+ DataDir = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE_data"]),
+ true = filelib:is_dir(DataDir),
+
+ DataFile = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data", "some_data.txt"]),
+ true = filelib:is_file(DataFile).
+
%% this test probably only fails when this suite is run via rebar3 with the --cover flag
data_dir_correct(Config) ->
DataDir = ?config(data_dir, Config),
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 526f827..1221db7 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -5,7 +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]).
+-export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -15,7 +15,7 @@
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,
- retarget_path].
+ retarget_path, alt_base_dir_abs, alt_base_dir_rel].
init_per_testcase(_, Config) ->
C = rebar_test_utils:init_rebar_state(Config),
@@ -124,4 +124,41 @@ retarget_path(Config) ->
?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
+ rebar_dir:retarget_path(State, "/somewhere/outside/the/project")).
+
+alt_base_dir_abs(Config) ->
+ AltName = lists:flatten(io_lib:format("~p", [os:timestamp()])),
+ AltBaseDir = filename:join(?config(priv_dir, Config), AltName),
+ RebarConfig = [{base_dir, AltBaseDir}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ BaseDir = rebar_dir:base_dir(State),
+ ?assertEqual(filename:join(AltBaseDir, "default"), BaseDir),
+
+ Name1 = ?config(app_one, Config),
+ Name2 = ?config(app_two, Config),
+
+ ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name1, "ebin"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".app"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".beam"]))),
+ ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
+
+alt_base_dir_rel(Config) ->
+ AltName = lists:flatten(io_lib:format("~p", [os:timestamp()])),
+ AltBaseDir = filename:join("..", AltName),
+ RebarConfig = [{base_dir, AltBaseDir}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ BaseDir = rebar_dir:base_dir(State),
+
+ Name1 = ?config(app_one, Config),
+ Name2 = ?config(app_two, Config),
+
+ ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name1, "ebin"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".app"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name1, "ebin", Name1++".beam"]))),
+ ?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
+ ?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
diff --git a/test/rebar_new_SUITE.erl b/test/rebar_new_SUITE.erl
index b514a2b..1971be6 100644
--- a/test/rebar_new_SUITE.erl
+++ b/test/rebar_new_SUITE.erl
@@ -7,9 +7,25 @@
-include_lib("eunit/include/eunit.hrl").
all() -> [app_git_user, app_hg_user, app_with_fallbacks,
- app_with_flags1, app_with_flags2].
+ app_with_flags1, app_with_flags2, plugin_tpl].
+init_per_testcase(plugin_tpl, Config) ->
+ application:load(rebar),
+ DataDir = ?config(data_dir, Config),
+ PrivDir = ?config(priv_dir, Config),
+ Name = rebar_test_utils:create_random_name("plugin_tpl"),
+ AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
+ ec_file:copy(filename:join([DataDir, "plugin_tpl"]), AppsDir, [recursive]),
+ Verbosity = rebar3:log_level(),
+ rebar_log:init(command_line, Verbosity),
+ GlobalDir = filename:join([DataDir, "cache"]),
+ State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{global_rebar_dir, GlobalDir}
+ ,{root_dir, AppsDir}]),
+ mock_home_dir(DataDir),
+ mock_empty_escript_templates(),
+ [{apps, AppsDir}, {state, State}, {name, Name} | Config];
init_per_testcase(Case, Config0) ->
Config = rebar_test_utils:init_rebar_state(Config0),
Name = rebar_test_utils:create_random_name(atom_to_list(Case)),
@@ -132,11 +148,24 @@ app_with_flags2(Config) ->
{filename:join(["src", Name++"_app.erl"]), [Name]}
]).
+plugin_tpl(Config) ->
+ Name = ?config(name, Config),
+ rebar_test_utils:run_and_check(
+ Config, [],
+ ["new", "-f", "tpl", Name],
+ {ok, []}
+ ),
+ Result = filename:join(["src", Name++".erl"]), % In CWD
+ {ok, Bin} = file:read_file(Result),
+ {match, _} = re:run(Bin, Name, [multiline,global]).
+
validate_files(_Config, Name, Checks) ->
[begin
Path = filename:join([Name, File]),
+ ct:pal("validating ~s for content", [Path]),
{ok, Bin} = file:read_file(Path),
[{match, _} = re:run(Bin, Pattern, [multiline,global])
|| Pattern <- Patterns]
end || {File, Patterns} <- Checks],
ok.
+
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/LICENSE.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/LICENSE.dtl
new file mode 100644
index 0000000..41588ab
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/LICENSE.dtl
@@ -0,0 +1,29 @@
+Copyright (c) {{copyright_year}}, {{author_name}} <{{author_email}}>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+* The names of its contributors may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/README.md.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/README.md.dtl
new file mode 100644
index 0000000..5507536
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/README.md.dtl
@@ -0,0 +1,9 @@
+{{name}}
+=====
+
+{{desc}}
+
+Build
+-----
+
+ $ rebar3 compile
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/app.erl.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/app.erl.dtl
new file mode 100644
index 0000000..83eb9a3
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/app.erl.dtl
@@ -0,0 +1,27 @@
+%%%-------------------------------------------------------------------
+%% @doc {{name}} public API
+%% @end
+%%%-------------------------------------------------------------------
+
+-module({{name}}_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2
+ ,stop/1]).
+
+%%====================================================================
+%% API
+%%====================================================================
+
+start(_StartType, _StartArgs) ->
+ {{name}}_sup:start_link().
+
+%%--------------------------------------------------------------------
+stop(_State) ->
+ ok.
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/bad_index.template b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/bad_index.template
new file mode 100644
index 0000000..50998cc
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/bad_index.template
@@ -0,0 +1,13 @@
+{description, "OTP Application"}.
+{variables, [
+ {name, "mylib", "Name of the OTP application"},
+ {desc, "An OTP application", "Short description of the app"}
+]}.
+bad_term,
+{template, "app.erl.dtl", "{{name}}/src/{{name}}_app.erl"}.
+{template, "sup.erl.dtl", "{{name}}/src/{{name}}_sup.erl"}.
+{template, "otp_app.app.src.dtl", "{{name}}/src/{{name}}.app.src"}.
+{template, "rebar.config.dtl", "{{name}}/rebar.config"}.
+{template, "gitignore.dtl", "{{name}}/.gitignore"}.
+{template, "LICENSE.dtl", "{{name}}/LICENSE"}.
+{template, "README.md.dtl", "{{name}}/README.md"}.
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/gitignore.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/gitignore.dtl
new file mode 100644
index 0000000..40a1d4f
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/gitignore.dtl
@@ -0,0 +1,18 @@
+.rebar3
+_*
+.eunit
+*.o
+*.beam
+*.plt
+*.swp
+*.swo
+.erlang.cookie
+ebin
+log
+erl_crash.dump
+.rebar
+_rel
+_deps
+_plugins
+_tdeps
+logs
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/otp_app.app.src.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/otp_app.app.src.dtl
new file mode 100644
index 0000000..5188f56
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/otp_app.app.src.dtl
@@ -0,0 +1,12 @@
+{application, {{name}},
+ [{description, "{{desc}}"}
+ ,{vsn, "0.1.0"}
+ ,{registered, []}
+ ,{mod, {'{{name}}_app', []}}
+ ,{applications,
+ [kernel
+ ,stdlib
+ ]}
+ ,{env,[]}
+ ,{modules, []}
+ ]}.
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/rebar.config.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/rebar.config.dtl
new file mode 100644
index 0000000..f618f3e
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/rebar.config.dtl
@@ -0,0 +1,2 @@
+{erl_opts, [debug_info]}.
+{deps, []}. \ No newline at end of file
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/sup.erl.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/sup.erl.dtl
new file mode 100644
index 0000000..a2e7209
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/bad_index/sup.erl.dtl
@@ -0,0 +1,35 @@
+%%%-------------------------------------------------------------------
+%% @doc {{name}} top level supervisor.
+%% @end
+%%%-------------------------------------------------------------------
+
+-module({{name}}_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+-define(SERVER, ?MODULE).
+
+%%====================================================================
+%% API functions
+%%====================================================================
+
+start_link() ->
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
+
+%%====================================================================
+%% Supervisor callbacks
+%%====================================================================
+
+%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
+init([]) ->
+ {ok, { {one_for_all, 0, 1}, []} }.
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/.gitignore b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/.gitignore
new file mode 100644
index 0000000..a939dce
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/.gitignore
@@ -0,0 +1,19 @@
+.rebar3
+_*
+.eunit
+*.o
+*.beam
+*.plt
+*.swp
+*.swo
+.erlang.cookie
+ebin
+log
+erl_crash.dump
+.rebar
+_rel
+_deps
+_plugins
+_tdeps
+logs
+_build \ No newline at end of file
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/module.erl.dtl b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/module.erl.dtl
new file mode 100644
index 0000000..9129961
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/module.erl.dtl
@@ -0,0 +1,2 @@
+-module({{name}}).
+
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/tpl.template b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/tpl.template
new file mode 100644
index 0000000..7fa4caf
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/priv/tpl.template
@@ -0,0 +1,7 @@
+{description, "A basic template"}.
+{variables, [
+ {name, "mod", "Name of the module"}
+]}.
+
+{dir, "test"}.
+{template, "module.erl.dtl", "src/{{name}}.erl"}.
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/rebar.config b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/rebar.config
new file mode 100644
index 0000000..f618f3e
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/rebar.config
@@ -0,0 +1,2 @@
+{erl_opts, [debug_info]}.
+{deps, []}. \ No newline at end of file
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.app.src b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.app.src
new file mode 100644
index 0000000..6c6d811
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.app.src
@@ -0,0 +1,15 @@
+{application, 'tpl',
+ [{description, "A rebar plugin"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {applications,
+ [kernel,
+ stdlib
+ ]},
+ {env,[]},
+ {modules, []},
+
+ {contributors, []},
+ {licenses, []},
+ {links, []}
+ ]}.
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.erl b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.erl
new file mode 100644
index 0000000..529bcb8
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl.erl
@@ -0,0 +1,8 @@
+-module('tpl').
+
+-export([init/1]).
+
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ {ok, State1} = 'tpl_prv':init(State),
+ {ok, State1}.
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl_prv.erl b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl_prv.erl
new file mode 100644
index 0000000..c68ffa3
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/_checkouts/tpl/src/tpl_prv.erl
@@ -0,0 +1,32 @@
+-module('tpl_prv').
+
+-export([init/1, do/1, format_error/1]).
+
+-define(PROVIDER, 'tpl').
+-define(DEPS, [app_discovery]).
+
+%% ===================================================================
+%% Public API
+%% ===================================================================
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ Provider = providers:create([
+ {name, ?PROVIDER}, % The 'user friendly' name of the task
+ {module, ?MODULE}, % The module implementation of the task
+ {bare, true}, % The task can be run by the user, always true
+ {deps, ?DEPS}, % The list of dependencies
+ {example, "rebar3 tpl"}, % How to use the plugin
+ {opts, []}, % list of options understood by the plugin
+ {short_desc, "A rebar plugin"},
+ {desc, "A rebar plugin"}
+ ]),
+ {ok, rebar_state:add_provider(State, Provider)}.
+
+
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do(State) ->
+ {ok, State}.
+
+-spec format_error(any()) -> iolist().
+format_error(Reason) ->
+ io_lib:format("~p", [Reason]).
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/rebar.config b/test/rebar_new_SUITE_data/plugin_tpl/rebar.config
new file mode 100644
index 0000000..74d1fc5
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/rebar.config
@@ -0,0 +1,3 @@
+{erl_opts, [debug_info]}.
+{deps, []}.
+{plugins, [tpl]}.
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.app.src b/test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.app.src
new file mode 100644
index 0000000..8f18874
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.app.src
@@ -0,0 +1,15 @@
+{application, 'plugin_tpl',
+ [{description, "An OTP library"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {applications,
+ [kernel,
+ stdlib
+ ]},
+ {env,[]},
+ {modules, []},
+
+ {contributors, []},
+ {licenses, []},
+ {links, []}
+ ]}.
diff --git a/test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.erl b/test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.erl
new file mode 100644
index 0000000..406bd97
--- /dev/null
+++ b/test/rebar_new_SUITE_data/plugin_tpl/src/plugin_tpl.erl
@@ -0,0 +1,13 @@
+-module('plugin_tpl').
+
+%% API exports
+-export([]).
+
+%%====================================================================
+%% API functions
+%%====================================================================
+
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index af6bf42..9f19e0d 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -11,7 +11,8 @@
-define(good_checksum, <<"1C6CE379D191FBAB41B7905075E0BF87CBBE23C77CECE775C5A0B786B2244C35">>).
all() -> [good_uncached, good_cached, badindexchk, badpkg,
- bad_to_good, good_disconnect, bad_disconnect, pkgs_provider].
+ bad_to_good, good_disconnect, bad_disconnect, pkgs_provider,
+ find_highest_matching].
init_per_suite(Config) ->
application:start(meck),
@@ -30,8 +31,8 @@ init_per_testcase(pkgs_provider=Name, Config) ->
filelib:ensure_dir(filename:join([CacheDir, "registry"])),
ok = ets:tab2file(Tid, filename:join([CacheDir, "registry"])),
meck:new(rebar_packages, [passthrough]),
- meck:expect(rebar_packages, registry_dir, fun(_) -> CacheDir end),
- meck:expect(rebar_packages, package_dir, fun(_) -> CacheDir end),
+ meck:expect(rebar_packages, registry_dir, fun(_) -> {ok, CacheDir} end),
+ meck:expect(rebar_packages, package_dir, fun(_) -> {ok, CacheDir} end),
rebar_prv_update:hex_to_index(rebar_state:new()),
Config;
init_per_testcase(good_uncached=Name, Config0) ->
@@ -86,7 +87,12 @@ init_per_testcase(bad_disconnect=Name, Config0) ->
meck:unload(httpc),
meck:new(httpc, [passthrough, unsticky]),
meck:expect(httpc, request, fun(_, _, _, _, _) -> {error, econnrefused} end),
- Config.
+ Config;
+init_per_testcase(Name, Config0) ->
+ Config = [{good_cache, false},
+ {pkg, {<<"goodpkg">>, <<"1.0.0">>}}
+ | Config0],
+ mock_config(Name, Config).
end_per_testcase(_, Config) ->
unmock_config(Config),
@@ -172,6 +178,16 @@ pkgs_provider(Config) ->
{ok, []}
).
+find_highest_matching(_Config) ->
+ State = rebar_state:new(),
+ {ok, Vsn} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0.0">>, package_index, State),
+ ?assertEqual(<<"1.0.1">>, Vsn),
+ {ok, Vsn1} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0">>, package_index, State),
+ ?assertEqual(<<"1.1.1">>, Vsn1),
+ {ok, Vsn2} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"2.0">>, package_index, State),
+ ?assertEqual(<<"2.0.0">>, Vsn2).
+
+
%%%%%%%%%%%%%%%
%%% Helpers %%%
%%%%%%%%%%%%%%%
@@ -182,10 +198,13 @@ mock_config(Name, Config) ->
Tid = ets:new(registry_table, [public]),
ets:insert_new(Tid, [
{<<"badindexchk">>,[[<<"1.0.0">>]]},
- {<<"goodpkg">>,[[<<"1.0.0">>]]},
+ {<<"goodpkg">>,[[<<"1.0.0">>, <<"1.0.1">>, <<"1.1.1">>, <<"2.0.0">>]]},
{<<"badpkg">>,[[<<"1.0.0">>]]},
{{<<"badindexchk">>,<<"1.0.0">>}, [[], ?bad_checksum, [<<"rebar3">>]]},
{{<<"goodpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"1.0.1">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"1.1.1">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"2.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]},
{{<<"badpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]}
]),
CacheDir = filename:join([CacheRoot, "hex", "com", "test", "packages"]),
@@ -203,8 +222,8 @@ mock_config(Name, Config) ->
meck:expect(rebar_dir, global_cache_dir, fun(_) -> CacheRoot end),
meck:new(rebar_packages, [passthrough]),
- meck:expect(rebar_packages, registry_dir, fun(_) -> CacheDir end),
- meck:expect(rebar_packages, package_dir, fun(_) -> CacheDir end),
+ meck:expect(rebar_packages, registry_dir, fun(_) -> {ok, CacheDir} end),
+ meck:expect(rebar_packages, package_dir, fun(_) -> {ok, CacheDir} end),
rebar_prv_update:hex_to_index(rebar_state:new()),
%% Cache fetches are mocked -- we assume the server and clients are
diff --git a/test/rebar_pkg_alias_SUITE.erl b/test/rebar_pkg_alias_SUITE.erl
index f7fa5d4..fef2310 100644
--- a/test/rebar_pkg_alias_SUITE.erl
+++ b/test/rebar_pkg_alias_SUITE.erl
@@ -98,8 +98,8 @@ mock_config(Name, Config) ->
meck:expect(rebar_dir, global_cache_dir, fun(_) -> CacheRoot end),
meck:new(rebar_packages, [passthrough, no_link]),
- meck:expect(rebar_packages, registry_dir, fun(_) -> CacheDir end),
- meck:expect(rebar_packages, package_dir, fun(_) -> CacheDir end),
+ meck:expect(rebar_packages, registry_dir, fun(_) -> {ok, CacheDir} end),
+ meck:expect(rebar_packages, package_dir, fun(_) -> {ok, CacheDir} end),
rebar_prv_update:hex_to_index(rebar_state:new()),
%% Cache fetches are mocked -- we assume the server and clients are