Skip to content

Run the code formatter on Mix.TaskTest #6793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 10, 2017
Merged
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
73 changes: 40 additions & 33 deletions lib/mix/test/mix/task_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Code.require_file "../test_helper.exs", __DIR__
Code.require_file("../test_helper.exs", __DIR__)

defmodule Mix.TaskTest do
use MixTest.Case
Expand All @@ -17,43 +17,48 @@ defmodule Mix.TaskTest do
Mix.Task.run("unknown")
end

assert_raise Mix.NoTaskError, "The task \"helli\" could not be found. Did you mean \"hello\"?", fn ->
message = "The task \"helli\" could not be found. Did you mean \"hello\"?"

assert_raise Mix.NoTaskError, message, fn ->
Mix.Task.run("helli")
end

assert_raise Mix.InvalidTaskError, "The task \"invalid\" does not export run/1", fn ->
Mix.Task.run("invalid")
end

misnamed_message =
message =
"The task \"acronym.http\" could not be found because the module is named " <>
"Mix.Tasks.Acronym.HTTP instead of Mix.Tasks.Acronym.Http as expected. " <>
"Please rename it and try again"
assert_raise Mix.NoTaskError, misnamed_message, fn ->
"Mix.Tasks.Acronym.HTTP instead of Mix.Tasks.Acronym.Http as expected. " <>
"Please rename it and try again"

assert_raise Mix.NoTaskError, message, fn ->
Mix.Task.run("acronym.http")
end
end

test "run/2 converts OptionParser.ParseError into Mix errors" do
assert_raise Mix.Error,
"Could not invoke task \"hello\": 1 error found!\n--unknown : Unknown option", fn ->
message = "Could not invoke task \"hello\": 1 error found!\n--unknown : Unknown option"

assert_raise Mix.Error, message, fn ->
Mix.Task.run("hello", ["--parser", "--unknown"])
end

Mix.Task.clear
Mix.Task.clear()

assert_raise Mix.Error,
"Could not invoke task \"hello\": 1 error found!\n--int : Expected type integer, got \"foo\"", fn ->
message =
"Could not invoke task \"hello\": 1 error found!\n--int : Expected type integer, got \"foo\""

assert_raise Mix.Error, message, fn ->
Mix.Task.run("hello", ["--parser", "--int", "foo"])
end
end

test "run/2 outputs task debug info if Mix.debug? is true" do
Mix.shell Mix.Shell.IO
Mix.shell(Mix.Shell.IO)
Mix.debug(true)

assert ExUnit.CaptureIO.capture_io(fn -> Mix.Task.run("hello") end) =~
"** Running mix hello"
assert ExUnit.CaptureIO.capture_io(fn -> Mix.Task.run("hello") end) =~ "** Running mix hello"
after
Mix.shell(Mix.Shell.Process)
Mix.debug(false)
Expand All @@ -68,6 +73,7 @@ defmodule Mix.TaskTest do
use Mix.Task
def run(_), do: "Hello, World"
end

:code.purge(Mix.Tasks.TaskHello)
:code.delete(Mix.Tasks.TaskHello)

Expand All @@ -76,15 +82,15 @@ defmodule Mix.TaskTest do
end

# Clean up the tasks and copy it into deps
Mix.TasksServer.clear
Mix.TasksServer.clear()
File.mkdir_p!("_build/dev/lib/sample/ebin")
File.write!("_build/dev/lib/sample/ebin/Elixir.Mix.Tasks.TaskHello.beam", bin)

# Task was found from deps loadpaths
assert Mix.Task.run("task_hello") == "Hello, World"

# The compile task should not have run yet
assert Mix.TasksServer.run({:task, "compile", Mix.Project.get})
assert Mix.TasksServer.run({:task, "compile", Mix.Project.get()})
end
end

Expand All @@ -97,13 +103,13 @@ defmodule Mix.TaskTest do
end

# Check if compile task have run
refute Mix.TasksServer.run({:task, "compile", Mix.Project.get})
refute Mix.TasksServer.run({:task, "compile", Mix.Project.get()})
end
end

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

Expand All @@ -116,21 +122,22 @@ defmodule Mix.TaskTest do
test "reenable/1 for recursive inside 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.run("clean")
assert :noop = Mix.Task.run("clean")

Mix.Task.reenable "clean"
assert [:ok, :ok] = Mix.Task.run "clean"
assert :noop = Mix.Task.run "clean"
Mix.Task.reenable("clean")
assert [:ok, :ok] = Mix.Task.run("clean")
assert :noop = Mix.Task.run("clean")
end)
end
end

test "reenable/1 for non-recursive inside umbrella" do
in_fixture "umbrella_dep/deps/umbrella", fn ->
Mix.Project.in_project(:umbrella, ".", fn _ ->
assert [:ok, :ok] = Mix.Task.run "clean"
assert :ok = Mix.Task.run "loadpaths" # loadpaths is not recursive
assert [:ok, :ok] = Mix.Task.run("clean")
# loadpaths is not recursive
assert :ok = Mix.Task.run("loadpaths")
end)
end
end
Expand All @@ -143,9 +150,9 @@ defmodule Mix.TaskTest do
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"
assert [:ok, :ok] = Mix.Task.run("clean")
assert :noop = Mix.Task.run("clean")
assert [:ok, :ok] = Mix.Task.rerun("clean")
end)
end
end
Expand All @@ -166,23 +173,23 @@ defmodule Mix.TaskTest do
assert Mix.Task.alias?(:sample) == false
assert Mix.Task.alias?("sample") == false

Mix.Project.push MixTest.Case.Sample
Mix.Project.push(MixTest.Case.Sample)
assert Mix.Task.alias?(:sample) == true
assert Mix.Task.alias?("sample") == true
assert Mix.Task.alias?("another") == false
after
Mix.Project.pop
Mix.Project.pop()
end

test "all_modules/0" do
Mix.Task.load_all
modules = Mix.Task.all_modules
Mix.Task.load_all()
modules = Mix.Task.all_modules()
assert Mix.Tasks.Hello in modules
assert Mix.Tasks.Compile in modules
end

test "moduledoc/1" do
Code.prepend_path MixTest.Case.tmp_path("beams")
Code.prepend_path(MixTest.Case.tmp_path("beams"))
assert Mix.Task.moduledoc(Mix.Tasks.Hello) == "A test task.\n"
end

Expand Down