 
   ## Helpers
 
-  defp assert_compile_fail(given_exception, string) do
-    case format_rescue(string) do
-      {^given_exception, _, _} -> :ok
-      {exception, _, _} ->
-        raise ExUnit.AssertionError,
-          left: inspect(exception),
-          right: inspect(given_exception),
-          message: "Expected match"
-    end
-  end
-
-  defp assert_compile_fail(given_exception, given_message, string) do
-    {exception, message, _} = format_rescue(string)
-
-    unless exception == given_exception and message =~ given_message do
-      raise ExUnit.AssertionError,
-        left: "#{inspect exception}[message: #{inspect message}]",
-        right: "#{inspect given_exception}[message: #{inspect given_message}]",
-        message: "Expected match"
-    end
-  end
-
-  defp rescue_stacktrace(expr) do
-    expr |> format_rescue() |> elem(2)
-  end
-
-  defp format_rescue(expr) do
-    result = try do
-      :elixir.eval(to_charlist(expr), [])
-      nil
-    rescue
-      error -> {error.__struct__, Exception.message(error), System.stacktrace}
-    end
-
-    result || flunk("Expected expression to fail")
+  defp assert_eval_raise(given_exception, string) do
+    assert_raise given_exception, fn ->
+      Code.eval_string(string)
+    end
+  end
+
+  defp assert_eval_raise(given_exception, given_message, string) do
+    assert_raise given_exception, given_message, fn ->
+      Code.eval_string(string)
+    end
+  end
+
+  defp rescue_stacktrace(string) do
+    stacktrace =
+      try do
+        Code.eval_string(string)
+        nil
+      rescue
+        _ -> System.stacktrace
+      end
+
+    stacktrace || flunk("Expected expression to fail")
   end
 end

  end

  test "private macro" do
    assert_compile_fail UndefinedFunctionError,
      "function Kernel.ErrorsTest.PrivateMacro.foo/0 is undefined (function foo/0 is not available)",
      '''
      defmodule Kernel.ErrorsTest.PrivateMacro do

  end

  test "internal function overridden" do
    assert_eval_raise CompileError,
      "nofile:2: cannot define def __info__/1 as it is automatically defined by Elixir",
      '''
      defmodule Kernel.ErrorsTest.InternalFunctionOverridden do
