Skip to content

Commit e7fd279

Browse files
committed
Make tests cross-platform
1 parent adb434f commit e7fd279

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

test/test_launch.ml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ let process_launch_failure () =
88
(fun () -> ignore (Launch.exec_process config [ "missing.exe" ]));
99

1010
match_raises "non-executable should not launch"
11-
(* File for exec_process is not an executable *)
12-
(function Unix.Unix_error (Unix.EACCES, _, _) -> true | _exn -> false)
11+
(* File for exec_process is not an executable.
12+
Unix returns EACCES, Windows returns ENOEXEC. *)
13+
(function
14+
| Unix.Unix_error (Unix.EACCES, _, _) -> true
15+
| Unix.Unix_error (Unix.ENOEXEC, _, _) -> true
16+
| _exn -> false)
1317
(fun () -> ignore (Launch.exec_process config [ "./run_endlessly.ml" ]));
1418

1519
match_raises "empty executable string should not launch"
@@ -24,11 +28,17 @@ let process_launch () =
2428
"process should launch" true
2529
(try
2630
let a = Launch.exec_process config [ "./run_endlessly.exe" ] in
27-
try
28-
(* Sending signal Zero to kill checks the process exists for Unix. *)
29-
Unix.kill a.pid 0;
30-
true
31-
with Unix.Unix_error (Unix.ESRCH, _, _) -> false
31+
(* Check the child is alive using waitpid WNOHANG.
32+
Unix.kill with signal 0 is not supported on Windows. *)
33+
let launched = a.alive () in
34+
(* Clean up the child process so it doesn't leak.
35+
On Windows, open files cannot be deleted, so the orphan process
36+
would prevent dune from cleaning up its temp directory. *)
37+
(try Unix.kill a.pid Sys.sigkill
38+
with Unix.Unix_error _ | Invalid_argument _ -> ());
39+
(try ignore (Unix.waitpid [] a.pid) with Unix.Unix_error _ -> ());
40+
a.close ();
41+
launched
3242
with
3343
(* Any exceptions indicate a failure to launch *)
3444
| Unix.Unix_error (Unix.ENOENT, _, _) -> false

0 commit comments

Comments
 (0)