 
   defp another_test_module do
     """
-    defmodule Another_test_module do
+    defmodule Sample2 do
       def hello do
         :world
       end

      r :non_existent_module
    end

    File.write! "test-module-code.ex", test_module_code
    assert c("test-module-code.ex") == [Helpers_test_module]
    assert Helpers_test_module.run == :run
    # FIXME: `r Helpers_test_module` returns :nosource
    assert r(Helpers_test_module) == [Helpers_test_module]

    assert r == [Helpers_test_module]
  after
    File.rm "test-module-code.ex"
    File.rm! "Elixir.Helpers_test_module.beam"

    # FIXME: This errors out with "Module 'Elixir.Helpers_test_module' must be purged before loading"
    #true = :code.delete Helpers_test_module

    :code.purge Helpers_test_module
  end

  defp test_module_code do
    """
    defmodule Helpers_test_module do
      def run do
        :run
      end

    end) >= 2
  end

  defp cleanup_modules(mods) do
    Enum.each mods, fn mod ->
      File.rm! "#{mod}.beam"
      true = :code.delete mod
      :code.purge mod
    end
  end

  defp with_file(names, codes, fun) when is_list(names) and is_list(codes) do
    Enum.each Enum.zip(names, codes), fn { name, code } ->
      File.write! name, code
    end
    try do
      fun.()
    after
      Enum.each names, File.rm(&1)
    end
  end

  defp with_file(name, code, fun) do
    with_file(List.wrap(name), List.wrap(code), fun)
  end

  test "c helper" do
    assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
      Sample.run
    end

    filename = "test-module-code.ex"
    with_file filename, test_module_code, fn ->
      assert c(filename) == [Sample]
      assert Sample.run == :run
    end
  after
    cleanup_modules([Sample])
  end

  test "c helper multiple modules" do
    assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
      Sample.run
    end

    filename = "test-module-code.ex"
    with_file filename, test_module_code <> "\n" <> another_test_module, fn ->
      assert c(filename) |> Enum.sort == [Sample,Sample2]
      assert Sample.run == :run
      assert Sample2.hello == :world
    end
  after
    cleanup_modules([Sample, Sample2])
  end

  test "c helper list" do
    assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
      Sample.run
    end

    filenames = ["test-module-code-1.ex", "test-module-code-2.ex"]
    with_file filenames, [test_module_code, another_test_module], fn ->
      assert c(filenames) |> Enum.sort == [Sample,Sample2]
      assert Sample.run == :run
      assert Sample2.hello == :world
    end
  after
    cleanup_modules([Sample, Sample2])
  end

  test "l helper" do
    assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
      Sample.run
    end

    assert l(:non_existent_module) == {:error,:nofile}

    filename = "test-module-code.ex"
    with_file filename, test_module_code, fn ->
      assert c(filename) == [Sample]
      assert Sample.run == :run

      File.write! filename, "defmodule Sample do end"
      # FIXME: is there another way to compile a file without loading its module?
      System.cmd "elixirc test-module-code.ex"

      assert l(Sample) == {:module, Sample}
      assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
        Sample.run
      end
    end
  after
    # Clean up the old version left over after l()
    :code.purge(Sample)
    cleanup_modules([Sample])
  end

  test "r helper" do
    assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
      Sample.run
    end

    assert r == []
