 
     quote do
       expected = unquote(expected_ast)
-
-      case unquote(expr_ast) do
-        ^expected ->
-          :ok
-
-        actual ->
-          doctest = unquote(doctest)
-
-          expr =
-            "#{unquote(Macro.to_string(last_expr_ast))} === #{unquote(String.trim(expected))}"
-
-          error = [
-            message: "Doctest failed",
-            doctest: doctest,
-            expr: expr,
-            left: actual,
-            right: expected
-          ]
-
-          reraise ExUnit.AssertionError, error, unquote(stack)
-      end
+      doctest = unquote(doctest)
+      expr = <<unquote(Macro.to_string(last_expr_ast)), " === ", unquote(String.trim(expected))>>
+      stack = unquote(stack)
+
+      ExUnit.DocTest.__test__(unquote(expr_ast), expected, doctest, expr, stack)
     end
   end
 

      exception = unquote(exception)
      doctest = unquote(doctest)
      message = unquote(message)

      try do
        unquote(expr_ast)
      rescue
        error ->
          actual_exception = error.__struct__
          actual_message = Exception.message(error)

          message =
            cond do
              actual_exception != exception ->
                "Doctest failed: expected exception #{inspect(exception)} but got " <>
                  "#{inspect(actual_exception)} with message #{inspect(actual_message)}"

              actual_message != message ->
                "Doctest failed: wrong message for #{inspect(actual_exception)}\n" <>
                  "expected:\n" <>
                  "  #{inspect(message)}\n" <>
                  "actual:\n" <> "  #{inspect(actual_message)}"

              true ->
                nil
            end

          if message do
            reraise ExUnit.AssertionError, [message: message, doctest: doctest], stack
          end
      else
        _ ->
          message =
            "Doctest failed: expected exception #{inspect(exception)} but nothing was raised"

          error = [message: message, doctest: doctest]
          reraise ExUnit.AssertionError, error, stack
      end
    end
  end


    doctest = "\n" <> formatted <> "\n" <> expected
    expr_ast = string_to_quoted(location, stack, expr, doctest) |> insert_assertions()
    expected_ast = string_to_quoted(location, stack, expected, doctest)
    last_expr_ast = Macro.to_string(last_expr(expr_ast))

    quote do
      expected = unquote(expected_ast)
      value = unquote(expr_ast)
      doctest = unquote(doctest)
      expr = <<"inspect(", unquote(last_expr_ast), ") === ", unquote(String.trim(expected))>>
      stack = unquote(stack)

      ExUnit.DocTest.__inspect__(value, expected, doctest, expr, stack)
    end
  end

