File tree Expand file tree Collapse file tree 7 files changed +73
-2
lines changed
test/e2e/alcotest/passing Expand file tree Collapse file tree 7 files changed +73
-2
lines changed Original file line number Diff line number Diff line change 1
1
### unreleased
2
2
3
3
- Add ` seq ` , a testable for ` Seq.t ` and ` contramap ` (#412 @xvw )
4
+ - BREAKING: ` match_raises ` now expects the user-defined function to return
5
+ true for expected exceptions. Previously false was interpreted as an
6
+ expected exception. (#418 , #419 , @psafont )
4
7
5
8
### 1.8.0 (2024-07-25)
6
9
Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ let match_raises ?here ?pos msg exnp f =
263
263
Fmt. pf ppf " %t%a %s: got nothing." (pp_location ?here ?pos) Pp. tag
264
264
`Fail msg)
265
265
| Some e ->
266
- if exnp e then
266
+ if not ( exnp e) then
267
267
check_err (fun ppf () ->
268
268
Fmt. pf ppf " %t%a %s: got %a." (pp_location ?here ?pos) Pp. tag `Fail
269
269
msg Fmt. exn e)
Original file line number Diff line number Diff line change @@ -158,7 +158,9 @@ val check_raises : (string -> exn -> (unit -> unit) -> unit) extra_info
158
158
159
159
val match_raises :
160
160
(string -> (exn -> bool ) -> (unit -> unit ) -> unit ) extra_info
161
- (* * Check that an exception is raised. *)
161
+ (* * [match_raises msg exception_is_expected f] Runs [f ()], and passes the
162
+ raised exception to [exception_is_expected]. The check fails when no
163
+ exception is raised, or [exception_is_expected] returns false. *)
162
164
163
165
val skip : unit -> 'a
164
166
(* * Skip the current test case.
Original file line number Diff line number Diff line change 15
15
isatty
16
16
json_output
17
17
list_tests
18
+ match_raises
18
19
only_monadic_effects
19
20
quick_only
20
21
quick_only_regex
41
42
isatty
42
43
json_output
43
44
list_tests
45
+ match_raises
44
46
only_monadic_effects
45
47
quick_only
46
48
quick_only_regex
621
623
(action
622
624
(diff list_tests -js . expected list_tests -js . processed )))
623
625
626
+ (rule
627
+ (target match_raises . actual )
628
+ (action
629
+ (with -outputs -to %{target }
630
+ (with -accepted -exit -codes (or 0 124 125 )
631
+ (run %{dep :match_raises . exe })))))
632
+
633
+ (rule
634
+ (target match_raises . processed )
635
+ (action
636
+ (with -outputs -to %{target }
637
+ (run .. /.. /strip_randomness . exe %{dep :match_raises . actual }))))
638
+
639
+ (rule
640
+ (alias runtest )
641
+ (package alcotest )
642
+ (action
643
+ (diff match_raises . expected match_raises . processed )))
644
+
645
+ (rule
646
+ (target match_raises -js . actual )
647
+ (action
648
+ (with -outputs -to %{target }
649
+ (with -accepted -exit -codes (or 0 124 125 )
650
+ (run node %{dep :match_raises . bc . js })))))
651
+
652
+ (rule
653
+ (target match_raises -js . processed )
654
+ (action
655
+ (with -outputs -to %{target }
656
+ (run .. /.. /strip_randomness . exe %{dep :match_raises -js . actual }))))
657
+
658
+ (rule
659
+ (alias runtest -js )
660
+ (package alcotest )
661
+ (action
662
+ (diff match_raises -js . expected match_raises -js . processed )))
663
+
624
664
(rule
625
665
(target only_monadic_effects . actual )
626
666
(action
Original file line number Diff line number Diff line change
1
+ Testing `Exceptions'.
2
+ This run has ID `<uuid>'.
3
+
4
+ [OK] matches_raises 0 True means the exception is expec...
5
+
6
+ Full test results in `<build-context>/_build/_tests/<test-dir>'.
7
+ Test Successful in <test-duration>s. 1 test run.
Original file line number Diff line number Diff line change
1
+ Testing `Exceptions'.
2
+ This run has ID `<uuid>'.
3
+
4
+ [OK] matches_raises 0 True means the exception is expec...
5
+
6
+ Full test results in `<build-context>/_build/_tests/<test-dir>'.
7
+ Test Successful in <test-duration>s. 1 test run.
Original file line number Diff line number Diff line change
1
+ let to_test () = raise (Failure " " )
2
+ let expect_failure = function Failure _ -> true | _ -> false
3
+ let test () = Alcotest. match_raises " Generates Failure" expect_failure to_test
4
+
5
+ let () =
6
+ Alcotest. run " Exceptions"
7
+ [
8
+ ( " matches_raises" ,
9
+ [
10
+ Alcotest. test_case " True means the exception is expected" `Quick test;
11
+ ] );
12
+ ]
You can’t perform that action at this time.
0 commit comments