Skip to content

Commit e321cae

Browse files
author
José Valim
committed
Merge pull request #1286 from ToJans/WindowsBugfixing
Fixed path tests when running on Windows: removed drive prefixes from check
2 parents c572cb8 + 5dd3a23 commit e321cae

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

lib/elixir/test/elixir/path_test.exs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ defmodule PathTest do
8181
end
8282

8383
test :absname_with_binary do
84-
assert Path.absname("/foo/bar") == "/foo/bar"
85-
assert Path.absname("/foo/bar/") == "/foo/bar"
86-
assert Path.absname("/foo/bar/../bar") == "/foo/bar/../bar"
84+
assert (Path.absname("/foo/bar") |> strip_drive_letter_if_windows) == "/foo/bar"
85+
assert (Path.absname("/foo/bar/") |> strip_drive_letter_if_windows) == "/foo/bar"
86+
assert (Path.absname("/foo/bar/../bar") |> strip_drive_letter_if_windows) == "/foo/bar/../bar"
8787

8888
assert Path.absname("bar", "/foo") == "/foo/bar"
8989
assert Path.absname("bar/", "/foo") == "/foo/bar"
@@ -93,10 +93,10 @@ defmodule PathTest do
9393
end
9494

9595
test :absname_with_list do
96-
assert Path.absname('/foo/bar') == '/foo/bar'
97-
assert Path.absname('/foo/bar/') == '/foo/bar'
98-
assert Path.absname('/foo/bar/.') == '/foo/bar/.'
99-
assert Path.absname('/foo/bar/../bar') == '/foo/bar/../bar'
96+
assert (Path.absname('/foo/bar') |> strip_drive_letter_if_windows) == '/foo/bar'
97+
assert (Path.absname('/foo/bar/') |> strip_drive_letter_if_windows) == '/foo/bar'
98+
assert (Path.absname('/foo/bar/.') |> strip_drive_letter_if_windows) == '/foo/bar/.'
99+
assert (Path.absname('/foo/bar/../bar') |> strip_drive_letter_if_windows) == '/foo/bar/../bar'
100100
end
101101

102102
test :expand_path_with_user_home do
@@ -115,26 +115,26 @@ defmodule PathTest do
115115
end
116116

117117
test :expand_path_with_binary do
118-
assert Path.expand("/foo/bar") == "/foo/bar"
119-
assert Path.expand("/foo/bar/") == "/foo/bar"
120-
assert Path.expand("/foo/bar/.") == "/foo/bar"
121-
assert Path.expand("/foo/bar/../bar") == "/foo/bar"
118+
assert (Path.expand("/foo/bar") |> strip_drive_letter_if_windows) == "/foo/bar"
119+
assert (Path.expand("/foo/bar/") |> strip_drive_letter_if_windows) == "/foo/bar"
120+
assert (Path.expand("/foo/bar/.") |> strip_drive_letter_if_windows)== "/foo/bar"
121+
assert (Path.expand("/foo/bar/../bar") |> strip_drive_letter_if_windows) == "/foo/bar"
122122

123-
assert Path.expand("bar", "/foo") == "/foo/bar"
124-
assert Path.expand("bar/", "/foo") == "/foo/bar"
125-
assert Path.expand("bar/.", "/foo") == "/foo/bar"
126-
assert Path.expand("bar/../bar", "/foo") == "/foo/bar"
127-
assert Path.expand("../bar/../bar", "/foo/../foo/../foo") == "/bar"
123+
assert (Path.expand("bar", "/foo") |> strip_drive_letter_if_windows)== "/foo/bar"
124+
assert (Path.expand("bar/", "/foo") |> strip_drive_letter_if_windows)== "/foo/bar"
125+
assert (Path.expand("bar/.", "/foo") |> strip_drive_letter_if_windows)== "/foo/bar"
126+
assert (Path.expand("bar/../bar", "/foo") |> strip_drive_letter_if_windows)== "/foo/bar"
127+
assert (Path.expand("../bar/../bar", "/foo/../foo/../foo")|> strip_drive_letter_if_windows) == "/bar"
128128

129129
full = Path.expand("foo/bar")
130130
assert Path.expand("bar/../bar", "foo") == full
131131
end
132132

133133
test :expand_path_with_list do
134-
assert Path.expand('/foo/bar') == '/foo/bar'
135-
assert Path.expand('/foo/bar/') == '/foo/bar'
136-
assert Path.expand('/foo/bar/.') == '/foo/bar'
137-
assert Path.expand('/foo/bar/../bar') == '/foo/bar'
134+
assert (Path.expand('/foo/bar')|> strip_drive_letter_if_windows) == '/foo/bar'
135+
assert (Path.expand('/foo/bar/')|> strip_drive_letter_if_windows) == '/foo/bar'
136+
assert (Path.expand('/foo/bar/.')|> strip_drive_letter_if_windows) == '/foo/bar'
137+
assert (Path.expand('/foo/bar/../bar')|> strip_drive_letter_if_windows) == '/foo/bar'
138138
end
139139

140140
test :relative_to_with_binary do
@@ -250,4 +250,11 @@ defmodule PathTest do
250250
assert Path.split('foo') == ['foo']
251251
assert Path.split('/foo/bar') == ['/', 'foo', 'bar']
252252
end
253+
254+
if match? { :win32, _ }, :os.type do
255+
defp strip_drive_letter_if_windows([_d,?:|rest]), do: rest
256+
defp strip_drive_letter_if_windows(<<_d,?:,rest::binary>>), do: rest
257+
else
258+
defp strip_drive_letter_if_windows(path), do: path
259+
end
253260
end

0 commit comments

Comments
 (0)