File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -533,6 +533,15 @@ defmodule IEx.Helpers do
533533 end
534534 end
535535
536+ @ doc """
537+ Similar to `import_file` but only imports it if it is available.
538+ """
539+ defmacro import_file_if_available ( path ) do
540+ quote do
541+ import_file ( unquote ( path ) , optional: true )
542+ end
543+ end
544+
536545 @ doc """
537546 Evaluates the contents of the file at `path` as if it were directly typed into
538547 the shell.
Original file line number Diff line number Diff line change @@ -257,11 +257,11 @@ defmodule IEx.HelpersTest do
257257 end
258258
259259 test "import_file when the file is missing" do
260- assert "nil" == capture_iex ( "import_file \" nonexistent\" , optional: true" )
261-
262260 failing = capture_iex ( "import_file \" nonexistent\" " )
263261 assert "** (File.Error) could not read file" <> _ = failing
264262 assert failing =~ "no such file or directory"
263+
264+ assert "nil" == capture_iex ( "import_file_if_available \" nonexistent\" " )
265265 end
266266
267267 test "import_if_available helper" do
You can’t perform that action at this time.
0 commit comments