Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/mix/lib/mix/tasks/do.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,25 @@ defmodule Mix.Tasks.Do do
{apps, args} = extract_apps_from_args(args)
show_forgotten_apps_warning(apps)

Enum.each(gather_commands(args), fn [task | args] ->
if apps == [] do
Mix.Task.run(task, args)
else
Mix.Task.run_in_apps(task, apps, args)
end
Enum.each(gather_commands(args), fn
[task | args] ->
if apps == [] do
Mix.Task.run(task, args)
else
Mix.Task.run_in_apps(task, apps, args)
end

[] ->
Mix.raise("""
One of the commands passed to "mix do" is empty. Each command passed to "mix do" must \
have at least the task name. These are all invalid:

mix do
mix do my_task +
mix do + my_task

Run "mix help do" for more information.
""")
end)
end

Expand Down
8 changes: 8 additions & 0 deletions lib/mix/test/mix/tasks/do_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ defmodule Mix.Tasks.DoTest do
end)
end

test "raises if a task is empty" do
for args <- [~w(), ~w(+), ~w(help +), ~w(+ help)] do
assert_raise Mix.Error, ~r"^One of the commands passed to \"mix do\" is empty", fn ->
Mix.Tasks.Do.run(args)
end
end
end

test "gather_command returns a list of commands" do
assert gather_commands(["help", "+", "compile"]) ==
[["help"], ["compile"]]
Expand Down
Loading