diff --git a/alcotest-async.opam b/alcotest-async.opam index 652c1456..7ee98a6f 100644 --- a/alcotest-async.opam +++ b/alcotest-async.opam @@ -14,6 +14,7 @@ depends: [ "alcotest" {= version} "async_unix" {>= "v0.9.0"} "core_kernel" {>= "v0.9.0"} + "async" {with-test} ] build: [ ["dune" "subst"] {pinned} diff --git a/dune-project b/dune-project index ecd0ae7c..a60db2ca 100644 --- a/dune-project +++ b/dune-project @@ -42,7 +42,8 @@ tests to run. (ocaml (>= 4.03.0)) (alcotest (= :version)) (async_unix (>= v0.9.0)) - (core_kernel (>= v0.9.0)))) + (core_kernel (>= v0.9.0)) + (async :with-test))) (package (name alcotest-lwt) diff --git a/test/e2e/alcotest-async/dune b/test/e2e/alcotest-async/dune new file mode 100644 index 00000000..7e853d4f --- /dev/null +++ b/test/e2e/alcotest-async/dune @@ -0,0 +1,4 @@ +(env + (_ + (env-vars + (ALCOTEST_COLOR auto)))) diff --git a/test/e2e/alcotest-async/failing/dune b/test/e2e/alcotest-async/failing/dune new file mode 100644 index 00000000..437345f9 --- /dev/null +++ b/test/e2e/alcotest-async/failing/dune @@ -0,0 +1,21 @@ +(env + (_ + (env-vars + (ALCOTEST_COLOR auto)))) + +(include dune.inc) + +(rule + (targets dune.gen) + (deps + (source_tree .)) + (action + (with-stdout-to + %{targets} + (run ../../gen_dune_rules.exe --expect-failure --package "alcotest-async" + --libraries "alcotest-async async async_kernel async_unix core")))) + +(rule + (alias runtest) + (action + (diff dune.inc dune.gen))) diff --git a/test/e2e/alcotest-async/failing/dune.inc b/test/e2e/alcotest-async/failing/dune.inc new file mode 100644 index 00000000..14678974 --- /dev/null +++ b/test/e2e/alcotest-async/failing/dune.inc @@ -0,0 +1,28 @@ +(executables + (names + exceptions + ) + (libraries alcotest alcotest-async async async_kernel async_unix core) + (modules + exceptions + ) +) + +(rule + (target exceptions.actual) + (action + (with-outputs-to %{target} + (with-accepted-exit-codes (or 1 125) + (run %{dep:exceptions.exe}))))) + +(rule + (target exceptions.processed) + (action + (with-outputs-to %{target} + (run ../../strip_randomness.exe %{dep:exceptions.actual})))) + +(rule + (alias runtest) + (package alcotest-async) + (action + (diff exceptions.expected exceptions.processed))) diff --git a/test/e2e/alcotest-async/failing/exceptions.expected b/test/e2e/alcotest-async/failing/exceptions.expected new file mode 100644 index 00000000..1862107a --- /dev/null +++ b/test/e2e/alcotest-async/failing/exceptions.expected @@ -0,0 +1,45 @@ +Testing `test/e2e/alcotest-async/failing/exceptions.ml'. +This run has ID `'. + +ASSERT 1 = 2 + [FAIL] all 0 failed check. + [FAIL] all 1 internal exception. + +┌──────────────────────────────────────────────────────────────────────────────┐ +│ [FAIL] all 0 failed check. │ +└──────────────────────────────────────────────────────────────────────────────┘ +(monitor.ml.Error ("Alcotest_engine__Core.Check_error(_)") + ("Raised at Alcotest_engine__Test.check in file \"src/alcotest-engine/test.ml\", line 159, characters 4-114" + "Called from Dune__exe__Exceptions.test_failed_check in file \"test/e2e/alcotest-async/failing/exceptions.ml\", line 5, characters 2-34" + "Called from Alcotest_async.run_test in file \"src/alcotest-async/alcotest_async.ml\", line 22, characters 29-38" + "Called from Alcotest_engine__Core.Make.protect_test.(fun) in file \"src/alcotest-engine/core.ml\", line 269, characters 17-23" + "Called from Async_kernel__Monitor.Exported_for_scheduler.schedule'.upon_work_fill_i in file \"src/monitor.ml\", line 295, characters 42-51" + "Called from Async_kernel__Job_queue.run_jobs in file \"src/job_queue.ml\", line 167, characters 6-47")) +Raised at Alcotest_engine__Test.check in file "src/alcotest-engine/test.ml", line 159, characters 4-114 +Called from Dune__exe__Exceptions.test_failed_check in file "test/e2e/alcotest-async/failing/exceptions.ml", line 5, characters 2-34 +Called from Alcotest_async.run_test in file "src/alcotest-async/alcotest_async.ml", line 22, characters 29-38 +Called from Alcotest_engine__Core.Make.protect_test.(fun) in file "src/alcotest-engine/core.ml", line 269, characters 17-23 +Called from Async_kernel__Monitor.Exported_for_scheduler.schedule'.upon_work_fill_i in file "src/monitor.ml", line 295, characters 42-51 +Called from Async_kernel__Job_queue.run_jobs in file "src/job_queue.ml", line 167, characters 6-47 + + ────────────────────────────────────────────────────────────────────────────── + + +┌──────────────────────────────────────────────────────────────────────────────┐ +│ [FAIL] all 1 internal exception. │ +└──────────────────────────────────────────────────────────────────────────────┘ +(monitor.ml.Error (Internal) + ("Raised at Dune__exe__Exceptions.test_internal_exception in file \"test/e2e/alcotest-async/failing/exceptions.ml\", line 10, characters 2-16" + "Called from Alcotest_async.run_test in file \"src/alcotest-async/alcotest_async.ml\", line 22, characters 29-38" + "Called from Alcotest_engine__Core.Make.protect_test.(fun) in file \"src/alcotest-engine/core.ml\", line 269, characters 17-23" + "Called from Async_kernel__Monitor.Exported_for_scheduler.schedule'.upon_work_fill_i in file \"src/monitor.ml\", line 295, characters 42-51" + "Called from Async_kernel__Job_queue.run_jobs in file \"src/job_queue.ml\", line 167, characters 6-47")) +Raised at Dune__exe__Exceptions.test_internal_exception in file "test/e2e/alcotest-async/failing/exceptions.ml", line 10, characters 2-16 +Called from Alcotest_async.run_test in file "src/alcotest-async/alcotest_async.ml", line 22, characters 29-38 +Called from Alcotest_engine__Core.Make.protect_test.(fun) in file "src/alcotest-engine/core.ml", line 269, characters 17-23 +Called from Async_kernel__Monitor.Exported_for_scheduler.schedule'.upon_work_fill_i in file "src/monitor.ml", line 295, characters 42-51 +Called from Async_kernel__Job_queue.run_jobs in file "src/job_queue.ml", line 167, characters 6-47 + + ────────────────────────────────────────────────────────────────────────────── + +2 failures! in s. 2 tests run. diff --git a/test/e2e/alcotest-async/failing/exceptions.ml b/test/e2e/alcotest-async/failing/exceptions.ml new file mode 100644 index 00000000..58c3902a --- /dev/null +++ b/test/e2e/alcotest-async/failing/exceptions.ml @@ -0,0 +1,23 @@ +open! Core +open! Async + +let test_failed_check () = + Alcotest.(check int) "1 = 2" 1 2; + Deferred.return () + +let test_internal_exception () = + let exception Internal in + raise Internal + +let () = + let open Alcotest_async in + ignore + (run ~verbose:true __FILE__ + [ + ( "all", + [ + test_case "failed check" `Quick test_failed_check; + test_case "internal exception" `Quick test_internal_exception; + ] ); + ]); + never_returns (Scheduler.go ())