diff options
Diffstat (limited to 'test')
11 files changed, 146 insertions, 1 deletions
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/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 +%%==================================================================== |