Merge pull request #777 from rgrinberg/spec-reach-for-running
Add tests for reach_for_running
This commit is contained in:
commit
3548e2f6d4
|
@ -741,7 +741,7 @@ let exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args =
|
|||
Process.run Strict ~dir ~env
|
||||
~stdout_to ~stderr_to
|
||||
~purpose:ectx.purpose
|
||||
(Path.reach_for_running ~from:dir prog) args
|
||||
prog args
|
||||
|
||||
let exec_run ~stdout_to ~stderr_to =
|
||||
let stdout_to = get_std_output stdout_to in
|
||||
|
|
|
@ -112,7 +112,7 @@ module Fancy = struct
|
|||
| x :: rest -> x :: colorize_args rest
|
||||
|
||||
let command_line ~prog ~args ~dir ~stdout_to ~stderr_to =
|
||||
let prog = Path.to_string prog in
|
||||
let prog = Path.reach_for_running ?from:dir prog in
|
||||
let quote = quote_for_shell in
|
||||
let prog = colorize_prog (quote prog) in
|
||||
let s =
|
||||
|
@ -232,7 +232,7 @@ let run_internal ?dir ?(stdout_to=Terminal) ?(stderr_to=Terminal) ~env ~purpose
|
|||
if display = Verbose then
|
||||
Format.eprintf "@{<kwd>Running@}[@{<id>%d@}]: %s@." id
|
||||
(Colors.strip_colors_for_stderr command_line);
|
||||
let prog = Path.to_string prog in
|
||||
let prog = Path.reach_for_running ?from:dir prog in
|
||||
let argv = Array.of_list (prog :: args) in
|
||||
let output_filename, stdout_fd, stderr_fd, to_close =
|
||||
match stdout_to, stderr_to with
|
||||
|
@ -347,11 +347,11 @@ let run_capture_line ?dir ~env ?(purpose=Internal_job) fail_mode prog args =
|
|||
| [x] -> x
|
||||
| l ->
|
||||
let cmdline =
|
||||
let prog = Path.to_string prog in
|
||||
let s = String.concat (prog :: args) ~sep:" " in
|
||||
let prog = Path.reach_for_running ?from:dir prog in
|
||||
let prog_display = String.concat (prog :: args) ~sep:" " in
|
||||
match dir with
|
||||
| None -> s
|
||||
| Some dir -> sprintf "cd %s && %s" (Path.to_string dir) s
|
||||
| None -> prog_display
|
||||
| Some dir -> sprintf "cd %s && %s" (Path.to_string dir) prog_display
|
||||
in
|
||||
match l with
|
||||
| [] ->
|
||||
|
|
|
@ -302,7 +302,7 @@ let reach t ~from =
|
|||
| Local t, Local from ->
|
||||
Local.reach t ~from
|
||||
|
||||
let reach_for_running t ~from =
|
||||
let reach_for_running ?(from=root) t =
|
||||
match kind t, kind from with
|
||||
| External _, _ -> t
|
||||
| Local _, External _ ->
|
||||
|
|
|
@ -70,7 +70,9 @@ val absolute : string -> t
|
|||
val to_absolute_filename : t -> root:string -> string
|
||||
|
||||
val reach : t -> from:t -> string
|
||||
val reach_for_running : t -> from:t -> t
|
||||
|
||||
(** [from] defaults to [Path.root] *)
|
||||
val reach_for_running : ?from:t -> t -> string
|
||||
|
||||
val descendant : t -> of_:t -> t option
|
||||
val is_descendant : t -> of_:t -> bool
|
||||
|
|
|
@ -284,3 +284,31 @@ Path.is_in_build_dir Path.build_dir
|
|||
[%%expect{|
|
||||
- : bool = false
|
||||
|}]
|
||||
|
||||
Path.reach_for_running Path.build_dir ~from:Path.root
|
||||
[%%expect{|
|
||||
- : string = "./_build"
|
||||
|}]
|
||||
|
||||
Path.(reach_for_running (relative build_dir "foo/baz")
|
||||
~from:(relative build_dir "foo/bar/baz"))
|
||||
[%%expect{|
|
||||
- : string = "../../baz"
|
||||
|}]
|
||||
|
||||
Path.(reach_for_running (Path.absolute "/fake/path")
|
||||
~from:(relative build_dir "foo/bar/baz"))
|
||||
[%%expect{|
|
||||
- : string = "/fake/path"
|
||||
|}]
|
||||
|
||||
Path.(reach_for_running (relative build_dir "foo/baz")
|
||||
~from:(Path.absolute "/fake/path"))
|
||||
[%%expect{|
|
||||
Exception: Stdune__Exn.Code_error <abstr>.
|
||||
|}]
|
||||
|
||||
Path.(reach_for_running (relative root "foo") ~from:(Path.relative root "foo"))
|
||||
[%%expect{|
|
||||
- : string = "./."
|
||||
|}]
|
||||
|
|
Loading…
Reference in New Issue