Skip to content

Examples: add async #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,44 @@ jobs:

- os: windows-latest
ocaml-compiler: "4.14"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

- os: ubuntu-latest
ocaml-compiler: "4.08"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

- os: ubuntu-latest
ocaml-compiler: "4.09"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

- os: ubuntu-latest
ocaml-compiler: "4.10"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

- os: ubuntu-latest
ocaml-compiler: "4.11"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

- os: ubuntu-latest
ocaml-compiler: "4.12"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

- os: ubuntu-latest
ocaml-compiler: "4.13"
packages: "alcotest alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
packages: "alcotest alcotest-async alcotest-js alcotest-lwt alcotest-mirage"
opam-local-packages: "alcotest.opam alcotest-async.opam alcotest-js.opam alcotest-lwt.opam alcotest-mirage.opam"
runtest: false

runs-on: ${{ matrix.os }}
Expand Down
13 changes: 13 additions & 0 deletions examples/async/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(test
(name test)
(modes exe)
(preprocess
(pps ppx_jane))
(libraries
alcotest
alcotest-async
async
async_kernel
async_unix
core
core_unix.time_float_unix))
29 changes: 29 additions & 0 deletions examples/async/test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
open Async
open Async_unix

let plain_test () = Alcotest.(check int) "same int" 42 42

let async_test_check_raises () =
(* Use timeout of 1.0 as by default, Alcotest timeout after 2.0 *)
let%bind () = Clock.after (Time_float_unix.Span.of_sec 1.0) in
Alcotest.check_raises "Exit" Exit (fun () -> raise Exit);
return ()

let async_test () =
(* Use timeout of 1.0 as by default, Alcotest timeout after 2.0 *)
let%bind () = Clock.after (Time_float_unix.Span.of_sec 1.0) in
Alcotest.(check int) "same int" 42 42;
return ()

let () =
Async.Thread_safe.block_on_async_exn (fun () ->
let open Alcotest_async in
run "Async tests"
[
( "basic",
[
test_case "Async" `Quick async_test;
test_case "Async check raises" `Quick async_test_check_raises;
test_case_sync "Plain" `Quick plain_test;
] );
])
Loading