       Code.string_to_quoted!(expr, location)
     rescue
       e ->
-        message = "(#{inspect e.__struct__}) #{Exception.message(e)}"
+        ex_message = "(#{inspect(e.__struct__)}) #{Exception.message(e)}"
+
         quote do
+          message = "Doctest did not compile, got: #{unquote(ex_message)}"
+
           reraise ExUnit.AssertionError,
-            [message: "Doctest did not compile, got: #{unquote(message)}",
-             expr: unquote(String.trim(expr))],
-            unquote(stack)
+                  [message: message, expr: unquote(String.trim(expr))],
+                  unquote(stack)
         end
     end
   end

  defp gen_code_for_tests(tests, whole_expr, stack) do
    quote do
      stack = unquote(stack)
      try do
        # Put all tests into one context
        unquote_splicing(tests)
      rescue
        e in [ExUnit.AssertionError] ->
          reraise e, stack

        error ->
          original_stack = System.stacktrace
          reraise ExUnit.AssertionError,
            [message: "Doctest failed: got #{inspect(error.__struct__)} with message " <> inspect(Exception.message(error)),
             expr: unquote(String.trim(whole_expr))],
            original_stack
      end
    end
  end

  defp test_case_content(expr, {:test, expected}, location, stack) do
    expr_ast     = string_to_quoted(location, stack, expr)
    expected_ast = string_to_quoted(location, stack, expected)

    quote do
      expected = unquote(expected_ast)
      case unquote(expr_ast) do
        ^expected -> :ok
        actual ->
          reraise ExUnit.AssertionError,
            [message: "Doctest failed",
             expr: "#{unquote(String.trim(expr))} === #{unquote(String.trim(expected))}",
             left: actual],
            unquote(stack)
      end
    end
  end

    case String.trim_leading(line) do
      "" ->
        raise_incomplete_doctest(line_no, module)

      ^stripped_line ->
        :ok

      _ ->
        n_spaces = if indent == 1, do: "#{indent} space", else: "#{indent} spaces"

        raise Error,
          line: line_no,
          module: module,
          message: "indentation level mismatch: #{inspect(line)}, should have been #{n_spaces}"
    end

    adjusted_lines = [{stripped_line, line_no} | adjusted_lines]
