Skip to content

Commit c289632

Browse files
committed
Handle the enotdir case in ls helper
1 parent e0dc938 commit c289632

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,11 @@ defmodule IEx.Helpers do
10771077
IO.puts(IEx.color(:eval_error, "No such file or directory #{path}"))
10781078

10791079
{:error, :enotdir} ->
1080-
IO.puts(IEx.color(:eval_info, Path.absname(path)))
1080+
if File.exists?(path) do
1081+
IO.puts(IEx.color(:eval_info, Path.absname(path)))
1082+
else
1083+
IO.puts(IEx.color(:eval_error, "Not a directory #{path}"))
1084+
end
10811085
end
10821086

10831087
dont_display_result()

lib/iex/test/iex/helpers_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,15 @@ defmodule IEx.HelpersTest do
12131213
"No such file or directory unknown_dir\n"
12141214
end)
12151215
end
1216+
1217+
test "prints an error if part of the path is not a dir (enotdir)" do
1218+
File.cd!(iex_path(), fn ->
1219+
path = Path.join("mix.exs", "foo")
1220+
1221+
assert capture_io(fn -> ls(path) end) ==
1222+
"Not a directory #{path}\n"
1223+
end)
1224+
end
12161225
end
12171226

12181227
describe "exports" do

0 commit comments

Comments
 (0)