na4zagin3 / satyrographos

Package manager for SATySFi
GNU Lesser General Public License v3.0
44 stars 13 forks source link

Refactoring: Setting PATH in the testcases #196

Open na4zagin3 opened 3 years ago

na4zagin3 commented 3 years ago

The current test implementation tries to update PATH in two locations. One is PrepareBin.prepare_bin and the other is `TestLib.with_bin_dir. They need to be unified.

(* PrepareBin *)
let prepare_bin bin log_file =
  let path = Unix.getenv "PATH" in
  let gen_bin name content =
    let path = FilePath.concat bin name in
    let open Shexp_process in
    let open Infix in
    mkdir ~p:() bin
    >> stdout_to path (content |> echo)
    >> chmod path ~perm:0o755
  in
  let open Shexp_process in
  let open Infix in
  Unix.putenv "PATH" (bin ^ ":" ^ path);
  gen_bin "satysfi" (satysfi log_file)
  >> gen_bin "opam" (opam log_file)
(* TestLib *)
let with_bin_dir bin_dir cmd =
  get_env "PATH"
  >>= fun path ->
  set_env "PATH" (bin_dir ^ ":" ^ Option.get path) cmd