Skip to content

Commit

Permalink
Convert pipe tests to cram and port to Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Jan 27, 2024
1 parent bc926ee commit 91b10d0
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 301 deletions.
300 changes: 0 additions & 300 deletions test/pipe.ml

This file was deleted.

1 change: 0 additions & 1 deletion test/tester.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

let () =
Alcotest.run "luv" (List.flatten [
if not Sys.win32 then Pipe.tests else [];
UDP.tests;
TTY.tests;
File.tests;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/pipe/bind.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let () =
Helpers.with_pipe @@ fun pipe ->
Luv.Pipe.bind pipe Helpers.filename |> ok "bind" @@ fun () ->
print_endline "Ok"
5 changes: 5 additions & 0 deletions test/unit/pipe/chmod.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let () =
Helpers.with_pipe @@ fun pipe ->
Luv.Pipe.bind pipe Helpers.filename |> ok "bind" @@ fun () ->
Luv.Pipe.chmod pipe [`READABLE] |> ok "chmod" @@ fun () ->
print_endline "Ok"
4 changes: 4 additions & 0 deletions test/unit/pipe/chmod_error.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let () =
Helpers.with_pipe @@ fun pipe ->
Luv.Pipe.chmod pipe [`READABLE] |> error [`EBADF] "chmod" @@ fun () ->
print_endline "Ok"
8 changes: 8 additions & 0 deletions test/unit/pipe/connect_exception.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let () =
Luv.Error.set_on_unhandled_exception (function
| Exit -> print_endline "Ok"; exit 0
| _ -> ());

Helpers.with_server_and_client ()
~server:(fun server_pipe accept_pipe -> Luv.Handle.close server_pipe ignore)
~client:(fun client_pipe -> raise Exit)
32 changes: 32 additions & 0 deletions test/unit/pipe/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(cram
(alias runtest-windows)
(deps
trivial.exe
bind.exe
listen_accept.exe
getsockname.exe
getpeername.exe
connect_exception.exe
read_write.exe
receive_handle.exe
chmod.exe
chmod_error.exe
handle.exe
))

(executables
(names
trivial
bind
listen_accept
getsockname
getpeername
connect_exception
read_write
receive_handle
chmod
chmod_error
handle
)
(libraries luv unit_helpers)
(flags -open Unit_helpers))
9 changes: 9 additions & 0 deletions test/unit/pipe/getpeername.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let () =
Helpers.with_server_and_client ()
~server:begin fun server_pipe accept_pipe ->
Luv.Handle.close server_pipe ignore
end
~client:begin fun client_pipe ->
Luv.Pipe.getpeername client_pipe |> ok "getpeername" @@ fun filename' ->
Printf.printf "%b\n" (filename' = Helpers.filename)
end
7 changes: 7 additions & 0 deletions test/unit/pipe/getsockname.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let () =
Helpers.with_pipe @@ fun pipe ->

Luv.Pipe.bind pipe Helpers.filename |> ok "bind" @@ fun () ->
Luv.Pipe.getsockname pipe |> ok "getsockname" @@ fun filename' ->

Printf.printf "%b\n" (filename' = Helpers.filename)
12 changes: 12 additions & 0 deletions test/unit/pipe/handle.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(* This is a compilation test. If the type constraints in handle.mli are wrong,
there will be a type error in this test. *)
let () =
Helpers.with_pipe begin fun pipe ->
ignore @@ Luv.Handle.send_buffer_size pipe;
ignore @@ Luv.Handle.recv_buffer_size pipe;
ignore @@ Luv.Handle.set_send_buffer_size pipe 4096;
ignore @@ Luv.Handle.set_recv_buffer_size pipe 4096;
ignore @@ Luv.Handle.fileno pipe
end;

print_endline "Ok"
Loading

0 comments on commit 91b10d0

Please sign in to comment.