File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -1080,11 +1080,17 @@ defmodule IEx.Helpers do
10801080 { :error , :enoent } ->
10811081 IO . puts ( IEx . color ( :eval_error , "No such file or directory #{ path } " ) )
10821082
1083- { :error , :enotdir } ->
1084- IO . puts ( IEx . color ( :eval_info , Path . absname ( path ) ) )
1085-
10861083 { :error , reason } ->
1087- IO . puts ( IEx . color ( :eval_error , :file . format_error ( reason ) ) )
1084+ cond do
1085+ File . exists? ( path ) and not File . dir? ( path ) ->
1086+ IO . puts ( IEx . color ( :eval_info , Path . absname ( path ) ) )
1087+
1088+ reason == :enotdir ->
1089+ IO . puts ( IEx . color ( :eval_error , "No such file or directory #{ path } " ) )
1090+
1091+ true ->
1092+ IO . puts ( IEx . color ( :eval_error , :file . format_error ( reason ) ) )
1093+ end
10881094 end
10891095
10901096 dont_display_result ( )
Original file line number Diff line number Diff line change @@ -1200,6 +1200,28 @@ defmodule IEx.HelpersTest do
12001200 test "lists the given directory" do
12011201 assert capture_io ( fn -> ls ( "~" ) end ) == capture_io ( fn -> ls ( System . user_home ( ) ) end )
12021202 end
1203+
1204+ test "returns an existing file" do
1205+ File . cd! ( iex_path ( ) , fn ->
1206+ assert capture_io ( fn -> ls ( "mix.exs" ) end ) == Path . join ( iex_path ( ) , "mix.exs" ) <> "\n "
1207+ end )
1208+ end
1209+
1210+ test "prints an error if directory doesn't exist" do
1211+ File . cd! ( iex_path ( ) , fn ->
1212+ assert capture_io ( fn -> ls ( "unknown_dir" ) end ) ==
1213+ "No such file or directory unknown_dir\n "
1214+ end )
1215+ 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+ "No such file or directory #{ path } \n "
1223+ end )
1224+ end
12031225 end
12041226
12051227 describe "exports" do
You can’t perform that action at this time.
0 commit comments