[OCaml] Enable backtraces in tests.
[oota-llvm.git] / test / Bindings / Ocaml / irreader.ml
1 (* RUN: cp %s %T/irreader.ml
2  * RUN: %ocamlcomp -g -warn-error A -package llvm.irreader -linkpkg %T/irreader.ml -o %t
3  * RUN: %t
4  * XFAIL: vg_leak
5  *)
6
7 (* Note: It takes several seconds for ocamlopt to link an executable with
8          libLLVMCore.a, so it's better to write a big test than a bunch of
9          little ones. *)
10
11 open Llvm
12 open Llvm_irreader
13
14 let context = global_context ()
15
16 (* Tiny unit test framework - really just to help find which line is busted *)
17 let print_checkpoints = false
18
19 let suite name f =
20   if print_checkpoints then
21     prerr_endline (name ^ ":");
22   f ()
23
24 let _ =
25   Printexc.record_backtrace true
26
27 let insist cond =
28   if not cond then failwith "insist"
29
30
31 (*===-- IR Reader ---------------------------------------------------------===*)
32
33 let test_irreader () =
34   begin
35     let buf = MemoryBuffer.of_string "@foo = global i32 42" in
36     let m   = parse_ir context buf in
37     match lookup_global "foo" m with
38     | Some foo ->
39         insist ((global_initializer foo) = (const_int (i32_type context) 42))
40     | None ->
41         failwith "global"
42   end;
43
44   begin
45     let buf = MemoryBuffer.of_string "@foo = global garble" in
46     try
47       ignore (parse_ir context buf);
48       failwith "parsed"
49     with Llvm_irreader.Error _ ->
50       ()
51   end
52
53
54 (*===-- Driver ------------------------------------------------------------===*)
55
56 let _ =
57   suite "irreader" test_irreader