Skip to content

Commit 1ece71a

Browse files
committed
Handle Windows separators on mix test (#13232)
Closes #13225.
1 parent 197351d commit 1ece71a

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

lib/ex_unit/lib/ex_unit/filters.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ defmodule ExUnit.Filters do
5151

5252
[path | parts] ->
5353
{path_parts, line_numbers} = Enum.split_while(parts, &(to_line_number(&1) == nil))
54-
path = Enum.join([path | path_parts], ":")
54+
path = Enum.join([path | path_parts], ":") |> Path.split() |> Path.join()
5555
lines = for n <- line_numbers, valid_number = validate_line_number(n), do: valid_number
5656

5757
case lines do

lib/ex_unit/test/ex_unit/filters_test.exs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,33 @@ defmodule ExUnit.FiltersTest do
198198
windows_path = "C:\\some\\path.exs"
199199

200200
for path <- [unix_path, windows_path] do
201+
fixed_path = path |> Path.split() |> Path.join()
202+
201203
assert ExUnit.Filters.parse_path("#{path}:123") ==
202-
{path, [exclude: [:test], include: [location: {path, 123}]]}
204+
{fixed_path, [exclude: [:test], include: [location: {fixed_path, 123}]]}
203205

204-
assert ExUnit.Filters.parse_path(path) == {path, []}
206+
assert ExUnit.Filters.parse_path(path) == {fixed_path, []}
205207

206208
assert ExUnit.Filters.parse_path("#{path}:123notreallyalinenumber123") ==
207-
{"#{path}:123notreallyalinenumber123", []}
209+
{"#{fixed_path}:123notreallyalinenumber123", []}
208210

209211
assert ExUnit.Filters.parse_path("#{path}:123:456") ==
210-
{path, [exclude: [:test], include: [location: {path, [123, 456]}]]}
212+
{fixed_path, [exclude: [:test], include: [location: {fixed_path, [123, 456]}]]}
211213

212214
assert ExUnit.Filters.parse_path("#{path}:123notalinenumber123:456") ==
213-
{"#{path}:123notalinenumber123",
214-
[exclude: [:test], include: [location: {"#{path}:123notalinenumber123", 456}]]}
215+
{"#{fixed_path}:123notalinenumber123",
216+
[
217+
exclude: [:test],
218+
include: [location: {"#{fixed_path}:123notalinenumber123", 456}]
219+
]}
215220

216221
output =
217222
ExUnit.CaptureIO.capture_io(:stderr, fn ->
218223
assert ExUnit.Filters.parse_path("#{path}:123:456notalinenumber456") ==
219-
{path, [{:exclude, [:test]}, {:include, [location: {path, 123}]}]}
224+
{fixed_path, [{:exclude, [:test]}, {:include, [location: {fixed_path, 123}]}]}
220225

221226
assert ExUnit.Filters.parse_path("#{path}:123:0:-789:456") ==
222-
{path, [exclude: [:test], include: [location: {path, [123, 456]}]]}
227+
{fixed_path, [exclude: [:test], include: [location: {fixed_path, [123, 456]}]]}
223228
end)
224229

225230
assert output =~ "invalid line number given as ExUnit filter: 456notalinenumber456"
@@ -231,25 +236,25 @@ defmodule ExUnit.FiltersTest do
231236
test "multiple file paths with line numbers" do
232237
unix_path = "test/some/path.exs"
233238
windows_path = "C:\\some\\path.exs"
234-
other_unix_path = "test/some/other_path.exs"
239+
other_unix_path = "test//some//other_path.exs"
235240
other_windows_path = "C:\\some\\other_path.exs"
236241

237-
for {path, other_path} <- [
238-
{unix_path, other_unix_path},
239-
{windows_path, other_windows_path}
240-
] do
242+
for {path, other_path} <- [{unix_path, other_unix_path}, {windows_path, other_windows_path}] do
243+
fixed_path = path |> Path.split() |> Path.join()
244+
fixed_other_path = other_path |> Path.split() |> Path.join()
245+
241246
assert ExUnit.Filters.parse_paths([path, "#{other_path}:456:789"]) ==
242-
{[path, other_path],
247+
{[fixed_path, fixed_other_path],
243248
[
244249
exclude: [:test],
245-
include: [location: {other_path, [456, 789]}]
250+
include: [location: {fixed_other_path, [456, 789]}]
246251
]}
247252

248253
assert ExUnit.Filters.parse_paths(["#{path}:123", "#{other_path}:456"]) ==
249-
{[path, other_path],
254+
{[fixed_path, fixed_other_path],
250255
[
251256
exclude: [:test],
252-
include: [location: {path, 123}, location: {other_path, 456}]
257+
include: [location: {fixed_path, 123}, location: {fixed_other_path, 456}]
253258
]}
254259

255260
output =
@@ -258,12 +263,12 @@ defmodule ExUnit.FiltersTest do
258263
"#{path}:123:0:-789:456",
259264
"#{other_path}:321:0:-987:654"
260265
]) ==
261-
{[path, other_path],
266+
{[fixed_path, fixed_other_path],
262267
[
263268
exclude: [:test],
264269
include: [
265-
location: {path, [123, 456]},
266-
location: {other_path, [321, 654]}
270+
location: {fixed_path, [123, 456]},
271+
location: {fixed_other_path, [321, 654]}
267272
]
268273
]}
269274
end)

lib/mix/test/mix/tasks/test_test.exs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ defmodule Mix.Tasks.TestTest do
223223
output = mix(["test", "test/passing_and_failing_test_failed.exs", "--failed"])
224224
assert output =~ "1 test, 1 failure"
225225

226+
# Plus line
227+
output = mix(["test", "test/passing_and_failing_test_failed.exs:5", "--failed"])
228+
assert output =~ "1 test, 1 failure"
229+
230+
if windows?() do
231+
output = mix(["test", "test\\passing_and_failing_test_failed.exs:5", "--failed"])
232+
assert output =~ "1 test, 1 failure"
233+
end
234+
226235
# `--failed` composes with an `--only` filter by running the intersection.
227236
# Of the failing tests, 1 is tagged with `@tag :foo`.
228237
# Of the passing tests, 1 is tagged with `@tag :foo`.
@@ -509,17 +518,28 @@ defmodule Mix.Tasks.TestTest do
509518
refute output =~ "==> foo"
510519
refute output =~ "Paths given to \"mix test\" did not match any directory/file"
511520

512-
output = mix(["test", "apps/foo/test/foo_tests.exs:9", "apps/bar/test/bar_tests.exs:5"])
521+
casing =
522+
if windows?() do
523+
"apps\\bar\\test\\bar_tests.exs:5"
524+
else
525+
"apps/bar/test/bar_tests.exs:5"
526+
end
527+
528+
output = mix(["test", "apps/foo/test/foo_tests.exs:9", casing])
513529

514530
assert output =~ """
515531
Excluding tags: [:test]
516532
Including tags: [location: {"test/foo_tests.exs", 9}]
517533
"""
518534

535+
assert output =~ "1 test, 0 failures\n"
536+
519537
assert output =~ """
520538
Excluding tags: [:test]
521539
Including tags: [location: {"test/bar_tests.exs", 5}]
522540
"""
541+
542+
assert output =~ "4 tests, 0 failures, 3 excluded\n"
523543
end)
524544
end
525545
end

0 commit comments

Comments
 (0)