summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralisdair sullivan <alisdairsullivan@yahoo.ca>2016-10-17 13:41:05 -0700
committerGitHub <noreply@github.com>2016-10-17 13:41:05 -0700
commit4e7b765645d7eb49da750ed59bb917d41cd08a66 (patch)
treeb4ebeffad41331730aaa3a1ffaea7783d5888fc9
parent94f87477d5db0243992ca222c79486acbfb9fcee (diff)
parent504431473b9cc7f9c1641f640fc4d8a02c9aa079 (diff)
Merge pull request #1356 from ferd/prevent-as-crash-on-missing-tasks
Prevent crashes in `rebar3 as` with no tasks
-rw-r--r--src/rebar_prv_as.erl6
-rw-r--r--test/rebar_as_SUITE.erl17
2 files changed, 20 insertions, 3 deletions
diff --git a/src/rebar_prv_as.erl b/src/rebar_prv_as.erl
index b4f7ac4..e7c6d68 100644
--- a/src/rebar_prv_as.erl
+++ b/src/rebar_prv_as.erl
@@ -33,9 +33,11 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{Profiles, Tasks} = args_to_profiles_and_tasks(rebar_state:command_args(State)),
- case Profiles of
- [] ->
+ case {Profiles, Tasks} of
+ {[], _} ->
{error, "At least one profile must be specified when using `as`"};
+ {_, []} ->
+ {error, "At least one task must be specified when using `as`"};
_ ->
warn_on_empty_profile(Profiles, State),
State1 = rebar_state:apply_profiles(State, [list_to_atom(X) || X <- Profiles]),
diff --git a/test/rebar_as_SUITE.erl b/test/rebar_as_SUITE.erl
index 0f37dc8..ce8046b 100644
--- a/test/rebar_as_SUITE.erl
+++ b/test/rebar_as_SUITE.erl
@@ -14,6 +14,7 @@
as_dir_name/1,
as_with_task_args/1,
warn_on_empty_profile/1,
+ error_on_empty_tasks/1,
clean_as_profile/1]).
-include_lib("common_test/include/ct.hrl").
@@ -33,7 +34,7 @@ all() -> [as_basic, as_multiple_profiles, as_multiple_tasks,
as_multiple_profiles_multiple_tasks,
as_comma_placement, as_comma_then_space,
as_dir_name, as_with_task_args,
- warn_on_empty_profile, clean_as_profile].
+ warn_on_empty_profile, error_on_empty_tasks, clean_as_profile].
as_basic(Config) ->
AppDir = ?config(apps, Config),
@@ -159,6 +160,20 @@ warn_on_empty_profile(Config) ->
meck:unload(rebar_log),
ok.
+error_on_empty_tasks(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("as_error_empty_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ meck:new(rebar_log, [passthrough]),
+ rebar_test_utils:run_and_check(Config,
+ [],
+ ["as", "default"],
+ {error, "At least one task must be specified when using `as`"}),
+ ok.
+
warn_match(App, History) ->
lists:any(
fun({_, {rebar_log,log, [warn, "No entry for profile ~s in config.",