Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_inline_test.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247openBaseopenPpxlibopenAst_builder.Default(* Generated code should depend on the environment in scope as little as
possible. E.g. rather than [foo = []] do [match foo with [] ->], to eliminate the
use of [=]. It is especially important to not use polymorphic comparisons, since we
are moving more and more to code that doesn't have them in scope. *)typemaybe_drop=|Keep|Drop_with_deadcode|Dropletmaybe_drop_mode=refKeepletset_default_maybe_dropx=maybe_drop_mode:=xlet()=Driver.add_arg"-inline-test-drop"(Unit(fun()->maybe_drop_mode:=Drop))~doc:" Drop unit tests";Driver.add_arg"-inline-test-drop-with-deadcode"(Unit(fun()->maybe_drop_mode:=Drop_with_deadcode))~doc:" Drop unit tests by wrapping them inside deadcode to prevent \
unused variable warnings.";;;let()=Driver.Cookies.add_simple_handler"inline-test"Ast_pattern.(pexp_ident(lident__'))~f:(function|None->()|Someid->matchid.txtwith|"drop"->maybe_drop_mode:=Drop|"drop_with_deadcode"->maybe_drop_mode:=Drop_with_deadcode|s->Location.raise_errorf~loc:id.loc"invalid 'inline-test' cookie (%s), expected one of: drop, drop_with_deadcode"s)letmaybe_droploccode=match!maybe_drop_modewith|Keep->[%strlet()=[%ecode]]|Drop_with_deadcode->[%strlet()=iffalsethen[%ecode]else()]|Drop->Attribute.explicitly_drop#expressioncode;[%str]letrecshort_desc_of_expr~max_lene=matche.pexp_descwith|Pexp_let(_,_,e)|Pexp_letmodule(_,_,e)->short_desc_of_expr~max_lene|_->lets=Pprintast.string_of_expressioneinletres=ifString.lengths>=max_lenthenlets_short=String.subs~pos:0~len:(max_len-5)ins_short^"[...]"elsesinString.mapres~f:(function|'\n'->' '|c->c);;letdescr~(loc:Location.t)?(inner_loc=loc)e_optid_opt=letfilename=File_path.get_default_pathlocinletline=loc.loc_start.pos_lnuminletstart_pos=loc.loc_start.pos_cnum-loc.loc_start.pos_bolinletend_pos=inner_loc.Location.loc_end.pos_cnum-loc.loc_start.pos_bolinletdescr=matchid_opt,e_optwith|None,None->""|None,Somee->": <<"^short_desc_of_expr~max_len:50e^">>"|Someid,_->": "^idin(estring~locdescr,estring~locfilename,eint~locline,eint~locstart_pos,eint~locend_pos);;letapply_to_descrlid~loc?inner_loce_optid_opttagsmore_arg=letdescr,filename,line,start_pos,end_pos=descr~loc?inner_loce_optid_optinletexpr=pexp_apply~loc(evar~loc("Ppx_inline_test_lib.Runtime."^lid))[Labelled"config",[%expr(moduleInline_test_config)];Labelled"descr",descr;Labelled"tags",elist~loc(List.map~f:(estring~loc)tags);Labelled"filename",filename;Labelled"line_number",line;Labelled"start_pos",start_pos;Labelled"end_pos",end_pos;Nolabel,more_arg]inmaybe_droplocexpr;;letcan_use_test_extensions()=match!maybe_drop_mode,Ppx_inline_test_libname.get()with|Keep,None->false|(Drop|Drop_with_deadcode),_|_,Some_->true;;(* Set to [true] when we see a [let%test] or [let%expect_test] etc extension. *)moduleHas_tests=Driver.Create_file_property(structletname="ppx_inline_test.has_tests"end)(Bool)letall_tags=["no-js";"js-only";"64-bits-only";"32-bits-only";"x-library-inlining-sensitive"]letvalidate_tagtag=ifnot(List.memall_tagstag~equal:String.equal)thenError(Spellcheck.spellcheckall_tagstag)elseOk()letvalidate_extension_point_exn~name_of_ppx_rewriter~loc~tags=Has_tests.settrue;ifnot(can_use_test_extensions())thenLocation.raise_errorf~loc"%s: extension is disabled because the tests would be ignored \
(the build system didn't pass -inline-test-lib)"name_of_ppx_rewriter;List.itertags~f:(funtag->matchvalidate_tagtagwith|Ok()->()|Errorhint->lethint=matchhintwith|None->""|Somehint->"\n"^hintinLocation.raise_errorf~loc"%s: %S is not a valid tag for inline tests.%s"name_of_ppx_rewritertaghint);;letname_of_ppx_rewriter="ppx_inline_test"letexpand_test~loc~path:_~name:id~tagse=validate_extension_point_exn~name_of_ppx_rewriter~loc~tags;apply_to_descr"test"~loc(Somee)idtags(pexp_fun~locNolabelNone(punit~loc)e);;letexpand_test_unit~loc~path:_~name:id~tagse=validate_extension_point_exn~name_of_ppx_rewriter~loc~tags;apply_to_descr"test_unit"~loc(Somee)idtags(pexp_fun~locNolabelNone(punit~loc)e);;letexpand_test_module~loc~path:_~name:id~tagsm=validate_extension_point_exn~name_of_ppx_rewriter~loc~tags;apply_to_descr"test_module"~loc~inner_loc:m.pmod_locNoneidtags(pexp_fun~locNolabelNone(punit~loc)(pexp_letmodule~loc(Located.mk~loc"M")m(eunit~loc)));;moduleE=structopenAst_patternlettags=Attribute.declare"tags"Attribute.Context.pattern(single_expr_payload(pexp_tuple(many(estring__))|||map(estring__)~f:(funfx->f[x])))(funx->x)letlist_of_option=function|None->[]|Somex->xletopt_name()=map(pstring__)~f:(funfx->f(Somex))|||mapppat_any~f:(funf->fNone)letopt_name_and_exprexpr=pstr((pstr_valuenonrecursive((value_binding~pat:(map(Attribute.patterntags(opt_name()))~f:(funfattributesname_opt->f~name:name_opt~tags:(list_of_optionattributes)))~expr)^::nil))^::nil)lettest=Extension.declare_inline"inline_test.test"Extension.Context.structure_item(opt_name_and_expr__)expand_testlettest_unit=Extension.declare_inline"inline_test.test_unit"Extension.Context.structure_item(opt_name_and_expr__)expand_test_unitlettest_module=Extension.declare_inline"inline_test.test_module"Extension.Context.structure_item(opt_name_and_expr(pexp_pack__))expand_test_moduleletall=[test;test_unit;test_module]endlettags=E.tagsletopt_name_and_expr=E.opt_name_and_exprlet()=Driver.register_transformation"inline-test"~extensions:E.all~enclose_impl:(funloc->matchloc,Ppx_inline_test_libname.get()with|None,_|_,None->([],[])|Someloc,Some(libname,partition)->(* See comment in benchmark_accumulator.ml *)letheader=letloc={locwithloc_end=loc.loc_start}inmaybe_droploc[%exprPpx_inline_test_lib.Runtime.set_lib_and_partition[%eestring~loclibname][%eestring~locpartition]]andfooter=letloc={locwithloc_start=loc.loc_end}inmaybe_droploc[%exprPpx_inline_test_lib.Runtime.unset_lib[%eestring~loclibname]]in(header,footer));;