-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert Idle, Check, Prepare tests to cram tests
- Loading branch information
Showing
18 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let () = | ||
Helpers.with_check @@ fun check -> | ||
|
||
Luv.Check.start check (fun () -> print_endline "First") | ||
|> ok "first start" @@ fun () -> | ||
Luv.Check.start check (fun () -> print_endline "Second") | ||
|> ok "second start" @@ fun () -> | ||
|
||
Luv.Loop.run ~mode:`NOWAIT () |> ignore; | ||
Luv.Loop.run ~mode:`NOWAIT () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let () = | ||
Helpers.with_check @@ fun check -> | ||
Luv.Error.set_on_unhandled_exception (function | ||
| Exit -> print_endline "Ok" | ||
| _ -> ()); | ||
Luv.Check.start check (fun () -> raise Exit) | ||
|> ok "start" @@ fun () -> | ||
Luv.Loop.run ~mode:`NOWAIT () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let () = | ||
Helpers.with_check @@ fun check -> | ||
Ctypes.ptr_compare (Luv.Handle.get_loop check) (Luv.Loop.default ()) = 0 | ||
|> Printf.printf "%b\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let () = | ||
Helpers.with_check @@ fun check -> | ||
|
||
let calls = ref 0 in | ||
Luv.Check.start check begin fun () -> | ||
print_endline "Check"; | ||
incr calls; | ||
if !calls >= 2 then | ||
Luv.Check.stop check |> ignore | ||
end | ||
|> ok "start" @@ fun () -> | ||
|
||
while Luv.Loop.run ~mode:`NOWAIT () do | ||
() | ||
done; | ||
|
||
print_endline "Ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let () = | ||
Helpers.with_check ignore; | ||
print_endline "Ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(cram | ||
(deps | ||
idle_trivial.exe | ||
idle_loop.exe | ||
idle_start_stop.exe | ||
idle_double_start.exe | ||
idle_exception.exe | ||
check_trivial.exe | ||
check_loop.exe | ||
check_start_stop.exe | ||
check_double_start.exe | ||
check_exception.exe | ||
prepare_trivial.exe | ||
prepare_loop.exe | ||
prepare_start_stop.exe | ||
prepare_double_start.exe | ||
prepare_exception.exe | ||
)) | ||
|
||
(executables | ||
(names | ||
idle_trivial | ||
idle_loop | ||
idle_start_stop | ||
idle_double_start | ||
idle_exception | ||
check_trivial | ||
check_loop | ||
check_start_stop | ||
check_double_start | ||
check_exception | ||
prepare_trivial | ||
prepare_loop | ||
prepare_start_stop | ||
prepare_double_start | ||
prepare_exception | ||
) | ||
(libraries luv unit_helpers) | ||
(flags -open Unit_helpers)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
let with_idle f = | ||
Luv.Idle.init () |> ok "init" @@ fun idle -> | ||
f idle; | ||
Luv.Handle.close idle ignore | ||
|
||
let with_check f = | ||
Luv.Check.init () |> ok "init" @@ fun check -> | ||
f check; | ||
Luv.Handle.close check ignore | ||
|
||
let with_prepare f = | ||
Luv.Prepare.init () |> ok "init" @@ fun prepare -> | ||
f prepare; | ||
Luv.Handle.close prepare ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
$ dune exec ./idle_trivial.exe | ||
Ok | ||
|
||
$ dune exec ./idle_loop.exe | ||
true | ||
|
||
$ dune exec ./idle_start_stop.exe | ||
Idle | ||
Idle | ||
Ok | ||
|
||
$ dune exec ./idle_double_start.exe | ||
First | ||
First | ||
|
||
$ dune exec ./idle_exception.exe | ||
Ok | ||
|
||
$ dune exec ./check_trivial.exe | ||
Ok | ||
|
||
$ dune exec ./check_loop.exe | ||
true | ||
|
||
$ dune exec ./check_start_stop.exe | ||
Check | ||
Check | ||
Ok | ||
|
||
$ dune exec ./check_double_start.exe | ||
First | ||
First | ||
|
||
$ dune exec ./check_exception.exe | ||
Ok | ||
|
||
$ dune exec ./prepare_trivial.exe | ||
Ok | ||
|
||
$ dune exec ./prepare_loop.exe | ||
true | ||
|
||
$ dune exec ./prepare_start_stop.exe | ||
Prepare | ||
Prepare | ||
Ok | ||
|
||
$ dune exec ./prepare_double_start.exe | ||
First | ||
First | ||
|
||
$ dune exec ./prepare_exception.exe | ||
Ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let () = | ||
Helpers.with_idle @@ fun idle -> | ||
|
||
Luv.Idle.start idle (fun () -> print_endline "First") | ||
|> ok "first start" @@ fun () -> | ||
Luv.Idle.start idle (fun () -> print_endline "Second") | ||
|> ok "second start" @@ fun () -> | ||
|
||
Luv.Loop.run ~mode:`NOWAIT () |> ignore; | ||
Luv.Loop.run ~mode:`NOWAIT () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let () = | ||
Helpers.with_idle @@ fun idle -> | ||
Luv.Error.set_on_unhandled_exception (function | ||
| Exit -> print_endline "Ok" | ||
| _ -> ()); | ||
Luv.Idle.start idle (fun () -> raise Exit) | ||
|> ok "start" @@ fun () -> | ||
Luv.Loop.run ~mode:`NOWAIT () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let () = | ||
Helpers.with_idle @@ fun idle -> | ||
Ctypes.ptr_compare (Luv.Handle.get_loop idle) (Luv.Loop.default ()) = 0 | ||
|> Printf.printf "%b\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let () = | ||
Helpers.with_idle @@ fun idle -> | ||
|
||
let calls = ref 0 in | ||
Luv.Idle.start idle begin fun () -> | ||
print_endline "Idle"; | ||
incr calls; | ||
if !calls >= 2 then | ||
Luv.Idle.stop idle |> ignore | ||
end | ||
|> ok "start" @@ fun () -> | ||
|
||
while Luv.Loop.run ~mode:`NOWAIT () do | ||
() | ||
done; | ||
|
||
print_endline "Ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let () = | ||
Helpers.with_idle ignore; | ||
print_endline "Ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let () = | ||
Helpers.with_prepare @@ fun prepare -> | ||
|
||
Luv.Prepare.start prepare (fun () -> print_endline "First") | ||
|> ok "first start" @@ fun () -> | ||
Luv.Prepare.start prepare (fun () -> print_endline "Second") | ||
|> ok "second start" @@ fun () -> | ||
|
||
Luv.Loop.run ~mode:`NOWAIT () |> ignore; | ||
Luv.Loop.run ~mode:`NOWAIT () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let () = | ||
Helpers.with_prepare @@ fun prepare -> | ||
Luv.Error.set_on_unhandled_exception (function | ||
| Exit -> print_endline "Ok" | ||
| _ -> ()); | ||
Luv.Prepare.start prepare (fun () -> raise Exit) | ||
|> ok "start" @@ fun () -> | ||
Luv.Loop.run ~mode:`NOWAIT () |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let () = | ||
Helpers.with_prepare @@ fun prepare -> | ||
Ctypes.ptr_compare (Luv.Handle.get_loop prepare) (Luv.Loop.default ()) = 0 | ||
|> Printf.printf "%b\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let () = | ||
Helpers.with_prepare @@ fun prepare -> | ||
|
||
let calls = ref 0 in | ||
Luv.Prepare.start prepare begin fun () -> | ||
print_endline "Prepare"; | ||
incr calls; | ||
if !calls >= 2 then | ||
Luv.Prepare.stop prepare |> ignore | ||
end | ||
|> ok "start" @@ fun () -> | ||
|
||
while Luv.Loop.run ~mode:`NOWAIT () do | ||
() | ||
done; | ||
|
||
print_endline "Ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let () = | ||
Helpers.with_prepare ignore; | ||
print_endline "Ok" |