Skip to content

Commit ff1046a

Browse files
committed
Handle the enotdir case in ls helper
1 parent 7c1f8e1 commit ff1046a

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
@@ -1081,7 +1081,11 @@ defmodule IEx.Helpers do
10811081
IO.puts(IEx.color(:eval_error, "No such file or directory #{path}"))
10821082

10831083
{:error, :enotdir} ->
1084-
IO.puts(IEx.color(:eval_info, Path.absname(path)))
1084+
if File.exists?(path) do
1085+
IO.puts(IEx.color(:eval_info, Path.absname(path)))
1086+
else
1087+
IO.puts(IEx.color(:eval_error, "Not a directory #{path}"))
1088+
end
10851089

10861090
{:error, reason} ->
10871091
IO.puts(IEx.color(:eval_error, :file.format_error(reason)))

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)