From 8d8295fc75fd48edae244c7c08fc240c2a8e9089 Mon Sep 17 00:00:00 2001 From: Craig Ferguson Date: Sat, 12 Sep 2020 12:18:18 +0200 Subject: [PATCH 1/2] Test alcotest-async exception handling behaviour --- test/e2e/alcotest-async/dune | 4 ++ test/e2e/alcotest-async/failing/dune | 21 +++++++++ test/e2e/alcotest-async/failing/dune.inc | 28 ++++++++++++ .../failing/exceptions.expected | 45 +++++++++++++++++++ test/e2e/alcotest-async/failing/exceptions.ml | 23 ++++++++++ 5 files changed, 121 insertions(+) create mode 100644 test/e2e/alcotest-async/dune create mode 100644 test/e2e/alcotest-async/failing/dune create mode 100644 test/e2e/alcotest-async/failing/dune.inc create mode 100644 test/e2e/alcotest-async/failing/exceptions.expected create mode 100644 test/e2e/alcotest-async/failing/exceptions.ml 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 ()) From ca23e71fe02a958c97980f2dd6a06e1b6768fcc3 Mon Sep 17 00:00:00 2001 From: Craig Ferguson Date: Sat, 12 Sep 2020 12:29:17 +0200 Subject: [PATCH 2/2] Add async as a test dependency --- alcotest-async.opam | 1 + dune-project | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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)