Skip to content
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

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

bclement-ocp
Copy link
Collaborator

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 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 through the aliases stanza, which requires bumping our dune dependency to 3.5. If that is an issue, we can duplicate the rule instead.

@hra687261
Copy link
Contributor

which requires bumping our dune dependency to 3.5. If that is an issue, we can duplicate the rule instead.

Fine by me, but could be worth getting a second opinion form @Halbaroth or @Gbury

@bclement-ocp
Copy link
Collaborator Author

OK, I'll wait until either of them chimes in.

@Halbaroth
Copy link
Collaborator

In my opinion, we shouldn't force the update to dune 3.5 for such a tiny benefit.

@bclement-ocp
Copy link
Collaborator Author

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).

@Halbaroth
Copy link
Collaborator

Could rebase this PR please?

@bclement-ocp
Copy link
Collaborator Author

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.
@bclement-ocp bclement-ocp merged commit dc80e1a into OCamlPro:next Aug 17, 2023
10 checks passed
@Halbaroth Halbaroth added this to the 2.5.0 milestone Aug 23, 2023
@Halbaroth Halbaroth mentioned this pull request Aug 23, 2023
@bclement-ocp bclement-ocp deleted the gentest branch January 3, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants