From f11785eb37a8ebc16e531afaf2abbdc9a59924c8 Mon Sep 17 00:00:00 2001 From: Erick Dennis Date: Tue, 10 Oct 2017 09:30:57 +0200 Subject: [PATCH 1/4] Run the code formatter on Mix.TaskTest --- lib/mix/test/mix/task_test.exs | 76 ++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/lib/mix/test/mix/task_test.exs b/lib/mix/test/mix/task_test.exs index 7e7c64dd2f4..09329ae1e44 100644 --- a/lib/mix/test/mix/task_test.exs +++ b/lib/mix/test/mix/task_test.exs @@ -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 @@ -17,9 +17,11 @@ 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 -> - Mix.Task.run("helli") - end + assert_raise Mix.NoTaskError, + "The task \"helli\" could not be found. Did you mean \"hello\"?", + fn -> + Mix.Task.run("helli") + end assert_raise Mix.InvalidTaskError, "The task \"invalid\" does not export run/1", fn -> Mix.Task.run("invalid") @@ -27,8 +29,9 @@ defmodule Mix.TaskTest do misnamed_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" + "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.Task.run("acronym.http") end @@ -36,24 +39,25 @@ defmodule Mix.TaskTest do 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 -> - Mix.Task.run("hello", ["--parser", "--unknown"]) - end + "Could not invoke task \"hello\": 1 error found!\n--unknown : Unknown option", + 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 -> - Mix.Task.run("hello", ["--parser", "--int", "foo"]) - end + "Could not invoke task \"hello\": 1 error found!\n--int : Expected type integer, got \"foo\"", + 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) @@ -68,6 +72,7 @@ defmodule Mix.TaskTest do use Mix.Task def run(_), do: "Hello, World" end + :code.purge(Mix.Tasks.TaskHello) :code.delete(Mix.Tasks.TaskHello) @@ -76,7 +81,7 @@ 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) @@ -84,7 +89,7 @@ defmodule Mix.TaskTest do 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 @@ -97,13 +102,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 @@ -116,12 +121,12 @@ 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 @@ -129,8 +134,9 @@ defmodule Mix.TaskTest do 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 @@ -143,9 +149,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 @@ -166,23 +172,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 From 9b609ac1298699f675a0c1710c53b631a1d957ee Mon Sep 17 00:00:00 2001 From: Erick Dennis Date: Tue, 10 Oct 2017 10:14:50 +0200 Subject: [PATCH 2/4] Extract error messages to variables --- lib/mix/test/mix/task_test.exs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/mix/test/mix/task_test.exs b/lib/mix/test/mix/task_test.exs index 09329ae1e44..cac886d7493 100644 --- a/lib/mix/test/mix/task_test.exs +++ b/lib/mix/test/mix/task_test.exs @@ -17,11 +17,11 @@ 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 -> - Mix.Task.run("helli") - end + no_task_message = "The task \"helli\" could not be found. Did you mean \"hello\"?" + + assert_raise Mix.NoTaskError, no_task_message, fn -> + Mix.Task.run("helli") + end assert_raise Mix.InvalidTaskError, "The task \"invalid\" does not export run/1", fn -> Mix.Task.run("invalid") @@ -38,19 +38,21 @@ defmodule Mix.TaskTest do 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 -> - Mix.Task.run("hello", ["--parser", "--unknown"]) - end + unknown_opt_message = + "Could not invoke task \"hello\": 1 error found!\n--unknown : Unknown option" + + assert_raise Mix.Error, unknown_opt_message, fn -> + Mix.Task.run("hello", ["--parser", "--unknown"]) + end Mix.Task.clear() - assert_raise Mix.Error, - "Could not invoke task \"hello\": 1 error found!\n--int : Expected type integer, got \"foo\"", - fn -> - Mix.Task.run("hello", ["--parser", "--int", "foo"]) - end + bad_type_message = + "Could not invoke task \"hello\": 1 error found!\n--int : Expected type integer, got \"foo\"" + + assert_raise Mix.Error, bad_type_message, fn -> + Mix.Task.run("hello", ["--parser", "--int", "foo"]) + end end test "run/2 outputs task debug info if Mix.debug? is true" do From 82d362f6cbf3597ed71c7f4370357afe33ad8fd8 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 10 Oct 2017 14:27:47 +0200 Subject: [PATCH 3/4] Update task_test.exs --- lib/mix/test/mix/task_test.exs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/mix/test/mix/task_test.exs b/lib/mix/test/mix/task_test.exs index cac886d7493..a284204a40e 100644 --- a/lib/mix/test/mix/task_test.exs +++ b/lib/mix/test/mix/task_test.exs @@ -17,9 +17,9 @@ defmodule Mix.TaskTest do Mix.Task.run("unknown") end - no_task_message = "The task \"helli\" could not be found. Did you mean \"hello\"?" + message = "The task \"helli\" could not be found. Did you mean \"hello\"?" - assert_raise Mix.NoTaskError, no_task_message, fn -> + assert_raise Mix.NoTaskError, message, fn -> Mix.Task.run("helli") end @@ -27,30 +27,30 @@ defmodule Mix.TaskTest do 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 -> + assert_raise Mix.NoTaskError, message, fn -> Mix.Task.run("acronym.http") end end test "run/2 converts OptionParser.ParseError into Mix errors" do - unknown_opt_message = + message = "Could not invoke task \"hello\": 1 error found!\n--unknown : Unknown option" - assert_raise Mix.Error, unknown_opt_message, fn -> + assert_raise Mix.Error, message, fn -> Mix.Task.run("hello", ["--parser", "--unknown"]) end Mix.Task.clear() - bad_type_message = + message = "Could not invoke task \"hello\": 1 error found!\n--int : Expected type integer, got \"foo\"" - assert_raise Mix.Error, bad_type_message, fn -> + assert_raise Mix.Error, message, fn -> Mix.Task.run("hello", ["--parser", "--int", "foo"]) end end From bd99e6bffe0c672a7d20879d7dda0b89ac76f039 Mon Sep 17 00:00:00 2001 From: Erick Dennis Date: Tue, 10 Oct 2017 15:01:10 +0200 Subject: [PATCH 4/4] Rerun formatter after renaming variables --- lib/mix/test/mix/task_test.exs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/mix/test/mix/task_test.exs b/lib/mix/test/mix/task_test.exs index a284204a40e..cf3ef66d10a 100644 --- a/lib/mix/test/mix/task_test.exs +++ b/lib/mix/test/mix/task_test.exs @@ -38,8 +38,7 @@ defmodule Mix.TaskTest do end test "run/2 converts OptionParser.ParseError into Mix errors" do - message = - "Could not invoke task \"hello\": 1 error found!\n--unknown : Unknown option" + 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"])