Skip to content

Commit 16013b0

Browse files
committed
Add an internal test for STM on uncaught exceptions
1 parent d997c94 commit 16013b0

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

test/dune

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@
6363
(action
6464
(with-accepted-exit-codes 1
6565
(run %{test} --verbose --seed 260395858))))
66+
67+
(test
68+
(name uncaught_stm)
69+
(package qcheck-stm)
70+
(modules uncaught_stm)
71+
(libraries qcheck-stm.sequential)
72+
(action
73+
(with-accepted-exit-codes 1
74+
(run %{test} --verbose --seed 260395858))))

test/uncaught_stm.expected

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
random seed: 260395858
2+
generated error fail pass / total time test name
3+
[ ] 0 0 0 0 / 10 0.0s STM test of uncaught exceptions[ ] 0 0 0 0 / 10 0.0s STM test of uncaught exceptions (generating)[✗] 1 1 0 0 / 10 0.0s STM test of uncaught exceptions
4+
[ ] 0 0 0 0 / 10 0.0s neg STM test of uncaught exceptions[✗] 1 1 0 0 / 10 0.0s neg STM test of uncaught exceptions
5+
6+
=== Error ======================================================================
7+
8+
Test STM test of uncaught exceptions errored on (5 shrink steps):
9+
10+
AlwaysFail ()
11+
12+
13+
exception Failure("unexpected") raised but not caught while running AlwaysFail ()
14+
15+
16+
=== Error ======================================================================
17+
18+
Test neg STM test of uncaught exceptions errored on (5 shrink steps):
19+
20+
AlwaysFail ()
21+
22+
23+
exception Failure("unexpected") raised but not caught while running AlwaysFail ()
24+
25+
================================================================================
26+
failure (0 tests failed, 2 tests errored, ran 2 tests)

test/uncaught_stm.ml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(* Test of the behaviour of STM tests with uncaught exceptions *)
2+
3+
let always_fail () = failwith "unexpected"
4+
5+
module UncaughtExcConf : STM.Spec = struct
6+
open STM
7+
8+
type sut = unit
9+
type state = unit
10+
type cmd = AlwaysFail of sut
11+
12+
let show_cmd = function AlwaysFail () -> "AlwaysFail ()"
13+
let arb_cmd _ = QCheck.(make ~print:show_cmd (Gen.pure (AlwaysFail ())))
14+
let init_state = ()
15+
let next_state _ _ = ()
16+
let init_sut _ = ()
17+
let cleanup _ = ()
18+
let precond _ _ = true
19+
let run c s = match c with AlwaysFail () -> Res (unit, always_fail s)
20+
21+
let postcond c _ r =
22+
match (c, r) with AlwaysFail (), Res ((Unit, _), _) -> true | _ -> false
23+
end
24+
25+
module UE = STM_sequential.Make (UncaughtExcConf)
26+
27+
let _ =
28+
QCheck_base_runner.run_tests_main
29+
[
30+
UE.agree_test ~count:10 ~name:"STM test of uncaught exceptions";
31+
UE.neg_agree_test ~count:10 ~name:"neg STM test of uncaught exceptions";
32+
]

0 commit comments

Comments
 (0)