File: bad_test.ml

package info (click to toggle)
ppx-expect 0.17.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: ml: 3,399; ansic: 104; javascript: 19; makefile: 15; sh: 2
file content (43 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download | duplicates (2)
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
module Expect_test_config = struct
  include Expect_test_config

  let upon_unreleasable_issue = `Warning_for_collector_testing
end

let get_a_trace () =
  let rec loop n =
    if n < 0
    then Printexc.get_callstack 10, 0
    else (
      let x, y = loop (n - 1) in
      x, y + 1)
  in
  let trace, _ = loop 10 in
  trace
;;

let print_slot trace n =
  match Printexc.backtrace_slots trace with
  | None -> assert false
  | Some slots ->
    let slot = slots.(n) in
    (match Printexc.Slot.format 0 slot with
     | None -> assert false
     | Some str -> print_endline str)
;;

let%expect_test (_ [@tags "no-js"]) =
  (* We create a backtrace with 10 identical slots and then only print the 5th slot.
     Otherwise flambda and non-flambda compilers create slightly different
     backtraces. *)
  let trace = get_a_trace () in
  print_slot trace 5;
  [%expect
    {|
    (* expect_test_collector: This test expectation appears to contain a backtrace.
       This is strongly discouraged as backtraces are fragile.
       Please change this test to not include a backtrace. *)

    Raised by primitive operation at Ppx_expect_test__Bad_test.get_a_trace.loop in file "bad_test.ml", line 12, characters 17-29
    |}]
;;