raz / test / run / SetEnv.raz

26 lines · 743 B · raw · history · last change e0d008cd

1(* Sys.setEnv: a variable set, then set again, reaches a program this
2 one starts, as one variable; one it named in its own env wins. *)
3module SetEnv;
4import Out, Rt, Sys;
5
6proc run(env: [][]const U8);
7var p: Sys.Program; pid: INT;
8begin
9 p.path := "/bin/sh";
10 p.args := ["sh", "-c", "echo $RAZ_SET_ENV; env | grep -c ^RAZ_SET_ENV="];
11 p.env := env;
12 Out.flush;
13 pid := Sys.spawn(p);
14 if pid < 0 then Rt.stop("SetEnv: no sh"); end;
15 _, _, _ := Sys.wait(pid, true);
16end;
17
18proc main*;
19begin
20 if Sys.setEnv("RAZ_SET_ENV", "first") # 0 then Rt.stop("SetEnv: set"); end;
21 if Sys.setEnv("RAZ_SET_ENV", "second") # 0 then Rt.stop("SetEnv: set again"); end;
22 run([]);
23 run(["RAZ_SET_ENV=given"]);
24end;
25
26end SetEnv.