Commits

camlspotter committed 52b21e6

moved tests to tests

  • Participants
  • Parent commits f06897d
  • Branches dev

Comments (0)

Files changed (5)

 autoapi.ml : auto.ml module.pl $(addsuffix .idl.in, $(IDLS))
     ./module.pl *.idl.in > $@
 
+api.cmo api.cmi api.cmx: autoapi.cmi
+
 api.auto.mli: api.cmi api.ml
 
 OOApiauto.ml: api.auto.mli oowrap/oowrap.cmo

test.ml

-open Opycaml.Api (* Use the API *)
-
-let _ = 
-  prerr_endline "start";
-  Base.initialize () (* CR jfuruse: Actually, no effect, since this is called inside api.ml *)
-;;
-
-let _ =
-  prerr_endline "*** import non-existing module";
-  try
-    ignore (Import.importModule "hogehoge")
-  with
-  | Error (e, detail) ->
-      Printf.eprintf "Error: %s %s\n%!" (Py.String.asString (Object.repr e)) (Py.String.asString (Object.repr detail))
-	(* Opycaml.Api.Py.String is not available as
-	   Opycaml.Api.String, to avoid the name collision with the original OCaml String module under ``open Opycaml.Api''.
-	*)
-;;
-
-let _ =
-  prerr_endline "*** create string";
-  let o = Py.String.fromString "hello world" in
-  Base.debug "o" o;
-
-  prerr_endline "*** phys_equality";
-  assert (Base.phys_eq o o);
-
-  prerr_endline "*** repr";
-  let repr = Object.repr o in
-  Base.debug "repr" repr;
-
-  prerr_endline "*** hash";
-  let hash = Object.hash o in
-  Printf.eprintf "hash=%nd\n%!" hash;
-
-  try
-    prerr_endline "*** importing string module";
-    let stringModule = Import.importModule "string" in (* from string import * *)
-    Base.debug "stringModule" stringModule;
-
-    prerr_endline "*** dict of string";
-    let dict = Module.getDict stringModule in
-    (* Base.debug "dict" dict; *)
-
-    prerr_endline "*** get lowercase";
-    let lowercase = Dict.getItemString dict "lowercase" in
-    Base.debug "lowercase" lowercase;
-
-    prerr_endline "*** get capitalize";
-    let capitalize = Dict.getItemString dict "capitalize" in
-    Base.debug "capitalize" capitalize;
-
-    prerr_endline "*** check callable of capitalize";
-    if not (Callable.check capitalize) then begin
-      prerr_endline "capitalize is not a function!";
-      failwith "capitalize is not a function!";
-    end;
-
-    prerr_endline "*** tuple creation";
-    let tpl = Tuple.new_ 1 in
-    Base.debug "tpl" tpl;
-
-    prerr_endline "*** tuple setting";
-    prerr_endline "* ref count before:";
-    Base.debug "o" o;
-    Tuple.setItem tpl 0 o;
-    prerr_endline "* tuple set";
-    prerr_endline "* ref count after:";
-    Base.debug "tuple" tpl;
-    Base.debug "o" o; (* ref by tuple and o *)
-
-    prerr_endline "*** getItem";
-    let x = Tuple.getItem tpl 0 in
-    Base.debug "x" x; (* ref by tuple, o and x *) 
-    Base.debug "o" o; (* ref by tuple, o and x *) 
-
-    prerr_endline "*** GET_ITEM";
-    let xx = Tuple._GET_ITEM tpl 0 in
-    Base.debug "xx" xx; (* ref by tuple, o, x and xx *)
-    Base.debug "o" o;
-
-    prerr_endline "*** calling function";
-    let res = Object.callObject (Callable.coerce capitalize) [o] in
-    Printf.eprintf "res : refcnt = %d\n%!" (Base.refcnt res);
-    prerr_endline "* function called!";
-    prerr_endline (Py.String.asString (Py.String.coerce res));
-    prerr_endline (Py.String.asString o);
-
-    prerr_endline "*** fromLong (-1)";
-    let minus_1 = Int.fromLong (-1) in
-    assert (Int.asLong minus_1 = -1); 
-
-    prerr_endline "*** Run.simpleString";
-    Run.simpleString "print 'Run.simpleString'";
-    (* Run.simpleString "print(string.lowercase)"; *) (* does not work *)
-    (* Run.simpleString "print(lowercase)"; *) (* does not work *)
-
-    prerr_endline "*** registering opycaml command";
-    (* Register test command in python *)
-    Hashtbl.add Py.Callback.functions "test" 
-      (fun (self_opt : _Object t option) (args : _Object t list) ->
-	Format.eprintf "With self: %b@." (self_opt <> None);
-	Format.eprintf "#Args %d@." (List.length args);
-	Object.obj (Base.none ()));
-      (* Opycaml.Api.Py.Callback is not available as
-	 Opycaml.Api.Callback, to avoid the name collision with the original OCaml Callback module under ``open Opycaml.Api''.
-      *)
-    prerr_endline "* Now you can use opycaml.ocaml(\"test\", 1, 2, 3) to call the test OCaml function from Python";
-
-    prerr_endline "*** module insertion";
-    let m = Import.importModule "opycaml" in
-    Module.setItemString m "bar" xx;
-    prerr_endline "* check / import opycaml / opycaml.__dict__ / opycaml.bar";
-
-    prerr_endline "*** new module creation";
-    let m = Module.new_ "foo" in
-    Module.setItemString m "bar" xx;
-    Module.setToSys "foo" m;
-    prerr_endline "* check / import foo / foo.__dict__ / foo.bar";
-
-    prerr_endline "*** OCaml value embedding";
-    (* OCaml value => _Object t *)
-    let py_ocaml_1 = Base.unsafe_embed 1 in
-    Base.debug "py_ocaml_1" py_ocaml_1;
-
-    prerr_endline "*** inserting a closure into module opycaml";
-    let f (args : _Tuple t) : _Object t =
-      let i = ref 0 in
-      List.iter (fun t -> 
-	Format.eprintf "Arg %d : %s@." !i (Object.repr_string t);
-	incr i;
-      ) (Tuple.to_list args);
-      Object.obj (Base.none ())
-    in
-    
-    let m = Import.importModule "opycaml" in
-    Module.setClosureString m "f" f;
-    prerr_endline "* check / import opycaml / opycaml.__dict__ / opycaml.f(1)";
-
-    prerr_endline "*** Entering the toploop";
-    ignore (Base.main []);
-    prerr_endline "exited from toploop";
-
-  with
-  | Error (e, detail) -> 
-      Printf.eprintf "Error: %s %s\n%!" (Py.String.asString (Object.repr e)) (Py.String.asString (Object.repr detail))
-;;
-
-let _ = Base.finalize ()

