ocamltest: add the cd builtin action

This gives tests control over ocamltest's current working directory
master
Sébastien Hinderer 2018-03-23 09:21:25 +01:00
parent dd34dd5350
commit 41bd4f2ebf
3 changed files with 20 additions and 0 deletions

View File

@ -37,6 +37,19 @@ let fail = make
let result = Result.fail_with_reason "The fail action always fails." in
(result, env))
let cd = make
"cd"
(fun _log env ->
let cwd = Environments.safe_lookup Builtin_variables.cwd env in
begin
try
Sys.chdir cwd; (Result.pass, env)
with _ ->
let reason = "Could not chidir to \"" ^ cwd ^ "\"" in
let result = Result.fail_with_reason reason in
(result, env)
end)
let dumpenv = make
"dumpenv"
(fun log env ->
@ -140,6 +153,7 @@ let _ =
pass;
skip;
fail;
cd;
dumpenv;
libunix;
libwin32unix;

View File

@ -27,6 +27,9 @@ open Variables (* Should not be necessary with a ppx *)
let arguments = make ("arguments",
"Arguments passed to executed programs and scripts")
let cwd = make ("cwd",
"Used to change current working directory, but not updated")
let exit_status = make ("exit_status",
"Expected program exit status")
@ -96,6 +99,7 @@ let test_fail = make ("TEST_FAIL",
let _ = List.iter register_variable
[
arguments;
cwd;
exit_status;
files;
ocamltest_response;

View File

@ -19,6 +19,8 @@
val arguments : Variables.t
val cwd : Variables.t
val exit_status : Variables.t
val files : Variables.t