Skip to content

Commit fb2c249

Browse files
committed
test: test the pattern of printing an exception and raising it
Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent a7ff4cd commit fb2c249

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

test/raiser.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let foo () : unit = raise (Failure "foo")
33
let bar () =
44
try foo () with Failure _ as e -> Backtrace.reraise e (Failure "bar")
55

6+
let baz () = try foo () with exn -> raise exn
67

78
let no_backtraces = ref false
89

@@ -22,15 +23,23 @@ let test_v1_with_backtrace () =
2223
Printexc.record_backtrace false ;
2324
try Test_lib.Log.with_thread_associated_old "Backtrace lab" foo () with _ -> ()
2425

26+
let raise_again = ref false
27+
28+
let test_raise_again () =
29+
Printexc.record_backtrace true ;
30+
try Test_lib.Log.with_thread_associated "Backtrace lab" baz () with _ -> ()
31+
2532
let usage = Printf.sprintf "%s" Sys.argv.(0)
2633
let speclist = [
2734
("-no-backtraces", Arg.Set no_backtraces, "Test no-backtraces")
2835
; ("-reraise", Arg.Set reraise, "Test reraise")
2936
; ("-v1-with-backtrace", Arg.Set v1_with_backtrace, "Test v1-with-backtrace")
37+
; ("-raise-again", Arg.Set raise_again, "Test raise-again")
3038
]
3139

3240
let () =
3341
Arg.parse speclist (Fun.const ()) usage ;
3442
if !no_backtraces then test_no_backtraces () ;
3543
if !reraise then test_reraise () ;
36-
if !v1_with_backtrace then test_v1_with_backtrace ()
44+
if !v1_with_backtrace then test_v1_with_backtrace () ;
45+
if !raise_again then test_raise_again ()

test/reraise.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@
1616
Backtrace lab failed with exception Failure("foo")
1717
Raised Failure("foo")
1818
raiser.exe: Thread 0 has no backtrace table
19+
20+
$ ./raiser.exe -raise-again
21+
Backtrace lab failed with exception Failure("foo")
22+
Raised Failure("foo")
23+
1/4 raiser.exe Raised at file test/raiser.ml, line 1
24+
2/4 raiser.exe Called from file test/raiser.ml, line 6
25+
3/4 raiser.exe Called from file test/raiser.ml, line 6
26+
4/4 raiser.exe Called from file test/log.ml, line 55
27+

0 commit comments

Comments
 (0)