Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/iex/lib/iex/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1080,11 +1080,17 @@ defmodule IEx.Helpers do
{:error, :enoent} ->
IO.puts(IEx.color(:eval_error, "No such file or directory #{path}"))

{:error, :enotdir} ->
IO.puts(IEx.color(:eval_info, Path.absname(path)))

{:error, reason} ->
IO.puts(IEx.color(:eval_error, :file.format_error(reason)))
cond do
File.exists?(path) and not File.dir?(path) ->
IO.puts(IEx.color(:eval_info, Path.absname(path)))

reason == :enotdir ->
IO.puts(IEx.color(:eval_error, "No such file or directory #{path}"))

true ->
IO.puts(IEx.color(:eval_error, :file.format_error(reason)))
end
end

dont_display_result()
Expand Down
22 changes: 22 additions & 0 deletions lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,28 @@ defmodule IEx.HelpersTest do
test "lists the given directory" do
assert capture_io(fn -> ls("~") end) == capture_io(fn -> ls(System.user_home()) end)
end

test "returns an existing file" do
File.cd!(iex_path(), fn ->
assert capture_io(fn -> ls("mix.exs") end) == Path.join(iex_path(), "mix.exs") <> "\n"
end)
end

test "prints an error if directory doesn't exist" do
File.cd!(iex_path(), fn ->
assert capture_io(fn -> ls("unknown_dir") end) ==
"No such file or directory unknown_dir\n"
end)
end

test "prints an error if part of the path is not a dir (enotdir)" do
File.cd!(iex_path(), fn ->
path = Path.join("mix.exs", "foo")

assert capture_io(fn -> ls(path) end) ==
"No such file or directory #{path}\n"
end)
end
end

describe "exports" do
Expand Down