123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107moduleManifest=Extism_manifestmoduleError=ErrormodulePlugin=PluginmoduleFunction=FunctionmoduleHost_function=Host_functionmoduleType=TypemoduleVal=ValmoduleVal_type=Val_typeletextism_version=Bindings.extism_versionletwith_pluginfp=Fun.protect~finally:(fun()->Plugin.freep)(fun()->fp)let%test"with_plugin"=letmanifest=Manifest.(create[Wasm.file"test/code.wasm"])inletplugin=Plugin.of_manifestmanifest|>Error.unwrapinletb=with_plugin(funplugin->Plugin.callType.stringType.stringplugin~name:"count_vowels""this is a test"|>Error.unwrap="{\"count\":4,\"total\":4,\"vowels\":\"aeiouAEIOU\"}")plugininPlugin.freeplugin;Gc.minor();Gc.full_major();blet%test_=String.length(extism_version())>0letparse_level=Option.map(function|`Error->"error"|`Warn->"warn"|`Info->"info"|`Debug->"debug"|`Trace->"trace"|`Filterf->f)letset_log_file?levelfilename=Bindings.extism_log_filefilename(parse_levellevel)typedrain_logs=unit->unitletmk_drain_logsf()=letfxslength=lets=Ctypes.string_from_ptrs~length:(Ctypes.Uintptr.to_intlength)infsinBindings.extism_log_drainfxletset_log_custom?levelf=ifBindings.extism_log_custom(parse_levellevel)thenletx=mk_drain_logsfinlet()=Gc.finalise_last(mk_drain_logsf)xinxelseError.throw(`Msg"Unable to set custom logging")let%test_=letlog_file=tryString.length@@Unix.getenv"TEST_LOG_FILE">0withNot_found->falseiniflog_filethenset_log_file~level:`Trace"stderr"elseletcount=ref0inlet_drain_logs=set_log_custom~level:`Trace(funs->incrcount;print_strings)inletmanifest=Manifest.(create[Wasm.file"test/code.wasm"])inletplugin=Plugin.of_manifestmanifest|>Error.unwrapinlet_=Plugin.callType.stringType.stringplugin~name:"count_vowels""this is a test"in(* Make sure logs are drained when drain_logs is garbage collected *)Gc.minor();Gc.full_major();!count>0let%test_=letmanifest=Manifest.(create[Wasm.file"test/code.wasm"])inletcompiled=Plugin.Compiled.of_manifest_exnmanifestinletplugin=Plugin.of_compiled_exncompiledinlet_=Plugin.callType.stringType.stringplugin~name:"count_vowels""this is a test"inGc.minor();Gc.full_major();truelet%test_=letmanifest=Manifest.(create[Wasm.file"test/code.wasm"])inletcompiled=Plugin.Compiled.of_manifest_exnmanifestinletplugin=Plugin.of_compiled_exncompiledinlet_=Plugin.callType.stringType.stringplugin~name:"count_vowels""this is a test"inGc.minor();Gc.full_major();true