diff --git a/CHANGES.md b/CHANGES.md index fa33fd0c..c89bf8c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +### unreleased + +### Changed + +- Paths are normalized to drop the directory prefix ("./" on MacOs and Linux) + before pretty printing them (#482, @shonfeder). + ### 2.6.0 #### Added diff --git a/bin/cli.ml b/bin/cli.ml index 60e68321..041b1fb8 100644 --- a/bin/cli.ml +++ b/bin/cli.ml @@ -2,6 +2,17 @@ open Cmdliner let named wrapper = Term.(app (const wrapper)) +let normalize_file_path filename = + let local_prefix = Filename.current_dir_name ^ Filename.dir_sep in + let len_prefix = String.length local_prefix in + if + String.length filename >= len_prefix + && String.equal (String.sub filename 0 len_prefix) local_prefix + then + (* Strip current directory prefix *) + String.sub filename len_prefix (String.length filename - len_prefix) + else filename + let non_deterministic = let doc = "Run non-deterministic tests." in let env = Cmd.Env.info ~doc "MDX_RUN_NON_DETERMINISTIC" in diff --git a/bin/cli.mli b/bin/cli.mli index 3a0809dc..8936abc1 100644 --- a/bin/cli.mli +++ b/bin/cli.mli @@ -1,6 +1,7 @@ open Cmdliner.Term val named : ('a -> 'b) -> 'a t -> 'b t +val normalize_file_path : string -> string val non_deterministic : [> `Non_deterministic of bool ] t val syntax : [> `Syntax of Mdx.Syntax.t option ] t val file : [> `File of string ] t diff --git a/bin/dune_gen.ml b/bin/dune_gen.ml index 07a04942..0ee5bf95 100644 --- a/bin/dune_gen.ml +++ b/bin/dune_gen.ml @@ -34,7 +34,7 @@ let run (`Setup ()) (`Prelude prelude) (`Directories dirs) = in let pp_prelude ppf (env, filename) = - Fmt.pf ppf "(%a, %S)" pp_env env filename + Fmt.pf ppf "(%a, %S)" pp_env env (Cli.normalize_file_path filename) in let pp_preludes ppf preludes = diff --git a/bin/pp.ml b/bin/pp.ml index 7a7f389e..c79d01fa 100644 --- a/bin/pp.ml +++ b/bin/pp.ml @@ -30,7 +30,8 @@ let vpad_of_lines t = in aux 0 t -let pp_line_directive ppf (file, line) = Fmt.pf ppf "#%d %S" line file +let pp_line_directive ppf (file, line) = + Fmt.pf ppf "#%d %S" line (Cli.normalize_file_path file) let rec add_semi_semi = function | [] -> [] diff --git a/dune-project b/dune-project index 7ce26b6d..7adbeb1f 100644 --- a/dune-project +++ b/dune-project @@ -41,5 +41,4 @@ result (alcotest :with-test)) (conflicts - (result (< 1.5)) - (dune (and :with-test (= 3.24.0))))) + (result (< 1.5)))) diff --git a/mdx.opam b/mdx.opam index c7df39be..1c8a90ce 100644 --- a/mdx.opam +++ b/mdx.opam @@ -37,7 +37,6 @@ depends: [ ] conflicts: [ "result" {< "1.5"} - "dune" {with-test & = "3.24.0"} ] build: [ ["dune" "subst"] {dev}