Backport from sid to buster
[hcoop/debian/mlton.git] / regression / world4.sml
CommitLineData
7f918cf1
CE
1fun run (f: unit -> unit) =
2 case Posix.Process.fork () of
3 SOME pid =>
4 let
5 open Posix.Process
6 val (pid', status) = waitpid (W_CHILD pid, [])
7 in if pid = pid' andalso status = W_EXITED
8 then ()
9 else raise Fail "child failed"
10 end
11 | NONE => let open OS.Process
12 in exit ((f (); success) handle _ => failure)
13 end
14
15fun succeed () =
16 let open OS.Process
17 in exit success
18 end
19
20open MLton.World
21
22val (w1, out) = MLton.TextIO.mkstemp "/tmp/world"
23val _ = TextIO.closeOut out
24val (w2, out) = MLton.TextIO.mkstemp "/tmp/world"
25val _ = TextIO.closeOut out
26
27val _ = print "before saves\n"
28
29val original = ref true
30
31val _ = (case save w1 of
32 Clone => original := false
33 | Original => ())
34
35val _ = print "between saves\n"
36
37val _ = (case save w2 of
38 Clone => original := false
39 | Original => ())
40
41val _ = print "after saves\n"
42
43val _ = if !original
44 then (run (fn () => load w1)
45 ; run (fn () => load w2)
46 ; OS.FileSys.remove w1
47 ; OS.FileSys.remove w2)
48 else ()