123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475openCoreopenAsyncopenVcamlopenVcaml_test_helpers(* Tests for what should happen to a running plugin if Neovim crashes. This is probably
only relevant for plugins that are daemonized since Neovim by default kills its child
processes on exit. *)letrecomit_unstable_writer_info:Sexp.t->Sexp.t=function|Atom_asatom->atom|List(Atom"info"::_)->List[Atom"info";Atom"<omitted>"]|List[Atom"String";Atommsgpack_error]->letmsgpack_error=trySexp.of_stringmsgpack_errorwith|_->Atommsgpack_errorinList[Atom"String";omit_unstable_writer_infomsgpack_error]|Listsexps->List(List.mapsexps~f:omit_unstable_writer_info);;let%expect_test"Asynchronous write failure is returned to outstanding requests"=Backtrace.elide:=true;lettest~close_reader_and_writer_on_disconnect=Expect_test_helpers_async.within_temp_dir(fun()->let%bindworking_dir=Sys.getcwd()inlet%bindclient,nvim=letclient=Client.create~on_error:`RaiseinClient.attachclient(Embed{prog=neovim_path;args=["--headless";"-n";"--embed";"--clean";"--listen";"./socket"];working_dir;env=`Extend["NVIM_RPLUGIN_MANIFEST","rplugin.vim"]})~close_reader_and_writer_on_disconnect~time_source:(Time_source.read_only(Time_source.create~now:Time_ns.epoch()))>>|ok_exninProcess.send_signalnvimSignal.term;let%bindexit_or_signal=Process.waitnviminprint_s[%message"nvim exited"(exit_or_signal:Unix.Exit_or_signal.t)];(* Wait for Msgpack RPC to close the writer after disconnect if
[close_reader_and_writer_on_disconnect] is set. *)let%bind()=Scheduler.yield_until_no_jobs_remain()inletwrite_after_termination=run_join[%here]client(Nvim.command"echo 'hi'")inlet%bindresult=write_after_terminationinprint_s(omit_unstable_writer_info[%sexp(result:unitOr_error.t)]);Client.closeclient)inlet%bind()=test~close_reader_and_writer_on_disconnect:truein[%expect{|
("nvim exited" (exit_or_signal (Error (Exit_non_zero 1))))
(Error
(("Called from" lib/vcaml/test/semantics/test_nvim_crash.ml:LINE:COL)
("Msgpack error response"
(String
("Failed to send Msgpack RPC request: writer is closed"
(method_name nvim_command) (parameters ((String "echo 'hi'")))))))) |}];let%bind()=test~close_reader_and_writer_on_disconnect:falsein[%expect{|
("nvim exited" (exit_or_signal (Error (Exit_non_zero 1))))
(Error
(("Called from" lib/vcaml/test/semantics/test_nvim_crash.ml:LINE:COL)
("Msgpack error response"
(String
("Writer error from inner_monitor"
(Unix.Unix_error "Broken pipe" writev_assume_fd_is_nonblocking "")
(writer ((file_descr _) (info <omitted>) (kind Fifo)))))))) |}];Backtrace.elide:=false;return();;