[go: up one dir, main page]

Split Tezt into a JS-compatible core and a JS-incompatible Main

Corresponding MR in tezos/opam-repository: opam-repository!353 (merged)

Context

We'd like to convert unit test to Tezt (#1265 (closed)). However, it is currently not possible to run executables linked with Tezt using nodejs because of the dependency on lwt.unix. This MR splits Tezt into a core lib (tezt.core) which does not depend on lwt.unix (only on lwt and unix), and a non-JS compatible part (tezt).

The Process and Runner modules will not be available in the JS version, this would be too much work.

The Temp module is currently not available either in the JS version, but there is probably a way to make it work later. The big issue being the dependency from Temp to Runner, so we may need two different implementations of Temp?

The rest of Tezt though can be put in tezt.core:

  • Lwt_unix.sleep becomes a parameter;
  • the call Lwt_main.run is pushed into the Scheduler submodule, which is itself turned into a parameter;
  • the Regression module used Process to call diff, I replaced that with my own implementation of diff;
  • the Regression module also needed the type Process.hooks, which I have moved into its own module Process_hooks;
  • the Regression module no longer depends on Temp either: it gathers data in memory instead of a temporary file.

The new Main module is in charge of passing Unix-specific parameters such as Lwt_unix.sleep and the Scheduler.

TODO

  • Find what to do with Unix.getpid () in Temp (replace with Random.int? but do we want Random.self_init?)
  • Remove the example
  • Update the manifest to have it generate JS versions of tezts when we want
  • Use Lwt_js.sleep (from js_of_ocaml-lwt)
  • Try to have only one opam package but with js_of_ocaml as an optional dependency by making tezt.js itself optional (stanza (optional) to implement in the manifest)
  • Have a nice story to tell about how to use Tezt: with unix, with JS, with both, for non-Octez devs (i.e. no manifest)
  • Update documentation

Manually testing the MR

$ dune build tezt/example_js
$ dune exec tezt/example_js/main.exe
[13:43:47.628] [SUCCESS] (1/1) an example of test
$ dune exec tezt/example_js/main.exe -j 4
[13:43:47.628] [SUCCESS] (1/1) an example of test
$ nodejs _build/default/tezt/example_js/main_js.bc.js 
[13:43:47.628] [SUCCESS] (1/1) an example of test
$ nodejs _build/default/tezt/example_js/main_js.bc.js -j 4
[13:43:58.877] [warn] The -j argument is ignored when using Tezt_js.run.
[13:43:58.882] [SUCCESS] (1/1) an example of test

Also, check the absence of missing primitives with:

dune build tezt/example_js/main_js.bc.js --profile release

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Romain

Merge request reports

Loading