Remove tests for APIs that were removed.
[llvm/stm8.git] / test / Bindings / Ocaml / bitreader.ml
blobe5beccd118bd84f1be1f05abae2b3814293d9cea
1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_bitreader.cmxa llvm_bitwriter.cmxa %s -o %t
2 * RUN: %t %t.bc
3 * RUN: llvm-dis < %t.bc
4 * XFAIL: vg_leak
5 *)
7 (* Note that this takes a moment to link, so it's best to keep the number of
8 individual tests low. *)
10 let context = Llvm.global_context ()
12 let test x = if not x then exit 1 else ()
14 let _ =
15 let fn = Sys.argv.(1) in
16 let m = Llvm.create_module context "ocaml_test_module" in
18 test (Llvm_bitwriter.write_bitcode_file m fn);
20 Llvm.dispose_module m;
22 (* parse_bitcode *)
23 begin
24 let mb = Llvm.MemoryBuffer.of_file fn in
25 begin try
26 let m = Llvm_bitreader.parse_bitcode context mb in
27 Llvm.dispose_module m
28 with x ->
29 Llvm.MemoryBuffer.dispose mb;
30 raise x
31 end
32 end;
34 (* MemoryBuffer.of_file *)
35 test begin try
36 let mb = Llvm.MemoryBuffer.of_file (fn ^ ".bogus") in
37 Llvm.MemoryBuffer.dispose mb;
38 false
39 with Llvm.IoError _ ->
40 true
41 end;
43 (* get_module *)
44 begin
45 let mb = Llvm.MemoryBuffer.of_file fn in
46 let m = begin try
47 Llvm_bitreader.get_module context mb
48 with x ->
49 Llvm.MemoryBuffer.dispose mb;
50 raise x
51 end in
52 Llvm.dispose_module m
53 end;
55 (* corrupt the bitcode *)
56 let fn = fn ^ ".txt" in
57 begin let oc = open_out fn in
58 output_string oc "not a bitcode file\n";
59 close_out oc
60 end;
62 (* test get_module exceptions *)
63 test begin
64 try
65 let mb = Llvm.MemoryBuffer.of_file fn in
66 let m = begin try
67 Llvm_bitreader.get_module context mb
68 with x ->
69 Llvm.MemoryBuffer.dispose mb;
70 raise x
71 end in
72 Llvm.dispose_module m;
73 false
74 with Llvm_bitreader.Error _ ->
75 true
76 end