From 9895b28d25308a5ad793496a26ef19b295f19dfa Mon Sep 17 00:00:00 2001 From: Leo White Date: Sat, 18 Apr 2020 14:43:47 +0100 Subject: [PATCH] Add tests for backtraces from forcing lazy values --- testsuite/tests/backtrace/lazy.ml | 28 ++++++++++++++++++++++++ testsuite/tests/backtrace/lazy.reference | 11 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 testsuite/tests/backtrace/lazy.ml create mode 100644 testsuite/tests/backtrace/lazy.reference diff --git a/testsuite/tests/backtrace/lazy.ml b/testsuite/tests/backtrace/lazy.ml new file mode 100644 index 000000000..99c0735d7 --- /dev/null +++ b/testsuite/tests/backtrace/lazy.ml @@ -0,0 +1,28 @@ +(* TEST + flags = "-g" + compare_programs = "false" + * native +*) + + +let l1 : unit lazy_t = lazy (raise Not_found) + +let test1 () = + let () = Lazy.force l1 in () + +let l2 : unit lazy_t = lazy (raise Not_found) + +let test2 () = + let (lazy ()) = l2 in () + +let run test = + try + test (); + with exn -> + Printf.printf "Uncaught exception %s\n" (Printexc.to_string exn); + Printexc.print_backtrace stdout + +let () = + Printexc.record_backtrace true; + run test1; + run test2 diff --git a/testsuite/tests/backtrace/lazy.reference b/testsuite/tests/backtrace/lazy.reference new file mode 100644 index 000000000..575da064f --- /dev/null +++ b/testsuite/tests/backtrace/lazy.reference @@ -0,0 +1,11 @@ +Uncaught exception Not_found +Raised at Lazy.l1 in file "lazy.ml", line 8, characters 28-45 +Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27 +Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11 +Called from Lazy.run in file "lazy.ml", line 20, characters 4-11 +Uncaught exception Not_found +Raised at Lazy.l2 in file "lazy.ml", line 13, characters 28-45 +Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27 +Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11 +Called from Lazy.test2 in file "lazy.ml", line 16, characters 6-15 +Called from Lazy.run in file "lazy.ml", line 20, characters 4-11