Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file expect_test_helpers_base.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307open!Baseopen!Stdioinclude(Expect_test_helpers_base_intf:moduletypeofstructincludeExpect_test_helpers_base_intfendwithmoduleCR:=Expect_test_helpers_base_intf.CRwithmoduleSexp_style:=Expect_test_helpers_base_intf.Sexp_style)letprint_stringstring=print_stringstring;Out_channel.(flushstdout);;moduleCR=structincludeExpect_test_helpers_base_intf.CRletmessagethere=letcrcr=String.concat["(* ";cr;" require-failed: ";here|>Source_code_position.to_string;".\n";" Do not 'X' this CR; instead make the required property true,\n";" which will make the CR disappear. For more information, see\n";" [Expect_test_helpers_base.require]. *)"]inmatchtwith|CR->cr"CR"|CR_soon->cr"CR-soon"|CR_someday->cr"CR-someday"|Comment->String.concat["(* require-failed: ";here|>Source_code_position.to_string;". *)"];;lethide_unstable_output=function|CR->false|CR_soon|CR_someday|Comment->true;;endmoduleSexp_style=structincludeExpect_test_helpers_base_intf.Sexp_styleletdefault_pretty=Pretty(Sexp_pretty.Config.create~color:false())letsimple_pretty=Pretty{indent=1;data_alignment=Data_not_aligned;color_scheme=[||];atom_coloring=Color_none;atom_printing=Escaped;paren_coloring=false;opening_parens=Same_line;closing_parens=Same_line;comments=Drop;singleton_limit=Singleton_limit(Atom_threshold0,Character_threshold0);leading_threshold=Atom_threshold0,Character_threshold0;separator=No_separator;sticky_comments=false};;endlethide_positions_in_string=letmoduleRe=Re.Pcreinletexpanders=lazy([(* This first pattern has an alphabetic prefix because we want to match exceptions
and their file positions without also matching timestamps. However, [Re.Pcre]
doesn't implement back-references, precluding a simple substitution. Instead,
we provide a length of matched data to copy into the output, effectively acting
like a back-reference in this special case. *)"[a-zA-z]:[0-9]+:[0-9]+",1,":LINE:COL";"line [0-9]+:",0,"line LINE:";"line [0-9]+, characters [0-9]+-[0-9]+",0,"line LINE, characters C1-C2"]|>List.map~f:(fun(pattern,prefix_len,expansion)->letrex=Re.regexppatterninfunstring->Re.substitute~rexstring~subst:(funorig->String.concat[String.prefixorigprefix_len;expansion])))infunstring->List.fold(forceexpanders)~init:string~f:(funacexpander->expanderac);;letmaybe_hide_positions_in_string?(hide_positions=false)string=ifhide_positionsthenhide_positions_in_stringstringelsestring;;letsexp_style=refSexp_style.default_prettyletsexp_to_string?hide_positionssexp=letstring=match!sexp_stylewith|To_string_mach->Sexp.to_string_machsexp^"\n"|To_string_hum->Sexp.to_string_humsexp^"\n"|Prettyconfig->Sexp_pretty.pretty_stringconfigsexpinmaybe_hide_positions_in_string?hide_positionsstring;;letprint_s?hide_positionssexp=print_string(sexp_to_string?hide_positionssexp)leton_print_cr=refprint_endlineletprint_cr_with_optional_message?(cr=CR.CR)?(hide_positions=CR.hide_unstable_outputcr)hereoptional_message=letcr=CR.messagecrhere|>maybe_hide_positions_in_string~hide_positionsin!on_print_cr(matchoptional_messagewith|None->cr|Somesexp->String.concat[cr;"\n";String.rstrip(sexp_to_string~hide_positionssexp)]);;letprint_cr?cr?hide_positionsheremessage=print_cr_with_optional_message?cr?hide_positionshere(Somemessage);;letrequire?cr?hide_positions?if_false_then_print_sherebool=matchboolwith|true->()|false->print_cr_with_optional_message?cr?hide_positionshere(Option.mapif_false_then_print_s~f:force);;letrequire_equal(typea)?cr?hide_positions?if_false_then_print_s?(message="values are not equal")here(moduleM:With_equalwithtypet=a)xy=require?cr?hide_positionshere(M.equalxy)~if_false_then_print_s:(lazy[%messagemessage~_:(x:M.t)~_:(y:M.t)~_:(if_false_then_print_s:Sexp.tLazy.tsexp_option)]);;letrequire_compare_equal(typea)?cr?hide_positions?messagehere(moduleM:With_comparewithtypet=a)xy=require_equal?cr?hide_positions?messagehere(modulestructincludeMletequal=[%compare.equal:t]end)xy;;letrequire_sets_are_equal(typea)?cr?hide_positions?(names="first","second")here(moduleM:Setwithtypet=a)firstsecond=require?cr?hide_positionshere(M.equalfirstsecond)~if_false_then_print_s:(lazy(letshow_diff(name1,set1)(name2,set2)=letdiff=M.diffset1set2inifM.is_emptydiffthen[%message]else[%message(Printf.sprintf"in %s but not in %s"name1name2)~_:(diff:M.t)]inletfirst=fstnames,firstinletsecond=sndnames,secondin[%message.omit_nil"sets are not equal"~_:(show_difffirstsecond:Sexp.t)~_:(show_diffsecondfirst:Sexp.t)]));;typetry_with_result=|Did_not_raise|RaisedofSexp.tlettry_with?raise_message?(show_backtrace=false)(typea)(f:unit->a)=Backtrace.Exn.with_recordingshow_backtrace~f:(fun()->matchignore(f():a)with|()->Did_not_raise|exceptionexn->letbacktrace=ifnotshow_backtracethenNoneelseSome(Backtrace.Exn.most_recent())inRef.set_temporarilyBacktrace.elide(notshow_backtrace)~f:(fun()->Raised[%message""~_:(raise_message:stringsexp_option)~_:(exn:exn)(backtrace:Backtrace.tsexp_option)]));;letrequire_does_not_raise?cr?hide_positions?show_backtraceheref=matchtry_withf?show_backtrace~raise_message:"unexpectedly raised"with|Did_not_raise->()|Raisedmessage->print_cr?cr?hide_positionsheremessage;;letrequire_does_raise?cr?hide_positions?show_backtraceheref=matchtry_withf?show_backtracewith|Raisedmessage->print_s?hide_positionsmessage|Did_not_raise->print_cr?cr?hide_positionshere[%message"did not raise"];;letshow_raise(typea)?hide_positions?show_backtrace(f:unit->a)=print_s?hide_positions(matchtry_withf?show_backtrace~raise_message:"raised"with|Did_not_raise->[%message"did not raise"]|Raisedmessage->message);;letquickcheck(typea)here?cr?hide_positions?(seed=Base_quickcheck.Test.default_config.seed)?(sizes=Base_quickcheck.Test.default_config.sizes)?(trials=Base_quickcheck.Test.default_config.test_count)?(shrinker=Base_quickcheck.Shrinker.atomic)?(shrink_attempts=Base_quickcheck.Test.default_config.shrink_count)?examples~sexp_of~fquickcheck_generator=matchBase_quickcheck.Test.run~config:{seed;test_count=trials;shrink_count=shrink_attempts;sizes}?examples(modulestructtypet=aletsexp_of_t=sexp_ofletquickcheck_generator=quickcheck_generatorletquickcheck_shrinker=shrinkerend)~f:(funelt->letcr_count=ref0inletoriginal_on_print_cr=!on_print_crinRef.set_temporarilyon_print_cr(funstring->Int.incrcr_count;original_on_print_crstring)~f:(fun()->felt);if!cr_count>0thenOr_error.errorf"printed %d CRs for Quickcheck-generated input"!cr_countelseOk())with|Ok()->()|Errorerror->print_crhere?cr?hide_positions[%sexp(error:Error.t)];;