1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768(*
* Copyright (c) 2022 Antonin Décimo <antonin@tarides.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)(** Best-effort reporting of the location of the call to Alcotest.check. *)letcheck_callercallerentry=matchPrintexc.backtrace_slots_of_raw_entryentrywith|Some[|slot|]->(matchPrintexc.Slot.nameslotwith|Somenamewhencaller=name->true|_->false)|_->falseletget?(__FUNCTION__="Alcotest_engine__Test.check")()=letcaller=__FUNCTION__inletopenPrintexcinletcallstack_depth=3(* this function, caller, bound of test *)inletraw_backtrace=get_callstackcallstack_depthinletentries=raw_backtrace_entriesraw_backtraceinifArray.lengthentries>=callstack_depth&&check_callercaller(Array.unsafe_getentries1)thenmatchbacktrace_slots_of_raw_entry(Array.unsafe_getentries2)with|Some[|slot|]->(matchSlot.nameslotwith|SomeboundwhenAlcotest_stdlib_ext.String.(is_prefix~affix:"Alcotest_engine__Core."bound||is_prefix~affix:"Alcotest_lwt."bound||is_prefix~affix:"Alcotest_async."bound||is_prefix~affix:"Alcotest_mirage."bound)->None|Some_->Option.map(fun{filename;line_number;start_char;end_char=_}->{Lexing.pos_fname=filename;pos_lnum=line_number;pos_bol=0;pos_cnum=start_char;})(Slot.locationslot)|None->None)|_->NoneelseNoneletget?__FUNCTION__()=letguess=matchSys.getenv"ALCOTEST_SOURCE_CODE_POSITION"with|""|"false"|"no"|"n"|"0"->false|"true"|"yes"|"y"|"1"->true|_|(exception_)->trueinifguessthenget?__FUNCTION__()elseNone