From f0e2b2c463d92dc482a6bca163873fe03451c2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Hinderer?= Date: Mon, 19 Feb 2018 16:33:53 +0100 Subject: ocamltest: expand variables before exporting them to system env --- ocamltest/environments.ml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ocamltest/environments.ml b/ocamltest/environments.ml index 49293b3bf0..c5b9ba0b6a 100644 --- a/ocamltest/environments.ml +++ b/ocamltest/environments.ml @@ -31,17 +31,7 @@ let string_of_binding variable value = let name = (Variables.name_of_variable variable) in Printf.sprintf "%s=%s" name value -let to_system_env ?(f= string_of_binding) env = - let system_env = Array.make (VariableMap.cardinal env) "" in - let i = ref 0 in - let store variable value = - system_env.(!i) <- f variable value; - incr i in - VariableMap.iter store env; - system_env - let expand env value = - let bindings = to_bindings env in let f (variable, value) = ((Variables.name_of_variable variable), value) in let simple_bindings = List.map f bindings in @@ -49,6 +39,15 @@ let expand env value = let b = Buffer.create 100 in try Buffer.add_substitute b subst value; Buffer.contents b with _ -> value +let to_system_env ?(f= string_of_binding) env = + let system_env = Array.make (VariableMap.cardinal env) "" in + let i = ref 0 in + let store variable value = + system_env.(!i) <- f variable (expand env value); + incr i in + VariableMap.iter store env; + system_env + let lookup variable env = try Some (expand env (VariableMap.find variable env)) with Not_found -> None -- cgit v1.2.1