Skip to content

Commit

Permalink
Merge pull request #4394 from whatyouhide/mix-task-rerun
Browse files Browse the repository at this point in the history
Add Mix.Task.rerun/1,2
  • Loading branch information
josevalim committed Mar 16, 2016
2 parents 37accac + 9eee208 commit 8f8819d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/mix/lib/mix/task.ex
Expand Up @@ -388,6 +388,18 @@ defmodule Mix.Task do
end
end

@doc """
Reruns `task` with the given arguments.
This function reruns the given task; to do that, it first re-enables the task
and then regularly runs it.
"""
@spec rerun(task_name, [any]) :: any
def rerun(task, args \\ []) do
reenable(task)
run(task, args)
end

@doc """
Returns `true` if given module is a task.
"""
Expand Down
15 changes: 15 additions & 0 deletions lib/mix/test/mix/task_test.exs
Expand Up @@ -123,6 +123,21 @@ defmodule Mix.TaskTest do
end
end

test "rerun/1" do
assert Mix.Task.run("hello") == "Hello, World!"
assert Mix.Task.rerun("hello") == "Hello, World!"
end

test "rerun/1 for umbrella" do
in_fixture "umbrella_dep/deps/umbrella", fn ->
Mix.Project.in_project(:umbrella, ".", fn _ ->
assert [:ok, :ok] = Mix.Task.run "clean"
assert :noop = Mix.Task.run "clean"
assert [:ok, :ok] = Mix.Task.rerun "clean"
end)
end
end

test "get!" do
assert Mix.Task.get!("hello") == Mix.Tasks.Hello

Expand Down

0 comments on commit 8f8819d

Please sign in to comment.