diff --git a/lib/iex/lib/iex/helpers.ex b/lib/iex/lib/iex/helpers.ex index 4c072f30565..5b6349abd42 100644 --- a/lib/iex/lib/iex/helpers.ex +++ b/lib/iex/lib/iex/helpers.ex @@ -507,6 +507,7 @@ defmodule IEx.Helpers do source end end) + |> Enum.uniq() {erlang, elixir} = Enum.split_with(sources, &String.ends_with?(&1, ".erl")) diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index 79e4b68dbe9..a66579528a4 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -1544,6 +1544,31 @@ defmodule IEx.HelpersTest do cleanup_modules([Sample]) end + test "reloads Elixir modules from same file" do + filename = "sample.ex" + + contents = """ + defmodule Foo do + def hello, do: :foo + end + + defmodule Bar do + def hello, do: :bar + end + """ + + with_file(filename, contents, fn -> + assert Enum.sort(c(filename, ".")) == [Bar, Foo] + + assert capture_io(:stderr, fn -> + assert {:reloaded, modules} = r([Bar, Foo]) + assert Enum.sort(modules) == [Bar, Foo] + end) =~ "redefining module Foo" + end) + after + cleanup_modules([Bar, Foo]) + end + test "reloads Erlang modules" do assert_raise UndefinedFunctionError, ~r"function :sample.hello/0 is undefined", fn -> :sample.hello()