Skip to content

Commit 8720c56

Browse files
author
José Valim
committed
Ensure c helper works with full path
1 parent 2c5650c commit 8720c56

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule IEx.Helpers do
6969
raise ArgumentError, message: "expected a binary or a list of binaries as argument"
7070
end
7171

72-
{ found, not_found } = Enum.map(files, &Path.join(path, &1)) |> Enum.partition(&File.exists?/1)
72+
{ found, not_found } = Enum.map(files, &Path.expand(&1, path)) |> Enum.partition(&File.exists?/1)
7373

7474
unless Enum.empty?(not_found) do
7575
IO.puts IEx.color(:eval_error, %s[Cannot find #{Enum.join(not_found, ", ")}])
@@ -82,7 +82,8 @@ defmodule IEx.Helpers do
8282

8383
modules = Enum.map(erls, fn(source) ->
8484
{ module, binary } = compile_erlang(source)
85-
File.write!(Path.join(path, source), binary)
85+
base = source |> Path.basename |> Path.rootname
86+
File.write!(Path.join(path, base <> ".beam"), binary)
8687
module
8788
end)
8889

lib/iex/test/iex/helpers_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ defmodule IEx.HelpersTest do
207207
cleanup_modules([Sample])
208208
end
209209

210+
test "c helper with full path" do
211+
filename = "sample.ex"
212+
with_file filename, test_module_code, fn ->
213+
assert c(Path.expand(filename)) == [Sample]
214+
assert Sample.run == :run
215+
end
216+
after
217+
cleanup_modules([Sample])
218+
end
219+
210220
test "c helper multiple modules" do
211221
assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
212222
Sample.run

0 commit comments

Comments
 (0)