Skip to content

Clean up hooks

Romain requested to merge romain-cleanup-hooks into master

Description / Motivation

In multiple occasions I was asked whether there could be a hook to trigger something at the end of each test or at the end of all tests. There is already a way to trigger something at the end of all tests (just use at_exit, I think it should work), but there is nothing for the end of each test.

I myself now need a hook at the end of each test for Octez. My plan is to emit a warning if a test has tag node but does not actually run a node. (Same for all executables.) I also plan to use it to help me automatically detect all tests that use an executable but without the corresponding tag.

This MR thus adds Test.declare_clean_up_function (there already was Test.declare_reset_function).

I chose to have hook functions of type unit -> unit and not unit -> unit Lwt.t because:

  • declare_reset_function takes unit -> unit, so I chose consistency;
  • my use case does not need Lwt.t.

But it is possible that we may eventually add Lwt variants for those two hooks.

How to Test the MR Manually

I have added some cram tests, so just run dune runtest or let the CI do it for you.

Checklist

  • Update CHANGES.md. No need to document changes to documentation and tests.
  • Make sure all new values, types etc. are documented in .mli files and that the generated documentation looks ok.
  • Add tests in test/, if relevant.

Merge request reports