summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-01-27 21:30:18 -0500
committerFred Hebert <mononcqc@ferd.ca>2017-01-27 22:21:17 -0500
commitba954cfb43f0b05e15ee206b13488d62c3537267 (patch)
tree92dea83e69ed2b9717981c2838adf82c501cbce1 /test
parentabff9dfff34e04bd23b1f178eadee4d8770de9a9 (diff)
Survive EDoc crashes
Instead of a hard crash, display an error message indicating which app failed. We can't report the exact failure; only EDoc does it to stdout itself and we can't capture it. Pre/Post hooks are run properly despite the failure, as per escript and compile providers.
Diffstat (limited to 'test')
-rw-r--r--test/rebar_edoc_SUITE.erl22
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.app.src16
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.erl9
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_app.erl26
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_sup.erl35
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.app.src16
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.erl12
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_app.erl26
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_sup.erl35
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.app.src17
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.erl19
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_app.erl26
-rw-r--r--test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_sup.erl35
13 files changed, 293 insertions, 1 deletions
diff --git a/test/rebar_edoc_SUITE.erl b/test/rebar_edoc_SUITE.erl
index fded2b0..2c4aba5 100644
--- a/test/rebar_edoc_SUITE.erl
+++ b/test/rebar_edoc_SUITE.erl
@@ -3,7 +3,7 @@
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
-all() -> [multiapp].
+all() -> [multiapp, error_survival].
init_per_testcase(multiapp, Config) ->
application:load(rebar),
@@ -16,6 +16,18 @@ init_per_testcase(multiapp, Config) ->
rebar_log:init(command_line, Verbosity),
State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {state, State}, {name, Name} | Config];
+init_per_testcase(error_survival, Config) ->
+ application:load(rebar),
+ DataDir = ?config(data_dir, Config),
+ PrivDir = ?config(priv_dir, Config),
+ Name = rebar_test_utils:create_random_name("error_survival"),
+ AppsDir = filename:join([PrivDir, rebar_test_utils:create_random_name(Name)]),
+ ec_file:copy(filename:join([DataDir, "bad"]), AppsDir, [recursive]),
+ Verbosity = rebar3:log_level(),
+ rebar_log:init(command_line, Verbosity),
+ State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
[{apps, AppsDir}, {state, State}, {name, Name} | Config].
end_per_testcase(_, Config) ->
@@ -42,6 +54,14 @@ multiapp(Config) ->
filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
"apps/bar1/doc/bar1.html")).
+error_survival(Config) ->
+ RebarConfig = [],
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["edoc"],
+ {error,{rebar_prv_edoc,{app_failed,"bar2"}}}
+ ),
+ ok.
+
file_content_matches(Path, Regex) ->
case file:read_file(Path) of
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.app.src b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.app.src
new file mode 100644
index 0000000..6e7ec24
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.app.src
@@ -0,0 +1,16 @@
+{application, bar1,
+ [{description, "An OTP application"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {mod, { bar1_app, []}},
+ {applications,
+ [kernel,
+ stdlib
+ ]},
+ {env,[]},
+ {modules, []},
+
+ {maintainers, []},
+ {licenses, []},
+ {links, []}
+ ]}.
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.erl b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.erl
new file mode 100644
index 0000000..2700aef
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1.erl
@@ -0,0 +1,9 @@
+-module(bar1).
+-export([bar1/0]).
+-export_type([barer1/0]).
+
+-type barer1() :: string().
+
+% @doc Bar1 bars the bar.
+-spec bar1() -> barer1().
+bar1() -> "Barer1". \ No newline at end of file
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_app.erl b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_app.erl
new file mode 100644
index 0000000..414ac30
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_app.erl
@@ -0,0 +1,26 @@
+%%%-------------------------------------------------------------------
+%% @doc bar1 public API
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(bar1_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%%====================================================================
+%% API
+%%====================================================================
+
+start(_StartType, _StartArgs) ->
+ bar1_sup:start_link().
+
+%%--------------------------------------------------------------------
+stop(_State) ->
+ ok.
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_sup.erl b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_sup.erl
new file mode 100644
index 0000000..f9d6670
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar1/src/bar1_sup.erl
@@ -0,0 +1,35 @@
+%%%-------------------------------------------------------------------
+%% @doc bar1 top level supervisor.
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(bar1_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_edoc_SUITE_data/bad/apps/bar2/src/bar2.app.src b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.app.src
new file mode 100644
index 0000000..58de8bc
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.app.src
@@ -0,0 +1,16 @@
+{application, bar2,
+ [{description, "An OTP application"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {mod, { bar2_app, []}},
+ {applications,
+ [kernel,
+ stdlib
+ ]},
+ {env,[]},
+ {modules, []},
+
+ {maintainers, []},
+ {licenses, []},
+ {links, []}
+ ]}.
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.erl b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.erl
new file mode 100644
index 0000000..2afb745
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2.erl
@@ -0,0 +1,12 @@
+%% @doc one docline is fine
+%% @doc a second docline causes a failure
+%% @doc if not, then a & causes a bad ref error.
+-module(bar2).
+-export([bar2/0]).
+-export_type([barer2/0]).
+
+-type barer2() :: string().
+
+% @doc Bar2 bars the bar2.
+-spec bar2() -> barer2().
+bar2() -> "Barer2".
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_app.erl b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_app.erl
new file mode 100644
index 0000000..d0058a0
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_app.erl
@@ -0,0 +1,26 @@
+%%%-------------------------------------------------------------------
+%% @doc bar2 public API
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(bar2_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%%====================================================================
+%% API
+%%====================================================================
+
+start(_StartType, _StartArgs) ->
+ bar2_sup:start_link().
+
+%%--------------------------------------------------------------------
+stop(_State) ->
+ ok.
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_sup.erl b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_sup.erl
new file mode 100644
index 0000000..0bdaf4a
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/bar2/src/bar2_sup.erl
@@ -0,0 +1,35 @@
+%%%-------------------------------------------------------------------
+%% @doc bar2 top level supervisor.
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(bar2_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_edoc_SUITE_data/bad/apps/foo/src/foo.app.src b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.app.src
new file mode 100644
index 0000000..9987fd5
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.app.src
@@ -0,0 +1,17 @@
+{application, foo,
+ [{description, "An OTP application"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {mod, { foo_app, []}},
+ {applications,
+ [kernel,
+ stdlib,
+ bar1, bar2
+ ]},
+ {env,[]},
+ {modules, []},
+
+ {maintainers, []},
+ {licenses, []},
+ {links, []}
+ ]}.
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.erl b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.erl
new file mode 100644
index 0000000..52e3d0a
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo.erl
@@ -0,0 +1,19 @@
+-module(foo).
+
+-export([foo/0, bar1/0, bar2/0]).
+
+-export_type([fooer/0]).
+
+-type fooer() :: string().
+
+% @doc Foo function returns fooer.
+-spec foo() -> fooer().
+foo() -> "fooer".
+
+% @doc Bar1 function returns barer1.
+-spec bar1() -> bar1:barer1().
+bar1() -> bar1:bar1().
+
+% @doc Bar2 functions returns barer2.
+-spec bar2() -> bar2:barer2().
+bar2() -> bar2:bar2(). \ No newline at end of file
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_app.erl b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_app.erl
new file mode 100644
index 0000000..d0158d7
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_app.erl
@@ -0,0 +1,26 @@
+%%%-------------------------------------------------------------------
+%% @doc foo public API
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(foo_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%%====================================================================
+%% API
+%%====================================================================
+
+start(_StartType, _StartArgs) ->
+ foo_sup:start_link().
+
+%%--------------------------------------------------------------------
+stop(_State) ->
+ ok.
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
diff --git a/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_sup.erl b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_sup.erl
new file mode 100644
index 0000000..67e88b4
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/bad/apps/foo/src/foo_sup.erl
@@ -0,0 +1,35 @@
+%%%-------------------------------------------------------------------
+%% @doc foo top level supervisor.
+%% @end
+%%%-------------------------------------------------------------------
+
+-module(foo_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
+%%====================================================================