-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use dune's include stanza for generated tests #729
Conversation
Fine by me, but could be worth getting a second opinion form @Halbaroth or @Gbury |
OK, I'll wait until either of them chimes in. |
In my opinion, we shouldn't force the update to dune 3.5 for such a tiny benefit. |
OK, I will duplicate everything (athough I think most people already use a version of dune higher than 3.5 if they are using opam). |
Could rebase this PR please? |
Looks like the CI doesn't see the test files for some reason, I will have to investigate... |
The current implementation of test generation is quite high friction: - When adding new tests, running tests directly with dune doesn't work, because the dune files must be generated by `make gentest` beforehand. There is `make runtest`, but that always runs all the tests, and does not allow specifying only some tests to run (which, given that our test suite is quite big, is sometimes needed for quick iterations). - The generated dune files are not commited to the repository, which means that it is easy to forget to run `make gentest` when switching branches -- which either causes some tests to silently not run, or errors because some files are missing. This patch solves both issues by integrating the test generation with dune, using the `include` stanza. More precisely: - The test generation script (gentest.ml) is modified to write all the test cases on the standard output as a single file, rather than creating the dune test files by itself. The generated file makes use of the `subdir` stanza to locate the targets appropriately. - There is a new `dune.inc` file that is included by the `dune` file in `tests`, and a `diff` rule that generates the content of that `dune.inc` file using the `gentest.ml` script. This is the way rules generation must work in dune, and it means that the `dune.inc` file must be commited to the repository --- which may not be such a bad thing, see above. The rule generation is added to the `gentest`, `runtest`, `runtest-quick` and `runtest-ci` aliases. The advantage of the new approach is that since the dependency is known to dune (and not only to make), running a command such as `dune build @tests/issues/XXX/runtest-quick` will always regenerate the tests, and also that we won't have to delete `dune` files manually when switching branches, since everything is in the file that gets re-generated. It means that running tests is slightly slower, because it always requires running the `gentest` script --- but that is probably fine, until we have many more tests than currently.
Currently, the dune files for tests are generated using the Makefile, and not included in the repository. There are often issues when changing branches that add new tests, because the dune files easily get out of sync, and regularly require manual intervention to remove them when new test directories are added.
This patch uses dune's auto-generated files and include mechanism for test generation instead. More precisely:
The test generation script (gentest.ml) is modified to write all the test cases on the standard output as a single file, rather than creating the dune test files by itself. The generated file makes use of the
subdir
stanza to locate the targets appropriately.There is a new
dune.inc
file that is included by thedune
file intests
, and adiff
rule that generates the content of thatdune.inc
file using thegentest.ml
script. This is the way rules generation must work in dune, and it means that thedune.inc
file must be commited to the repository --- which may not be such a bad thing, see above.The rule generation is added to the
gentest
,runtest
,runtest-quick
andruntest-ci
aliases through thealiases
stanza, which requires bumping our dune dependency to 3.5. If that is an issue, we can duplicate the rule instead.