summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Binns <TheFirstAvenger@users.noreply.github.com>2019-05-18 15:48:00 -0400
committerJosé Valim <jose.valim@gmail.com>2019-05-18 21:48:00 +0200
commit852efbaf605dd7540f6717e13da2b5fdb1a5c5f9 (patch)
treea402e93f1db5e83fd389864797c934dec32833cb
parentd67240a39abf8989b2991a29b08a123abc2f5dd9 (diff)
downloadelixir-852efbaf605dd7540f6717e13da2b5fdb1a5c5f9.tar.gz
Resolve full umbrella path name in mix test arg (#9050)
-rw-r--r--lib/mix/lib/mix/tasks/test.ex35
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/bar/lib/bar.ex (renamed from lib/mix/test/fixtures/umbrella_cover/apps/bar/lib/bar.ex)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/bar/mix.exs (renamed from lib/mix/test/fixtures/umbrella_cover/apps/bar/mix.exs)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/bar/test/bar_tests.exs (renamed from lib/mix/test/fixtures/umbrella_cover/apps/bar/test/bar_tests.exs)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/bar/test/test_helper.exs (renamed from lib/mix/test/fixtures/umbrella_cover/apps/bar/test/test_helper.exs)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/foo/lib/foo.ex (renamed from lib/mix/test/fixtures/umbrella_cover/apps/foo/lib/foo.ex)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/foo/mix.exs (renamed from lib/mix/test/fixtures/umbrella_cover/apps/foo/mix.exs)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/foo/test/foo_tests.exs (renamed from lib/mix/test/fixtures/umbrella_cover/apps/foo/test/foo_tests.exs)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/apps/foo/test/test_helper.exs (renamed from lib/mix/test/fixtures/umbrella_cover/apps/foo/test/test_helper.exs)0
-rw-r--r--lib/mix/test/fixtures/umbrella_test/mix.exs (renamed from lib/mix/test/fixtures/umbrella_cover/mix.exs)2
-rw-r--r--lib/mix/test/mix/tasks/test_test.exs27
11 files changed, 62 insertions, 2 deletions
diff --git a/lib/mix/lib/mix/tasks/test.ex b/lib/mix/lib/mix/tasks/test.ex
index d75f92924..cd2b817c6 100644
--- a/lib/mix/lib/mix/tasks/test.ex
+++ b/lib/mix/lib/mix/tasks/test.ex
@@ -146,6 +146,16 @@ defmodule Mix.Tasks.Test do
mix test test/some/particular/file_test.exs
+ Tests in umbrella projects can be run from the root by specifying
+ the full suite path, including `apps/my_app/test`, in which case
+ recursive tests for other child apps will be skipped completely:
+
+ # To run all tests for my_app from the umbrella root
+ mix test apps/my_app/test
+
+ # To run a given test file on my_app from the umbrella root
+ mix test apps/my_app/test/some/particular/file_test.exs
+
## Command line options
* `--color` - enables color in the output
@@ -327,6 +337,31 @@ defmodule Mix.Tasks.Test do
def run(args) do
{opts, files} = OptionParser.parse!(args, strict: @switches)
+ if not Mix.Task.recursing?() do
+ do_run(opts, args, files)
+ else
+ {files_in_apps_path, files_not_in_apps_path} =
+ Enum.split_with(files, &String.starts_with?(&1, "apps/"))
+
+ current_app_path = "apps/#{Mix.Project.config()[:app]}/"
+
+ files_in_current_app_path =
+ files_in_apps_path
+ |> Enum.filter(fn file ->
+ String.starts_with?(file, current_app_path) or
+ not File.exists?(Path.join("../..", file))
+ end)
+ |> Enum.map(&String.trim_leading(&1, current_app_path))
+
+ if files_in_current_app_path == [] and files_in_apps_path != [] do
+ :ok
+ else
+ do_run(opts, args, files_in_current_app_path ++ files_not_in_apps_path)
+ end
+ end
+ end
+
+ defp do_run(opts, args, files) do
if opts[:listen_on_stdin] do
System.at_exit(fn _ ->
IO.gets(:stdio, "")
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/bar/lib/bar.ex b/lib/mix/test/fixtures/umbrella_test/apps/bar/lib/bar.ex
index a8e3b45de..a8e3b45de 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/bar/lib/bar.ex
+++ b/lib/mix/test/fixtures/umbrella_test/apps/bar/lib/bar.ex
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/bar/mix.exs b/lib/mix/test/fixtures/umbrella_test/apps/bar/mix.exs
index b045c8c03..b045c8c03 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/bar/mix.exs
+++ b/lib/mix/test/fixtures/umbrella_test/apps/bar/mix.exs
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/bar/test/bar_tests.exs b/lib/mix/test/fixtures/umbrella_test/apps/bar/test/bar_tests.exs
index a59c015f8..a59c015f8 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/bar/test/bar_tests.exs
+++ b/lib/mix/test/fixtures/umbrella_test/apps/bar/test/bar_tests.exs
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/bar/test/test_helper.exs b/lib/mix/test/fixtures/umbrella_test/apps/bar/test/test_helper.exs
index 869559e70..869559e70 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/bar/test/test_helper.exs
+++ b/lib/mix/test/fixtures/umbrella_test/apps/bar/test/test_helper.exs
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/foo/lib/foo.ex b/lib/mix/test/fixtures/umbrella_test/apps/foo/lib/foo.ex
index 639f78475..639f78475 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/foo/lib/foo.ex
+++ b/lib/mix/test/fixtures/umbrella_test/apps/foo/lib/foo.ex
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/foo/mix.exs b/lib/mix/test/fixtures/umbrella_test/apps/foo/mix.exs
index b4e5d0d8d..b4e5d0d8d 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/foo/mix.exs
+++ b/lib/mix/test/fixtures/umbrella_test/apps/foo/mix.exs
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/foo/test/foo_tests.exs b/lib/mix/test/fixtures/umbrella_test/apps/foo/test/foo_tests.exs
index 63eeefbb3..63eeefbb3 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/foo/test/foo_tests.exs
+++ b/lib/mix/test/fixtures/umbrella_test/apps/foo/test/foo_tests.exs
diff --git a/lib/mix/test/fixtures/umbrella_cover/apps/foo/test/test_helper.exs b/lib/mix/test/fixtures/umbrella_test/apps/foo/test/test_helper.exs
index 869559e70..869559e70 100644
--- a/lib/mix/test/fixtures/umbrella_cover/apps/foo/test/test_helper.exs
+++ b/lib/mix/test/fixtures/umbrella_test/apps/foo/test/test_helper.exs
diff --git a/lib/mix/test/fixtures/umbrella_cover/mix.exs b/lib/mix/test/fixtures/umbrella_test/mix.exs
index 438655760..e4756ac03 100644
--- a/lib/mix/test/fixtures/umbrella_cover/mix.exs
+++ b/lib/mix/test/fixtures/umbrella_test/mix.exs
@@ -1,4 +1,4 @@
-defmodule UmbrellaCover.MixProject do
+defmodule UmbrellaTest.MixProject do
use Mix.Project
def project do
diff --git a/lib/mix/test/mix/tasks/test_test.exs b/lib/mix/test/mix/tasks/test_test.exs
index 829518331..df1a503b1 100644
--- a/lib/mix/test/mix/tasks/test_test.exs
+++ b/lib/mix/test/mix/tasks/test_test.exs
@@ -124,7 +124,7 @@ defmodule Mix.Tasks.TestTest do
end
test "--cover: reports the coverage of each app's modules in an umbrella" do
- in_fixture("umbrella_cover", fn ->
+ in_fixture("umbrella_test", fn ->
output = mix(["test", "--cover"])
# For bar, we do regular --cover and also test protocols
@@ -297,6 +297,31 @@ defmodule Mix.Tasks.TestTest do
end)
end
+ test "umbrella with file path" do
+ in_fixture("umbrella_test", fn ->
+ output = mix(["test", "apps/bar/test/bar_tests.exs"])
+
+ assert output =~ """
+ ==> bar
+ .
+
+ """
+
+ refute output =~ """
+ ==> foo
+ .
+
+ """
+
+ assert mix(["test", "apps/unknown_app/test"]) =~ """
+ ==> bar
+ Paths given to "mix test" did not match any directory/file: apps/unknown_app/test
+ ==> foo
+ Paths given to "mix test" did not match any directory/file: apps/unknown_app/test
+ """
+ end)
+ end
+
defp receive_until_match(port, expected, acc) do
receive do
{^port, {:data, output}} ->