From d2d732965feb36d876f9a8e66a52e79c44e26ae3 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Wed, 23 Apr 2025 14:58:46 +0200 Subject: [PATCH 1/3] Examples: add async --- examples/async/dune | 13 +++++++++++++ examples/async/test.ml | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 examples/async/dune create mode 100644 examples/async/test.ml diff --git a/examples/async/dune b/examples/async/dune new file mode 100644 index 00000000..fbb588e9 --- /dev/null +++ b/examples/async/dune @@ -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)) diff --git a/examples/async/test.ml b/examples/async/test.ml new file mode 100644 index 00000000..a85ecbcd --- /dev/null +++ b/examples/async/test.ml @@ -0,0 +1,22 @@ +open Async +open Async_unix + +let plain_test () = Alcotest.(check int) "same int" 42 42 + +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_sync "Plain" `Quick plain_test; + ] ); + ]) From e8b3a8071b1ad5e00de7b3c3b76a721b375c34ce Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Wed, 23 Apr 2025 15:14:12 +0200 Subject: [PATCH 2/3] Examples/async: add check_raises for async case --- examples/async/test.ml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/async/test.ml b/examples/async/test.ml index a85ecbcd..676200d6 100644 --- a/examples/async/test.ml +++ b/examples/async/test.ml @@ -3,6 +3,12 @@ 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 @@ -17,6 +23,7 @@ let () = ( "basic", [ test_case "Async" `Quick async_test; + test_case "Async check raises" `Quick async_test_check_raises; test_case_sync "Plain" `Quick plain_test; ] ); ]) From 231e65ad1bf009822262a539d4753504702d8fac Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Wed, 23 Apr 2025 15:37:23 +0200 Subject: [PATCH 3/3] CI: add alcotest-async --- .github/workflows/build.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d49c554..b6200df5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 }}