Skip to content

Commit

Permalink
Add an internal test for STM on uncaught exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shym committed Jun 12, 2023
1 parent 7020dd3 commit 256047e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@
; filter out output that is not deterministic enough across
; versions and platforms
(run sed -e "/^[[]/d" -e "s/ ([0-9]* shrink steps)//"))))

(test
(name uncaught_stm)
(package qcheck-stm)
(modules uncaught_stm)
(libraries qcheck-stm.sequential)
(action
(pipe-outputs
(with-accepted-exit-codes 1
(run %{test} --no-colors --verbose --seed 260395858))
; filter out output that is not deterministic enough across
; versions and platforms
(run sed -e "/^[[]/d" -e "s/ ([0-9]* shrink steps)//"))))
24 changes: 24 additions & 0 deletions test/uncaught_stm.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
random seed: 260395858
generated error fail pass / total time test name

=== Error ======================================================================

Test STM test of uncaught exceptions errored on:

AlwaysFail ()


exception Failure("unexpected") raised but not caught while running AlwaysFail ()


=== Error ======================================================================

Test neg STM test of uncaught exceptions errored on:

AlwaysFail ()


exception Failure("unexpected") raised but not caught while running AlwaysFail ()

================================================================================
failure (0 tests failed, 2 tests errored, ran 2 tests)
32 changes: 32 additions & 0 deletions test/uncaught_stm.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(* Test of the behaviour of STM tests with uncaught exceptions *)

let always_fail () = failwith "unexpected"

module UncaughtExcConf : STM.Spec = struct
open STM

type sut = unit
type state = unit
type cmd = AlwaysFail of sut

let show_cmd = function AlwaysFail () -> "AlwaysFail ()"
let arb_cmd _ = QCheck.(make ~print:show_cmd (Gen.pure (AlwaysFail ())))
let init_state = ()
let next_state _ _ = ()
let init_sut _ = ()
let cleanup _ = ()
let precond _ _ = true
let run c s = match c with AlwaysFail () -> Res (unit, always_fail s)

let postcond c _ r =
match (c, r) with AlwaysFail (), Res ((Unit, _), _) -> true | _ -> false
end

module UE = STM_sequential.Make (UncaughtExcConf)

let _ =
QCheck_base_runner.run_tests_main
[
UE.agree_test ~count:10 ~name:"STM test of uncaught exceptions";
UE.neg_agree_test ~count:10 ~name:"neg STM test of uncaught exceptions";
]

0 comments on commit 256047e

Please sign in to comment.