Fix some Ocaml tests: the %t substitution now returns an absolute path.
[oota-llvm.git] / test / Bindings / Ocaml / bitwriter.ml
1 (* RUN: %ocamlopt -warn-error A unix.cmxa llvm.cmxa llvm_bitwriter.cmxa %s -o %t
2  * RUN: %t %t.bc
3  * RUN: llvm-dis < %t.bc | grep caml_int_ty
4  *)
5
6 (* Note that this takes a moment to link, so it's best to keep the number of
7    individual tests low. *)
8
9 let context = Llvm.global_context ()
10
11 let test x = if not x then exit 1 else ()
12
13 let read_file name =
14   let ic = open_in_bin name in
15   let len = in_channel_length ic in
16   let buf = String.create len in
17
18   test ((input ic buf 0 len) = len);
19
20   close_in ic;
21
22   buf
23
24 let temp_bitcode ?unbuffered m =
25   let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in
26
27   test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m);
28   flush temp_oc;
29
30   let temp_buf = read_file temp_name in
31
32   close_out temp_oc;
33
34   temp_buf
35
36 let _ =
37   let m = Llvm.create_module context "ocaml_test_module" in
38   
39   ignore (Llvm.define_type_name "caml_int_ty" (Llvm.i32_type context) m);
40
41   test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1));
42   let file_buf = read_file Sys.argv.(1) in
43
44   test (file_buf = temp_bitcode m);
45   test (file_buf = temp_bitcode ~unbuffered:false m);
46   test (file_buf = temp_bitcode ~unbuffered:true m)