summaryrefslogtreecommitdiff
path: root/inttest
diff options
context:
space:
mode:
authorTim Watson <watson.timothy@gmail.com>2011-01-26 01:50:33 +0000
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-03-12 16:31:41 +0100
commite76770511a6bae6fe9d23e7821db8d32e897f9a8 (patch)
treec99b887a4cbb19f2c84977294d2590459468391f /inttest
parent2e1b4da71d85122bbb2aabd78fd1b4dbfefddd21 (diff)
Add pre and post script support for all commands
This change makes it possible to assign pre/post scripts to all rebar commands. This allows users fine grained control over when scripts and/or shell commands should be executed, where such extensions are absolutely needed. Several examples have been added to the rebar.config.sample file.
Diffstat (limited to 'inttest')
-rw-r--r--inttest/thooks/fish.erl5
-rw-r--r--inttest/thooks/rebar.config7
-rw-r--r--inttest/thooks/thooks_rt.erl40
3 files changed, 52 insertions, 0 deletions
diff --git a/inttest/thooks/fish.erl b/inttest/thooks/fish.erl
new file mode 100644
index 0000000..739cb94
--- /dev/null
+++ b/inttest/thooks/fish.erl
@@ -0,0 +1,5 @@
+-module(fish).
+
+-compile(export_all).
+
+fish() -> fish.
diff --git a/inttest/thooks/rebar.config b/inttest/thooks/rebar.config
new file mode 100644
index 0000000..6514818
--- /dev/null
+++ b/inttest/thooks/rebar.config
@@ -0,0 +1,7 @@
+%% pre-scripts
+{pre_hooks, [{clean, "echo preclean >> preclean.out"},
+ {compile, "echo precompile >> precompile.out"}]}.
+
+%% post-scripts
+{post_hooks, [{clean, "echo postclean >> postclean.out"},
+ {compile, "echo postcompile >> postcompile.out"}]}.
diff --git a/inttest/thooks/thooks_rt.erl b/inttest/thooks/thooks_rt.erl
new file mode 100644
index 0000000..52af9f5
--- /dev/null
+++ b/inttest/thooks/thooks_rt.erl
@@ -0,0 +1,40 @@
+-module(thooks_rt).
+
+-include_lib("eunit/include/eunit.hrl").
+-compile(export_all).
+
+files() ->
+ [
+ %% dummy lfe files
+ {copy, "../../rebar", "rebar"},
+ {copy, "rebar.config", "rebar.config"},
+ {copy, "fish.erl", "src/fish.erl"},
+ {create, "ebin/fish.app", app(fish, [fish])}
+ ].
+
+run(_Dir) ->
+ ?assertMatch({ok, _}, retest_sh:run("./rebar -v clean compile", [])),
+ ensure_command_ran_only_once("preclean"),
+ ensure_command_ran_only_once("precompile"),
+ ensure_command_ran_only_once("postclean"),
+ ensure_command_ran_only_once("postcompile"),
+ ok.
+
+ensure_command_ran_only_once(Command) ->
+ File = Command ++ ".out",
+ ?assert(filelib:is_regular(File)),
+ %% ensure that this command only ran once (not for each module)
+ {ok, Content} = file:read_file(File),
+ ?assertEqual(Command ++ "\n", binary_to_list(Content)).
+
+%%
+%% Generate the contents of a simple .app file
+%%
+app(Name, Modules) ->
+ App = {application, Name,
+ [{description, atom_to_list(Name)},
+ {vsn, "1"},
+ {modules, Modules},
+ {registered, []},
+ {applications, [kernel, stdlib]}]},
+ io_lib:format("~p.\n", [App]).