-
Notifications
You must be signed in to change notification settings - Fork 437
fix: dune test dirtest.t/run.t running cram test incorrectly #11869
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
8000
|
@@ -33,6 +33,20 @@ let runtest_info = | |
;; | ||
|
||
let find_cram_test path ~parent_dir = | ||
(* We correct the [path] and [parent_dir] if we have a directory test and the | ||
user has given a path to "run.t" rather than the directory cram test itself. *) | ||
let path, parent_dir = | ||
Option.value ~default:(path, parent_dir) | ||
@@ | ||
let open Option.O in | ||
let* basename = Path.Source.basename_opt path in | ||
if String.equal basename Source.Cram_test.fname_in_dir_test | ||
then | ||
let* parent_dir_of_run = Path.Source.parent path in | ||
let+ parent_dir = Path.Source.parent parent_dir_of_run in | ||
parent_dir_of_run, parent_dir | ||
else None | ||
in | ||
let open Memo.O in | ||
Source_tree.nearest_dir parent_dir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are taking a possible file, we want this to be the nearest directory above. Otherwise we have to handle the file and directory cases separately. |
||
>>= Dune_rules.Cram_rules.cram_tests | ||
|
@@ -42,13 +56,11 @@ let find_cram_test path ~parent_dir = | |
>>| List.filter_map ~f:Result.to_option | ||
(* We search our list of known cram tests for the test we are looking | ||
for. *) | ||
>>| List.find ~f:(fun (test : Source.Cram_test.t) -> | ||
let src = | ||
match test with | ||
| File src -> src | ||
| Dir { dir = src; _ } -> src | ||
in | ||
Path.Source.equal path src) | ||
>>| List.find_map ~f:(fun (test : Source.Cram_test.t) -> | ||
let open Option.O in | ||
let* cram_basename = Source.Cram_test.path test |> Path.Source.basename_opt in | ||
let* basename = Path.Source.basename_opt path in | ||
Option.some_if (Filename.equal cram_basename basename) (test, parent_dir)) | ||
;; | ||
|
||
let explain_unsuccessful_search path ~parent_dir = | ||
|
@@ -92,7 +104,7 @@ let disambiguate_test_name path = | |
let open Memo.O in | ||
find_cram_test path ~parent_dir | ||
>>= (function | ||
| Some test -> | ||
| Some (test, parent_dir) -> | ||
(* If we find the cram test, then we request that is run. *) | ||
Memo.return (`Test (parent_dir, Source.Cram_test.name test)) | ||
| None -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
open Import | ||
|
||
(** [t] represents the source file associated to a cram test. *) | ||
type t = | ||
| File of Path.Source.t | ||
| Dir of | ||
{ file : Path.Source.t | ||
; dir : Path.Source.t | ||
} | ||
|
||
val is_cram_suffix : string -> bool | ||
val dyn_of_t : t -> Dyn.t | ||
val name : t -> string | ||
val to_dyn : t -> Dyn.t | ||
|
||
(** Checks if a filename has the ".t" suffix for a cram test. *) | ||
val is_cram_suffix : Filename.t -> bool | ||
|
||
(** The "run.t" filename for directory cram tests. *) | ||
val fname_in_dir_test : Filename.t | ||
|
||
(** The [name] of a cram test. If this is a file test, then it will be the file | ||
name without the cram suffix. If this is a directory test, then it will be | ||
the directory name without the cram suffix. *) | ||
val name : t -> string | ||
|
||
(** The [path] associated to a cram test. If this is a file test, then it will | ||
be the file. If this is a directory test, then it will be the directory. *) | ||
val path : t -> Path.Source.t | ||
|
||
(** The [script] of a cram test. If this is a file test, then it will be the | ||
file. If this is a directory test, then it will be the "run.t" file inside | ||
that directory. *) | ||
val script : t -> Path.Source.t |
There was a problem hiding this comment.
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:
foo
, look up the source directory for the parent of this path. Let's call itparent foo
.parent foo
contains a cram test withchop_prefix (basename foo) ~suffix:".t"
, then we found our test.foo
is therun.t
inside a cram test. For that, we now look for a testparent foo
.All of this logic should hopefully be shared as much as possible with the logic for discovering cram tests in the rules.
There was a problem hiding this comment.
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 haveparent foo = "a.t"
. Now we also satisfy (2) becauserun.t
looks like a file cram test to us. Even if we load the cram rules ina.t
we will haverun.t
reported erroneously as a cram test. When we load rules we don't go intoa.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.