Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_expect_evaluator.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240openBaseopenStdioopenExpect_test_commonopenExpect_test_matchermoduleTest_result=Ppx_inline_test_lib.Runtime.Test_resultmoduleCollector_test_outcome=Expect_test_collector.Test_outcomemoduleObj=structmoduleExtension_constructor=struct[@@@ocaml.warning"-3"]letof_val=Caml.Obj.extension_constructorletname=Caml.Obj.extension_nameendendtypegroup={filename:File.Name.t;file_contents:string;tests:Matcher.Test_outcome.tMap.M(File.Location).t}letconvert_collector_test~allow_output_patterns(test:Collector_test_outcome.t):File.Location.t*Matcher.Test_outcome.t=letsaved_output=Map.of_alist_multi(moduleFile.Location)test.saved_output|>Map.map~f:Matcher.Saved_output.of_nonempty_list_exninletexpectations=List.maptest.expectations~f:(fun(expect:Expectation.Raw.t)->(expect.extid_location,Expectation.map_prettyexpect~f:(Lexer.parse_pretty~allow_output_patterns)))|>Map.of_alist_exn(moduleFile.Location)inletuncaught_exn=matchtest.uncaught_exnwith|None->None|Some(exn,bt)->letexn=tryExn.to_stringexnwith|exn->letname=Obj.Extension_constructor.of_valexn|>Obj.Extension_constructor.nameinPrintf.sprintf"(\"%s(Cannot print more details, Exn.to_string failed)\")"nameinSome(matchCaml.Printexc.raw_backtrace_to_stringbtwith|""->exn|bt->Expect_test_config_types.Upon_unreleasable_issue.message_when_expectation_contains_backtracetest.upon_unreleasable_issue^exn^"\n"^bt)inletuncaught_exn,trailing_output=matchuncaught_exn,test.trailing_outputwith|None,_|_,""->uncaught_exn,test.trailing_output|Someuncaught_exn,trailing_output->(Some(String.concat~sep:"\n"[uncaught_exn;"Trailing output";"---------------";trailing_output]),"")inletuncaught_exn_expectation=Option.maptest.uncaught_exn_expectation~f:(funexpect->Expectation.map_prettyexpect~f:(Lexer.parse_pretty~allow_output_patterns))in(test.location,{expectations;saved_output;trailing_output=Matcher.Saved_output.of_nonempty_list_exn[trailing_output];uncaught_exn=Option.mapuncaught_exn~f:(funs->Matcher.Saved_output.of_nonempty_list_exn[s]);uncaught_exn_expectation;upon_unreleasable_issue=test.upon_unreleasable_issue});;letdir_seps='/'::(ifSys.win32then['\\';':']else[])letresolve_filenamefilename=letrelative_to=matchPpx_inline_test_lib.Runtime.source_tree_rootwith|None->File.initial_dir()|Someroot->ifCaml.Filename.is_relativerootthen(letinitial_dir=File.initial_dir()in(* Simplification for the common case where [root] is of the form [(../)*..] *)letl=String.split_on_charsroot~on:dir_sepsinifList.for_alll~f:(String.equalCaml.Filename.parent_dir_name)thenList.fold_leftl~init:initial_dir~f:(fundir_->Caml.Filename.dirnamedir)elseCaml.Filename.concatinitial_dirroot)elserootinFile.Name.relative_to~dir:relative_tofilename;;letcreate_group~allow_output_patterns(filename,tests)=letmoduleD=File.Digestinletexpected_digest=matchList.maptests~f:(fun(t:Collector_test_outcome.t)->t.file_digest)|>List.dedup_and_sort~compare:D.comparewith|[digest]->digest|[]->assertfalse|digests->Printf.ksprintffailwith"Expect tests make inconsistent assumption about file \"%s\" %s"(File.Name.to_stringfilename)(Sexp.to_string_hum(List.sexp_of_tD.sexp_of_tdigests))inletfile_contents=In_channel.read_all(resolve_filenamefilename)inletcurrent_digest=Caml.Digest.stringfile_contents|>Caml.Digest.to_hex|>D.of_stringinifD.compareexpected_digestcurrent_digest<>0thenPrintf.ksprintffailwith"File \"%s\" changed, you need rebuild inline_tests_runner to be able to run \
expect tests (expected digest: %s, current digest: %s)"(File.Name.to_stringfilename)(D.to_stringexpected_digest)(D.to_stringcurrent_digest);lettests=List.maptests~f:(convert_collector_test~allow_output_patterns)|>Map.of_alist_reduce(moduleFile.Location)~f:Matcher.Test_outcome.merge_exnin{filename;file_contents;tests};;letconvert_collector_tests~allow_output_patternstests:grouplist=List.maptests~f:(fun(test:Collector_test_outcome.t)->test.location.filename,test)|>Map.of_alist_multi(moduleFile.Name)|>Map.to_alist|>List.map~f:(create_group~allow_output_patterns);;letprocess_group~use_color~in_place~diff_command~allow_output_patterns{filename;file_contents;tests}:Test_result.t=letbad_outcomes=Map.foldtests~init:[]~f:(fun~key:location~data:testacc->matchMatcher.evaluate_test~file_contents~locationtest~allow_output_patternswith|Match->acc|Correctionc->c::acc)|>List.revinletfilename=resolve_filenamefilenameinletdot_corrected=filename^".corrected"inletremovefile=ifCaml.Sys.file_existsfilethenCaml.Sys.removefileinmatchbad_outcomeswith|[]->removedot_corrected;Success|_->letno_diff=matchdiff_commandwith|Some"-"->true|None|Some_->falseinletwrite_corrected~file=Matcher.write_correctedbad_outcomes~file~file_contents~mode:Inline_expect_testin(matchin_placewith|true->write_corrected~file:filename;removedot_corrected;Success|false->(matchno_diffwith|true->write_corrected~file:dot_corrected;Success|false->lettmp_corrected=(* We need a temporary file for corrections to allow [Ppxlib_print_diff] to work when
multiple inline_tests_runner are run simultaneously. Otherwise one copy may
remove the corrected file before the other can print the diff. *)Caml.Filename.temp_file(Caml.Filename.basenamefilename)".corrected.tmp"~temp_dir:(Caml.Filename.dirnamefilename)inwrite_corrected~file:tmp_corrected;Ppxlib_print_diff.print~file1:filename~file2:tmp_corrected~use_color?diff_command();Caml.Sys.renametmp_correcteddot_corrected;Failure));;letevaluate_tests~use_color~in_place~diff_command~allow_output_patterns=convert_collector_tests(Expect_test_collector.tests_run())~allow_output_patterns|>List.map~f:(fungroup->matchprocess_group~use_color~in_place~diff_command~allow_output_patternsgroupwith|exceptionexn->letbt=Caml.Printexc.get_raw_backtrace()inraise_s(Sexp.message"Expect test evaluator bug"["exn",sexp_of_exnexn;"backtrace",Atom(Caml.Printexc.raw_backtrace_to_stringbt);"filename",File.Name.sexp_of_tgroup.filename])|res->res)|>Test_result.combine_all;;let()=Ppx_inline_test_lib.Runtime.add_evaluator~f:(fun()->evaluate_tests~use_color:Ppx_inline_test_lib.Runtime.use_color~in_place:Ppx_inline_test_lib.Runtime.in_place~diff_command:Ppx_inline_test_lib.Runtime.diff_command~allow_output_patterns:Ppx_inline_test_lib.Runtime.allow_output_patterns);;