Skip to content
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

Test alcotest-async exception handling behaviour #279

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions alcotest-async.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ depends: [
"alcotest" {= version}
"async_unix" {>= "v0.9.0"}
"core_kernel" {>= "v0.9.0"}
"async" {with-test}
]
build: [
["dune" "subst"] {pinned}
Expand Down
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/alcotest-async/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(env
(_
(env-vars
(ALCOTEST_COLOR auto))))
21 changes: 21 additions & 0 deletions test/e2e/alcotest-async/failing/dune
Original file line number Diff line number Diff line change
@@ -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)))
28 changes: 28 additions & 0 deletions test/e2e/alcotest-async/failing/dune.inc
Original file line number Diff line number Diff line change
@@ -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)))
45 changes: 45 additions & 0 deletions test/e2e/alcotest-async/failing/exceptions.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Testing `test/e2e/alcotest-async/failing/exceptions.ml'.
This run has ID `<uuid>'.

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 <test-duration>s. 2 tests run.
23 changes: 23 additions & 0 deletions test/e2e/alcotest-async/failing/exceptions.ml
Original file line number Diff line number Diff line change
@@ -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 ())