1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020 Nomadic Labs. <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openTezos_event_logging_test_helpers(** [tztest] contains the definition of [tztest]: a wrapper for tests
cases running in the error monad. It also adds helpers for working
with the mock sink. *)(** Transform a function running in the error monad into an Alcotest, taking
care of failing the test if the function results is an error.
Note that the given function must still take care of test assertions,
e.g. by using [Alcotest.check]. *)lettztest(name:string)(speed:Alcotest.speed_level)(f:unit->'aLwt.t):unitAlcotest_lwt.test_case=Alcotest_lwt.test_casenamespeed(fun_sw()->letopenLwt_syntaxinlet*r=f()inmatchrwith|Ok()->Lwt.return_unit|Errorerr->let*()=Tezos_base_unix.Internal_event_unix.close()inletmsg=Format.asprintf"@\n%a@."pp_print_traceerrinLwt.fail(Alcotest.failmsg))lettztest_qcheck?count~namegeneratorf=letname,speed,run=QCheck_alcotest.to_alcotest(QCheck.Test.make?count~namegenerator@@funx->matchLwt_main.run(fx)with|Ok_->true|Errorerr->QCheck.Test.fail_reportf"@\n%a@."pp_print_traceerr)inAlcotest_lwt.test_casenamespeed(fun_sw()->Lwt.return@@run())lettztest_qcheck2?print?count~namegeneratorf=letname,speed,run=QCheck_alcotest.to_alcotest(QCheck2.Test.make?print?count~namegenerator@@funx->matchLwt_main.run(fx)with|Ok_->true|Errorerr->QCheck2.Test.fail_reportf"@\n%a@."pp_print_traceerr)inAlcotest_lwt.test_casenamespeed(fun_sw()->Lwt.return@@run())letmock_sink:Mock_sink.tInternal_event.sink_definition=(moduleMock_sink:Internal_event.SINKwithtypet=Mock_sink.t)(** [with_empty_mock_sink f] executes f after activating or clearing a Mock_sink
sink.
Sinks can only be registered and activated once, and not removed thereafter.
*)letwith_empty_mock_sink(f:unit->unitLwt.t):unitLwt.t=letopenLwt_syntaxinifnot(Mock_sink.is_activated())then(Internal_event.All_sinks.registermock_sink;let*r=Internal_event.All_sinks.activate(Uri.of_string"mock-log://")inmatchrwith|Ok_->f()|Errorerrors->Format.printf"Could not initialize mock sink:\n %a\n"pp_print_traceerrors;Format.print_flush();Lwt.return_unit)else(Mock_sink.clear_events();f())