summaryrefslogtreecommitdiff
path: root/testsuite/tests/match-exception/nested_handlers.ml
blob: 6f019d4b4b0c4651975d0dddeb93bbea2a454015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(* TEST
*)

(*
  Test that multiple handlers coexist happily.
*)

let test_multiple_handlers =
  let trace = ref [] in
  let collect v = trace := v :: !trace in
  let _ =
    match
      begin
        match
          begin
            collect "one";
            failwith "two"
          end
        with
          () -> collect "failure one"
        | exception (Failure x) ->
          collect x;
          failwith "three"
      end
    with
      () ->
        collect "failure two";
    | exception (Failure x) ->
      collect x;
      match
        begin
          collect "four";
          failwith "five"
        end
      with
        () -> collect "failure three"
      | exception (Failure x) ->
        collect x
  in
  print_endline (String.concat " " !trace);
  assert (!trace = [
    "five";
    "four";
    "three";
    "two";
    "one";
  ])
;;