add basic test

This commit is contained in:
Simon Cruanes 2024-10-24 00:07:21 -04:00
parent 4da0257298
commit a554d77671
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 32 additions and 0 deletions

4
tests/unix/dune Normal file
View file

@ -0,0 +1,4 @@
(tests
(names t1)
(libraries nanoev nanoev.unix threads))

3
tests/unix/t1.expected Normal file
View file

@ -0,0 +1,3 @@
writing
can read
done writing

25
tests/unix/t1.ml Normal file
View file

@ -0,0 +1,25 @@
module E = Nanoev_unix
let mkpipe () : Unix.file_descr * Unix.file_descr =
let f1, f2 = Unix.pipe () in
Unix.set_nonblock f1;
Unix.set_nonblock f2;
f1, f2
let loop (e : E.t) =
while true do
E.step e
done
let () =
let ev = E.create () in
ignore (Thread.create loop ev : Thread.t);
let rd, wr = mkpipe () in
E.on_readable ev rd () () (fun () () -> print_endline "can read");
Thread.delay 0.05;
print_endline "writing";
ignore
(Unix.write wr (Bytes.unsafe_of_string "hello") 0 (String.length "hello")
: int);
Thread.delay 0.1;
print_endline "done writing"