summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rebar.config.script17
-rw-r--r--src/rebar_templater.erl2
-rw-r--r--test/rebar_compile_SUITE.erl19
-rw-r--r--test/rebar_new_SUITE.erl59
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/LICENSE.dtl29
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/README.md.dtl9
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/app.erl.dtl27
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/gitignore.dtl18
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/otp_app.app.src.dtl12
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/rebar.config.dtl2
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/sup.erl.dtl35
-rw-r--r--test/rebar_new_SUITE_data/.rebar3/templates/app/test_app.template12
-rw-r--r--test/rebar_test_utils.erl12
13 files changed, 230 insertions, 23 deletions
diff --git a/rebar.config.script b/rebar.config.script
deleted file mode 100644
index 6735645..0000000
--- a/rebar.config.script
+++ /dev/null
@@ -1,17 +0,0 @@
-%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 ft=erlang et
-
-ExtraDeps = [{retest, ".*", {git, "git://github.com/dizzyd/retest.git"}}],
-
-case os:getenv("REBAR_EXTRA_DEPS") of
- false ->
- CONFIG;
- _ ->
- case lists:keysearch(deps, 1, CONFIG) of
- {value, {deps, Deps}} ->
- NDeps = Deps ++ ExtraDeps,
- lists:keyreplace(deps, 1, CONFIG, {deps, NDeps});
- false ->
- CONFIG ++ [{deps, ExtraDeps}]
- end
-end.
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index ca35b26..47ce093 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -272,7 +272,7 @@ find_disk_templates(State) ->
OtherTemplates = find_other_templates(State),
Home = rebar_dir:home_dir(),
HomeFiles = rebar_utils:find_files(filename:join([Home, ?CONFIG_DIR, "templates"]),
- ?TEMPLATE_RE),
+ ?TEMPLATE_RE, true), % recursive
[{file, F} || F <- OtherTemplates ++ HomeFiles].
%% Fetch template indexes that sit on disk in custom areas
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 03f9c1f..d67be77 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -5,7 +5,8 @@
end_per_suite/1,
init_per_testcase/2,
all/0,
- build_basic_app/1]).
+ build_basic_app/1,
+ build_release_apps/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -24,7 +25,7 @@ init_per_testcase(_, Config) ->
rebar_test_utils:init_rebar_state(Config).
all() ->
- [build_basic_app].
+ [build_basic_app, build_release_apps].
build_basic_app(Config) ->
AppDir = ?config(apps, Config),
@@ -35,3 +36,17 @@ build_basic_app(Config) ->
rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}).
+build_release_apps(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name1 = rebar_test_utils:create_random_name("app1_"),
+ Vsn1 = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(filename:join([AppDir,Name1]), Name1, Vsn1, [kernel, stdlib]),
+ Name2 = rebar_test_utils:create_random_name("app2_"),
+ Vsn2 = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(filename:join([AppDir,Name2]), Name2, Vsn2, [kernel, stdlib]),
+
+ rebar_test_utils:run_and_check(
+ Config, [], ["compile"],
+ {ok, [{app, Name1}, {app, Name2}]}
+ ).
diff --git a/test/rebar_new_SUITE.erl b/test/rebar_new_SUITE.erl
new file mode 100644
index 0000000..62a26af
--- /dev/null
+++ b/test/rebar_new_SUITE.erl
@@ -0,0 +1,59 @@
+%%% This suite can't run tests for built-in templates because
+%%% they require being escriptize and we currently don't support
+%%% this in here!
+-module(rebar_new_SUITE).
+-compile(export_all).
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+all() -> [app].
+
+
+init_per_testcase(Case, Config0) ->
+ Config = rebar_test_utils:init_rebar_state(Config0),
+ Name = rebar_test_utils:create_random_name(atom_to_list(Case)),
+ Data = ?config(data_dir, Config),
+ mock_home_dir(Data),
+ mock_empty_escript_templates(),
+ [{name, Name} | Config].
+
+end_per_testcase(_, Config) ->
+ meck:unload(),
+ Config.
+
+mock_home_dir(Path) ->
+ meck:new(rebar_dir, [passthrough]),
+ meck:expect(rebar_dir, home_dir, fun() -> Path end).
+
+mock_empty_escript_templates() ->
+ %% Can't find escript templates unless we run
+ %% from the escript, which obviously crashes these here tests.
+ meck:new(rebar_utils, [passthrough]),
+ meck:expect(rebar_utils, escript_foldl, fun(_,_,_) -> {ok, []} end).
+
+app(Config) ->
+ Name = ?config(name, Config),
+ rebar_test_utils:run_and_check(
+ Config, [],
+ ["new", "test_app", Name, "author_name=some_name"],
+ {ok, []}
+ ),
+ validate_files(
+ Config, Name,
+ [{"LICENSE", ["some_name", "anonymous@example.org"]},
+ {"README.md", [Name]},
+ {".gitignore", []},
+ {"rebar.config", []},
+ {filename:join(["src", Name++".app.src"]), [Name]},
+ {filename:join(["src", Name++"_sup.erl"]), [Name]},
+ {filename:join(["src", Name++"_app.erl"]), [Name]}
+ ]).
+
+validate_files(_Config, Name, Checks) ->
+ [begin
+ Path = filename:join([Name, File]),
+ {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/app/LICENSE.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/LICENSE.dtl
new file mode 100644
index 0000000..41588ab
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/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/app/README.md.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/README.md.dtl
new file mode 100644
index 0000000..5507536
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/README.md.dtl
@@ -0,0 +1,9 @@
+{{name}}
+=====
+
+{{desc}}
+
+Build
+-----
+
+ $ rebar3 compile
diff --git a/test/rebar_new_SUITE_data/.rebar3/templates/app/app.erl.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/app.erl.dtl
new file mode 100644
index 0000000..83eb9a3
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/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/app/gitignore.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/gitignore.dtl
new file mode 100644
index 0000000..40a1d4f
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/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/app/otp_app.app.src.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/otp_app.app.src.dtl
new file mode 100644
index 0000000..5188f56
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/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/app/rebar.config.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/rebar.config.dtl
new file mode 100644
index 0000000..f618f3e
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/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/app/sup.erl.dtl b/test/rebar_new_SUITE_data/.rebar3/templates/app/sup.erl.dtl
new file mode 100644
index 0000000..a2e7209
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/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/.rebar3/templates/app/test_app.template b/test/rebar_new_SUITE_data/.rebar3/templates/app/test_app.template
new file mode 100644
index 0000000..b17e30c
--- /dev/null
+++ b/test/rebar_new_SUITE_data/.rebar3/templates/app/test_app.template
@@ -0,0 +1,12 @@
+{description, "OTP Application"}.
+{variables, [
+ {name, "mylib", "Name of the OTP application"},
+ {desc, "An OTP application", "Short description of the app"}
+]}.
+{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_test_utils.erl b/test/rebar_test_utils.erl
index 868599f..ac85f41 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -97,13 +97,19 @@ create_random_vsn() ->
%%%%%%%%%%%%%%%
check_results(AppDir, Expected) ->
BuildDir = filename:join([AppDir, "_build", "lib"]),
+ Apps = rebar_app_discover:find_apps([AppDir]),
+ AppsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Apps],
Deps = rebar_app_discover:find_apps([BuildDir], all),
DepsNames = [{ec_cnv:to_list(rebar_app_info:name(App)), App} || App <- Deps],
lists:foreach(
fun({app, Name}) ->
- [App] = rebar_app_discover:find_apps([AppDir]),
ct:pal("Name: ~p", [Name]),
- ?assertEqual(Name, ec_cnv:to_list(rebar_app_info:name(App)))
+ case lists:keyfind(Name, 1, AppsNames) of
+ false ->
+ error({app_not_found, Name});
+ {Name, _App} ->
+ ok
+ end
; ({dep, Name}) ->
ct:pal("Name: ~p", [Name]),
?assertNotEqual(false, lists:keyfind(Name, 1, DepsNames))
@@ -111,7 +117,7 @@ check_results(AppDir, Expected) ->
ct:pal("Name: ~p, Vsn: ~p", [Name, Vsn]),
case lists:keyfind(Name, 1, DepsNames) of
false ->
- error({app_not_found, Name});
+ error({dep_not_found, Name});
{Name, App} ->
?assertEqual(iolist_to_binary(Vsn),
iolist_to_binary(rebar_app_info:original_vsn(App)))