Skip to content

Commit

Permalink
Convert pipe tests to cram
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Jan 27, 2024
1 parent bc926ee commit f014e52
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
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"
16 changes: 16 additions & 0 deletions test/unit/pipe/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(cram
(alias runtest-windows)
(deps
trivial.exe
bind.exe
listen_accept.exe
))

(executables
(names
trivial
bind
listen_accept
)
(libraries luv unit_helpers)
(flags -open Unit_helpers))
29 changes: 29 additions & 0 deletions test/unit/pipe/helpers.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let filename =
if Sys.win32 then
{|\\.\pipe\pipe|}
else
"pipe"

let with_pipe f =
Luv.Pipe.init () |> ok "init" @@ fun tcp ->
f tcp;
Luv.Handle.close tcp ignore

let with_server_and_client ~server ~client =
Luv.Pipe.init () |> ok "server init" @@ fun server_pipe ->
Luv.Pipe.bind server_pipe filename |> ok "bind" @@ fun () ->
Luv.Stream.listen server_pipe begin fun result ->
result |> ok "listen" @@ fun () ->
Luv.Pipe.init () |> ok "accept init" @@ fun accept_pipe ->
Luv.Stream.accept ~server:server_pipe ~client:accept_pipe
|> ok "accept" @@ fun () ->
server server_pipe accept_pipe
end;

Luv.Pipe.init () |> ok "client init" @@ fun client_pipe ->
Luv.Pipe.connect client_pipe filename begin fun result ->
result |> ok "connect" @@ fun () ->
client client_pipe
end;

Luv.Loop.run () |> ignore
8 changes: 8 additions & 0 deletions test/unit/pipe/listen_accept.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let () =
Helpers.with_server_and_client
~server:begin fun server_pipe accept_pipe ->
Luv.Handle.close server_pipe ignore
end
~client:begin fun client_tcp ->
prerr_endline "Connected"
end
9 changes: 9 additions & 0 deletions test/unit/pipe/pipe.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$ dune exec ./trivial.exe
Ok

$ dune exec ./bind.exe
Ok

$ dune exec ./listen_accept.exe
Accepted
Connected
3 changes: 3 additions & 0 deletions test/unit/pipe/trivial.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let () =
Helpers.with_pipe ignore;
print_endline "Ok"

0 comments on commit f014e52

Please sign in to comment.