test_bug1.ml

-open Opycaml.Api
-
-let _ = 
-  Base.initialize ();
-  ignore (Base.main []);
-  (* We cannot import things after Base.main ??? *)
-  ignore (Import.importModule "hogehoge"); 
-  Base.finalize ();
-  prerr_endline "finished"
-
+open Opycaml.Api (* Use the API *)
+
+let _ = 
+  prerr_endline "start";
+  Base.initialize () (* CR jfuruse: Actually, no effect, since this is called inside api.ml *)
+;;
+
+let _ =
+  prerr_endline "*** import non-existing module";
+  try
+    ignore (Import.importModule "hogehoge")
+  with
+  | Error (e, detail) ->
+      Printf.eprintf "Error: %s %s\n%!" (Py.String.asString (Object.repr e)) (Py.String.asString (Object.repr detail))
+	(* Opycaml.Api.Py.String is not available as
+	   Opycaml.Api.String, to avoid the name collision with the original OCaml String module under ``open Opycaml.Api''.
+	*)
+;;
+
+let _ =
+  prerr_endline "*** create string";
+  let o = Py.String.fromString "hello world" in
+  Base.debug "o" o;
+
+  prerr_endline "*** phys_equality";
+  assert (Base.phys_eq o o);
+
+  prerr_endline "*** repr";
+  let repr = Object.repr o in
+  Base.debug "repr" repr;
+
+  prerr_endline "*** hash";
+  let hash = Object.hash o in
+  Printf.eprintf "hash=%nd\n%!" hash;
+
+  try
+    prerr_endline "*** importing string module";
+    let stringModule = Import.importModule "string" in (* from string import * *)
+    Base.debug "stringModule" stringModule;
+
+    prerr_endline "*** dict of string";
+    let dict = Module.getDict stringModule in
+    (* Base.debug "dict" dict; *)
+
+    prerr_endline "*** get lowercase";
+    let lowercase = Dict.getItemString dict "lowercase" in
+    Base.debug "lowercase" lowercase;
+
+    prerr_endline "*** get capitalize";
+    let capitalize = Dict.getItemString dict "capitalize" in
+    Base.debug "capitalize" capitalize;
+
+    prerr_endline "*** check callable of capitalize";
+    if not (Callable.check capitalize) then begin
+      prerr_endline "capitalize is not a function!";
+      failwith "capitalize is not a function!";
+    end;
+
+    prerr_endline "*** tuple creation";
+    let tpl = Tuple.new_ 1 in
+    Base.debug "tpl" tpl;
+
+    prerr_endline "*** tuple setting";
+    prerr_endline "* ref count before:";
+    Base.debug "o" o;
+    Tuple.setItem tpl 0 o;
+    prerr_endline "* tuple set";
+    prerr_endline "* ref count after:";
+    Base.debug "tuple" tpl;
+    Base.debug "o" o; (* ref by tuple and o *)
+
+    prerr_endline "*** getItem";
+    let x = Tuple.getItem tpl 0 in
+    Base.debug "x" x; (* ref by tuple, o and x *) 
+    Base.debug "o" o; (* ref by tuple, o and x *) 
+
+    prerr_endline "*** GET_ITEM";
+    let xx = Tuple._GET_ITEM tpl 0 in
+    Base.debug "xx" xx; (* ref by tuple, o, x and xx *)
+    Base.debug "o" o;
+
+    prerr_endline "*** calling function";
+    let res = Object.callObject (Callable.coerce capitalize) [o] in
+    Printf.eprintf "res : refcnt = %d\n%!" (Base.refcnt res);
+    prerr_endline "* function called!";
+    prerr_endline (Py.String.asString (Py.String.coerce res));
+    prerr_endline (Py.String.asString o);
+
+    prerr_endline "*** fromLong (-1)";
+    let minus_1 = Int.fromLong (-1) in
+    assert (Int.asLong minus_1 = -1); 
+
+    prerr_endline "*** Run.simpleString";
+    Run.simpleString "print 'Run.simpleString'";
+    (* Run.simpleString "print(string.lowercase)"; *) (* does not work *)
+    (* Run.simpleString "print(lowercase)"; *) (* does not work *)
+
+    prerr_endline "*** registering opycaml command";
+    (* Register test command in python *)
+    Hashtbl.add Py.Callback.functions "test" 
+      (fun (self_opt : _Object t option) (args : _Object t list) ->
+	Format.eprintf "With self: %b@." (self_opt <> None);
+	Format.eprintf "#Args %d@." (List.length args);
+	Object.obj (Base.none ()));
+      (* Opycaml.Api.Py.Callback is not available as
+	 Opycaml.Api.Callback, to avoid the name collision with the original OCaml Callback module under ``open Opycaml.Api''.
+      *)
+    prerr_endline "* Now you can use opycaml.ocaml(\"test\", 1, 2, 3) to call the test OCaml function from Python";
+
+    prerr_endline "*** module insertion";
+    let m = Import.importModule "opycaml" in
+    Module.setItemString m "bar" xx;
+    prerr_endline "* check / import opycaml / opycaml.__dict__ / opycaml.bar";
+
+    prerr_endline "*** new module creation";
+    let m = Module.new_ "foo" in
+    Module.setItemString m "bar" xx;
+    Module.setToSys "foo" m;
+    prerr_endline "* check / import foo / foo.__dict__ / foo.bar";
+
+    prerr_endline "*** OCaml value embedding";
+    (* OCaml value => _Object t *)
+    let py_ocaml_1 = Base.unsafe_embed 1 in
+    Base.debug "py_ocaml_1" py_ocaml_1;
+
+    prerr_endline "*** inserting a closure into module opycaml";
+    let f (args : _Tuple t) : _Object t =
+      let i = ref 0 in
+      List.iter (fun t -> 
+	Format.eprintf "Arg %d : %s@." !i (Object.repr_string t);
+	incr i;
+      ) (Tuple.to_list args);
+      Object.obj (Base.none ())
+    in
+    
+    let m = Import.importModule "opycaml" in
+    Module.setClosureString m "f" f;
+    prerr_endline "* check / import opycaml / opycaml.__dict__ / opycaml.f(1)";
+
+    prerr_endline "*** Entering the toploop";
+    ignore (Base.main []);
+    prerr_endline "exited from toploop";
+
+  with
+  | Error (e, detail) -> 
+      Printf.eprintf "Error: %s %s\n%!" (Py.String.asString (Object.repr e)) (Py.String.asString (Object.repr detail))
+;;
+
+let _ = Base.finalize ()

tests/test_bug1.ml

+open Opycaml.Api
+
+let _ = 
+  Base.initialize ();
+  ignore (Base.main []);
+  (* We cannot import things after Base.main ??? *)
+  ignore (Import.importModule "hogehoge"); 
+  Base.finalize ();
+  prerr_endline "finished"
+