let result_full_of_exception ctxt e =
let backtrace () =
if Printexc.backtrace_status () then
Some (Printexc.get_backtrace ())
else
None
in
let locate_exn () =
if Printexc.backtrace_status () then
begin
let lst =
extract_backtrace_position (Printexc.get_backtrace ())
in
let pos_opt =
try
List.find
(function
| None -> false
| Some (fn, _) ->
not (starts_with ~prefix:"oUnit" (Filename.basename fn)) &&
not (List.mem fn standard_modules))
lst
with Not_found ->
None
in
match pos_opt with
| Some (filename, line) ->
Some {OUnitLogger.filename = filename; line = line}
| None ->
None
end
else
None
in
let result =
match e with
| OUnit_failure s -> RFailure (s, locate_exn (), backtrace ())
| Skip s -> RSkip s
| Todo s -> RTodo s
| s -> RError (Printexc.to_string s, backtrace ())
in
let position =
match result with
| RSuccess | RSkip _ | RTodo _ | RTimeout _ ->
None
| RFailure _ | RError _ ->
OUnitLogger.position ctxt.logger
in
ctxt.path, result, position