Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file expect_test_helpers_core.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320open!CoreincludeExpect_test_helpers_baseincludeExpect_test_helpers_core_intfmoduleAllocation_limit=structincludeAllocation_limitletis_okt~major_words_allocated~minor_words_allocated=matchtwith|Major_wordsn->major_words_allocated<=n|Minor_wordsn->major_words_allocated=0&&minor_words_allocated<=n;;letshow_major_words=function|Major_words_->true|Minor_words_->false;;endmoduletypeInt63able=sigtypetvalto_int63:t->Int63.tvalof_int63_exn:Int63.t->tendletprint_and_check_stable_internal(typea)?cr?hide_positions?max_binable_lengthhere(moduleM:Stable_without_comparatorwithtypet=a)(int63able:(moduleInt63ablewithtypet=a)option)list=letequal=[%compare.equal:M.t]inprint_s?hide_positions[%message""~bin_shape_digest:(Bin_prot.Shape.eval_to_digest_stringM.bin_shape_t:string)];require_does_not_raise?cr?hide_positionshere(fun()->List.iterlist~f:(funoriginal->letsexp=M.sexp_of_toriginalinletbin_io=Binable.to_string(moduleM)originalinletint63=Option.mapint63able~f:(fun(moduleI)->I.to_int63original)inprint_s?hide_positions[%message""(sexp:Sexp.t)(bin_io:string)(int63:(Int63.toption[@sexp.option]))];letsexp_roundtrip=M.t_of_sexpsexpinrequire?cr?hide_positionshere(equaloriginalsexp_roundtrip)~if_false_then_print_s:(lazy[%message"sexp serialization failed to round-trip"(original:M.t)(sexp:Sexp.t)(sexp_roundtrip:M.t)]);letbin_io_roundtrip=Binable.of_string(moduleM)bin_ioinrequire?cr?hide_positionshere(equaloriginalbin_io_roundtrip)~if_false_then_print_s:(lazy[%message"bin-io serialization failed to round-trip"(original:M.t)(bin_io:string)(bin_io_roundtrip:M.t)]);(matchmax_binable_lengthwith|None->()|Somemax_binable_length->letbin_io_length=String.lengthbin_ioinrequire?cr?hide_positionshere(bin_io_length<=max_binable_length)~if_false_then_print_s:(lazy[%message"bin-io serialization exceeds max binable length"(original:M.t)(bin_io:string)(bin_io_length:int)(max_binable_length:int)]));matchint63ablewith|None->()|Some(moduleI)->letint63=Option.value_exnint63inletint63_roundtrip=I.of_int63_exnint63inrequire?cr?hide_positionshere(equaloriginalint63_roundtrip)~if_false_then_print_s:(lazy[%message"int63 serialization failed to round-trip"(original:M.t)(int63:Int63.t)(int63_roundtrip:M.t)])));;letprint_and_check_stable_type(typea)?cr?hide_positions?max_binable_lengthhere(moduleM:Stable_without_comparatorwithtypet=a)list=print_and_check_stable_internal?cr?hide_positions?max_binable_lengthhere(moduleM)Nonelist;;letprint_and_check_stable_int63able_type(typea)?cr?hide_positions?max_binable_lengthhere(moduleM:Stable_int63ablewithtypet=a)list=print_and_check_stable_internal?cr?hide_positions?max_binable_lengthhere(moduleM)(Some(moduleM))list;;letrequire_allocation_does_not_exceed_private?(cr=CR.CR)?hide_positionsallocation_limitheref=let(x,{Gc.For_testing.Allocation_report.major_words_allocated;minor_words_allocated},allocs)=Gc.For_testing.measure_and_log_allocationfinrequirehere~cr?hide_positions(Allocation_limit.is_okallocation_limit~major_words_allocated~minor_words_allocated)~if_false_then_print_s:(lazy(letminor_words_allocated,major_words_allocated=ifCR.hide_unstable_outputcrthenNone,Noneelseifmajor_words_allocated>0||Allocation_limit.show_major_wordsallocation_limitthenSomeminor_words_allocated,Somemajor_words_allocatedelseSomeminor_words_allocated,Noneinifnot(CR.hide_unstable_outputcr)thenList.iterallocs~f:(fun{size_in_words;is_major;backtrace}->Printf.printf"Allocation of %d %s words occurred at:\n%s\n"size_in_words(ifis_majorthen"major"else"minor")backtrace);[%message"allocation exceeded limit"(allocation_limit:Allocation_limit.t)(minor_words_allocated:(intoption[@sexp.option]))(major_words_allocated:(intoption[@sexp.option]))]));x;;letrequire_allocation_does_not_exceed?hide_positionsallocation_limitheref=require_allocation_does_not_exceed_private?hide_positionsallocation_limitheref;;letrequire_no_allocation?hide_positionsheref=require_allocation_does_not_exceed?hide_positions(Minor_words0)heref;;letprint_and_check_comparable_sexps(typea)?cr?hide_positionshere(moduleM:With_comparablewithtypet=a)list=letset=Set.of_list(moduleM)listinletset_sexp=[%sexp(set:M.Set.t)]inprint_s[%message"Set"~_:(set_sexp:Sexp.t)];letsorted_list_sexp=[%sexp(List.sortlist~compare:M.compare:M.tlist)]inrequire?cr?hide_positionshere(Sexp.equalset_sexpsorted_list_sexp)~if_false_then_print_s:(lazy[%message"set sexp does not match sorted list sexp"(set_sexp:Sexp.t)(sorted_list_sexp:Sexp.t)]);letalist=List.mapilist~f:(funix->x,i)inletmap=Map.of_alist_exn(moduleM)alistinletmap_sexp=[%sexp(map:intM.Map.t)]inprint_s[%message"Map"~_:(map_sexp:Sexp.t)];letsorted_alist_sexp=[%sexp(List.sortalist~compare:(fun(x,_)(y,_)->M.comparexy):(M.t*int)list)]inrequire?cr?hide_positionshere(Sexp.equalmap_sexpsorted_alist_sexp)~if_false_then_print_s:(lazy[%message"map sexp does not match sorted alist sexp"(map_sexp:Sexp.t)(sorted_alist_sexp:Sexp.t)]);;letprint_and_check_hashable_sexps(typea)?cr?hide_positionshere(moduleM:With_hashablewithtypet=a)list=lethash_set=Hash_set.of_list(moduleM)listinlethash_set_sexp=[%sexp(hash_set:M.Hash_set.t)]inprint_s[%message"Hash_set"~_:(hash_set_sexp:Sexp.t)];letsorted_list_sexp=[%sexp(List.sortlist~compare:M.compare:M.tlist)]inrequire?cr?hide_positionshere(Sexp.equalhash_set_sexpsorted_list_sexp)~if_false_then_print_s:(lazy[%message"hash_set sexp does not match sorted list sexp"(hash_set_sexp:Sexp.t)(sorted_list_sexp:Sexp.t)]);letalist=List.mapilist~f:(funix->x,i)inlettable=Hashtbl.of_alist_exn(moduleM)alistinlettable_sexp=[%sexp(table:intM.Table.t)]inprint_s[%message"Table"~_:(table_sexp:Sexp.t)];letsorted_alist_sexp=[%sexp(List.sortalist~compare:(fun(x,_)(y,_)->M.comparexy):(M.t*int)list)]inrequire?cr?hide_positionshere(Sexp.equaltable_sexpsorted_alist_sexp)~if_false_then_print_s:(lazy[%message"table sexp does not match sorted alist sexp"(table_sexp:Sexp.t)(sorted_alist_sexp:Sexp.t)]);;letprint_and_check_container_sexps(typea)?cr?hide_positionsheremlist=let(moduleM:With_containerswithtypet=a)=minprint_and_check_comparable_sexps?cr?hide_positionshere(moduleM)list;print_and_check_hashable_sexps?cr?hide_positionshere(moduleM)list;;letremove_time_spans=letspan_regex=lazy(letsign=Re.set"-+"inletpart=letinteger=Re.rep1Re.digitinletdecimal=Re.opt(Re.seq[Re.char'.';Re.rep1Re.digit])inletsuffixes=List.map~f:Re.str["d";"h";"m";"s";"ms";"us";"ns"]inRe.seq[integer;decimal;Re.altsuffixes]inRe.compile(Re.seq[Re.optsign;Re.word(Re.rep1part)]))infunstring->Re.replace_string(forcespan_regex)~by:"SPAN"string;;moduleExpect_test_helpers_core_private=structletrequire_allocation_does_not_exceed=require_allocation_does_not_exceed_privateend