Skip to content

Conversation

@Alizter
Copy link
Collaborator

@Alizter Alizter commented May 27, 2025

We fix an issue where a user can write

dune test dirtest.t/run.t

and the corresponding cram test was being run incorrectly. This was due to the buggy parent detection code in runtest.ml. We fix how the parent directory of a cram test is actually detected and do some cleanup for cram source related code.

The runtest.ml test is updated to better reflect what we expect the command to do.

  • changelog

@Alizter Alizter requested a review from rgrinberg May 27, 2025 10:02
@Alizter Alizter force-pushed the fix-foo_t_run_t branch from 2d78589 to fcd9c8d Compare May 27, 2025 11:43
bin/runtest.ml Outdated
@@
let open Option.O in
let* basename = Path.Source.basename_opt path in
if String.equal basename Source.Cram_test.fname_in_dir_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fishy to me, there should be a way to look up tests without having to replicate dune's own logic for discovering them. The logic should be roughly like this:

  1. Given a path foo, look up the source directory for the parent of this path. Let's call it parent foo.
  2. If parent foo contains a cram test with chop_prefix (basename foo) ~suffix:".t", then we found our test.
  3. Otherwise, we check if foo is the run.t inside a cram test. For that, we now look for a test parent foo.
  4. if we find such a test, we return it if the "script" of the said test is equal to the user provided path.

All of this logic should hopefully be shared as much as possible with the logic for discovering cram tests in the rules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a subtle issue with this logic which is why I have to correct things here. If the user provides a.t/run.t then by (1) we have parent foo = "a.t". Now we also satisfy (2) because run.t looks like a file cram test to us. Even if we load the cram rules in a.t we will have run.t reported erroneously as a cram test. When we load rules we don't go into a.t/ subdirectories for cram tests so we don't have this issue.

I'm also not sure what logic you would like to share with loading the cram tests, there we are given a parent directory and simplify check if there are cram tests there, whereas here we are given directory that could ambiguously be a file or directory cram test (or the script of a directory cram test), we then have to disambiguate and check that its parent directory actually contains such a cram test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed out a commit sketching out what I had in mind. Seems to be working

@rgrinberg rgrinberg force-pushed the fix-foo_t_run_t branch 2 times, most recently from 97fa2e0 to a30a138 Compare August 1, 2025 21:28
@Alizter Alizter force-pushed the fix-foo_t_run_t branch 4 times, most recently from a22f777 to 66f6c26 Compare August 2, 2025 16:59
We fix an issue where a user can write

```
dune test dirtest.t/run.t
```

and the corresponding cram test was being run incorrectly. This was due
to the buggy parent detection code in runtest.ml. We fix how the parent
directory of a cram test is actually detected and do some cleanup for
cram source related code.

The runtest.ml test is updated to better reflect what we expect the
command to do.

Co-authored-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter merged commit 5a10815 into ocaml:main Aug 3, 2025
26 checks passed
@Alizter Alizter deleted the fix-foo_t_run_t branch August 3, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants