[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/2] mllib: Require OUnit2 for tests.



OUnit2 has an OUnit (v1) compatibility module.  Unfortunately it
is rather gravely broken:
https://forge.ocamlcore.org/tracker/?func=detail&aid=1392&group_id=162&atid=730

Since there is no new release fixing this, it's easier to switch to
using OUnit2 for unit tests.
---
 .gitignore                  |  2 +-
 README                      |  2 +-
 mllib/JSON_tests.ml         | 56 ++++++++++++++++++++-------------------------
 mllib/Makefile.am           |  2 ++
 mllib/common_utils_tests.ml | 50 +++++++++++++++++-----------------------
 5 files changed, 50 insertions(+), 62 deletions(-)

diff --git a/.gitignore b/.gitignore
index d5c6742..2a3cc81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -312,7 +312,7 @@ Makefile.in
 /mllib/JSON_tests
 /mllib/libdir.ml
 /mllib/link.sh
-/mllib/oUnit-anon.cache
+/mllib/oUnit-*
 /ocaml/bindtests.bc
 /ocaml/bindtests.opt
 /ocaml/bindtests.ml
diff --git a/README b/README
index ec08c01..4a5786c 100644
--- a/README
+++ b/README
@@ -242,7 +242,7 @@ The full requirements are described below.
 +--------------+-------------+---+-----------------------------------------+
 | bash-completion            | O | For tab-completion of commands in bash. |
 +--------------+-------------+---+-----------------------------------------+
-| ocaml-ounit  |             | O | For the tests of the common OCaml       |
+| ocaml-ounit  | 2.0.0       | O | For the tests of the common OCaml       |
 |              |             |   | modules.                                |
 +--------------+-------------+---+-----------------------------------------+
 | ocaml-libvirt| 0.6.1.5     | O | For building the virt-v2v test harness. |
diff --git a/mllib/JSON_tests.ml b/mllib/JSON_tests.ml
index fa37171..281d38e 100644
--- a/mllib/JSON_tests.ml
+++ b/mllib/JSON_tests.ml
@@ -18,19 +18,19 @@
 
 (* This file tests the JSON module. *)
 
-open OUnit
+open OUnit2
 
 (* Utils. *)
 let assert_equal_string = assert_equal ~printer:(fun x -> x)
 
 (* "basic" suite. *)
-let test_empty () =
+let test_empty ctx =
   let doc = [] in
   assert_equal_string "{}" (JSON.string_of_doc doc);
   assert_equal_string "{
 }" (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_string () =
+let test_string ctx =
   let doc = [ "test_string", JSON.String "foo"; ] in
   assert_equal_string "{ \"test_string\": \"foo\" }"
     (JSON.string_of_doc doc);
@@ -39,7 +39,7 @@ let test_string () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_bool () =
+let test_bool ctx =
   let doc = [ "test_true", JSON.Bool true;
               "test_false", JSON.Bool false ] in
   assert_equal_string
@@ -52,7 +52,7 @@ let test_bool () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_int () =
+let test_int ctx =
   let doc = [ "test_zero", JSON.Int 0;
               "test_pos", JSON.Int 5;
               "test_neg", JSON.Int (-5);
@@ -71,7 +71,7 @@ let test_int () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_list () =
+let test_list ctx =
   let doc = [ "item", JSON.List [ JSON.String "foo"; JSON.Int 10; JSON.Bool true ] ] in
   assert_equal_string
     "{ \"item\": [ \"foo\", 10, true ] }"
@@ -86,7 +86,7 @@ let test_list () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_nested_dict () =
+let test_nested_dict ctx =
   let doc = [
       "item", JSON.Dict [ "int", JSON.Int 5; "string", JSON.String "foo"; ];
       "last", JSON.Int 10;
@@ -104,7 +104,7 @@ let test_nested_dict () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_nested_nested_dict () =
+let test_nested_nested_dict ctx =
   let doc = [
       "item", JSON.Dict [ "int", JSON.Int 5;
         "item2", JSON.Dict [ "int", JSON.Int 0; ];
@@ -126,7 +126,7 @@ let test_nested_nested_dict () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_escape () =
+let test_escape ctx =
   let doc = [ "test_string", JSON.String "test \" ' \n \b \r \t"; ] in
   assert_equal_string "{ \"test_string\": \"test \\\" ' \\n \\b \\r \\t\" }"
     (JSON.string_of_doc doc);
@@ -136,7 +136,7 @@ let test_escape () =
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
 (* "examples" suite. *)
-let test_qemu () =
+let test_qemu ctx =
   let doc = [
     "file.driver", JSON.String "https";
     "file.url", JSON.String "https://libguestfs.org";;
@@ -155,7 +155,7 @@ let test_qemu () =
 }"
     (JSON.string_of_doc ~fmt:JSON.Indented doc)
 
-let test_builder () =
+let test_builder ctx =
   let doc = [
     "version", JSON.Int 1;
     "sources", JSON.List [
@@ -221,25 +221,19 @@ let test_builder () =
 
 (* Suites declaration. *)
 let suite =
-  TestList ([
-    "basic" >::: [
-      "empty" >:: test_empty;
-      "string" >:: test_string;
-      "bool" >:: test_bool;
-      "int" >:: test_int;
-      "list" >:: test_list;
-      "nested dict" >:: test_nested_dict;
-      "nested nested dict" >:: test_nested_nested_dict;
-      "escape" >:: test_escape;
-    ];
-    "examples" >::: [
-      "qemu" >:: test_qemu;
-      "virt-builder" >:: test_builder;
-    ];
-  ])
-
-let _ =
-  run_test_tt_main suite
+  "mllib JSON" >:::
+    [
+      "basic.empty" >:: test_empty;
+      "basic.string" >:: test_string;
+      "basic.bool" >:: test_bool;
+      "basic.int" >:: test_int;
+      "basic.list" >:: test_list;
+      "basic.nested_dict" >:: test_nested_dict;
+      "basic.nested_nested dict" >:: test_nested_nested_dict;
+      "basic.escape" >:: test_escape;
+      "examples.qemu" >:: test_qemu;
+      "examples.virt-builder" >:: test_builder;
+    ]
 
 let () =
-  Printf.fprintf stderr "\n"
+  run_test_tt_main suite
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index d5faf19..0b43684 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -165,6 +165,8 @@ if HAVE_OCAML_PKG_OUNIT
 TESTS += common_utils_tests JSON_tests
 endif
 
+CLEANFILES += oUnit-*
+
 check-valgrind:
 	$(MAKE) VG="$(top_builddir)/run @VG@" check
 
diff --git a/mllib/common_utils_tests.ml b/mllib/common_utils_tests.ml
index 283e9a1..a06476b 100644
--- a/mllib/common_utils_tests.ml
+++ b/mllib/common_utils_tests.ml
@@ -1,5 +1,5 @@
-(* virt-resize
- * Copyright (C) 2011 Red Hat Inc.
+(* Common utilities for OCaml tools in libguestfs.
+ * Copyright (C) 2011-2015 Red Hat Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
 
 (* This file tests the Common_utils module. *)
 
-open OUnit
+open OUnit2
 open Common_utils
 
 let prog = "common_utils_tests"
@@ -30,12 +30,12 @@ let assert_equal_int64 = assert_equal ~printer:(fun x -> Int64.to_string x)
 let assert_equal_stringlist = assert_equal ~printer:(fun x -> "(" ^ (String.escaped (String.concat "," x)) ^ ")")
 
 (* Test Common_utils.int_of_le32 and Common_utils.le32_of_int. *)
-let test_le32 () =
+let test_le32 ctx =
   assert_equal_int64 0x20406080L (int_of_le32 "\x80\x60\x40\x20");
   assert_equal_string "\x80\x60\x40\x20" (le32_of_int 0x20406080L)
 
 (* Test Common_utils.parse_size. *)
-let test_parse_resize () =
+let test_parse_resize ctx =
   (* For absolute sizes, oldsize is ignored. *)
   assert_equal_int64 100_L (parse_resize ~prog 100_L "100b");
   assert_equal_int64 100_L (parse_resize ~prog 1000_L "100b");
@@ -74,7 +74,7 @@ let test_parse_resize () =
   assert_equal_int64 101100_L (parse_resize ~prog 100000_L "+1.12%")
 
 (* Test Common_utils.human_size. *)
-let test_human_size () =
+let test_human_size ctx =
   assert_equal_string "100" (human_size 100_L);
   assert_equal_string "-100" (human_size (-100_L));
   assert_equal_string "1.0K" (human_size 1024_L);
@@ -87,7 +87,7 @@ let test_human_size () =
   assert_equal_string "-3.4G" (human_size (-3650722201_L))
 
 (* Test Common_utils.string_prefix. *)
-let test_string_prefix () =
+let test_string_prefix ctx =
   assert_bool "string_prefix,," (string_prefix "" "");
   assert_bool "string_prefix,foo," (string_prefix "foo" "");
   assert_bool "string_prefix,foo,foo" (string_prefix "foo" "foo");
@@ -95,7 +95,7 @@ let test_string_prefix () =
   assert_bool "not (string_prefix,,foo" (not (string_prefix "" "foo"))
 
 (* Test Common_utils.string_suffix. *)
-let test_string_suffix () =
+let test_string_suffix ctx =
   assert_bool "string_suffix,," (string_suffix "" "");
   assert_bool "string_suffix,foo," (string_suffix "foo" "");
   assert_bool "string_suffix,foo,foo" (string_suffix "foo" "foo");
@@ -103,7 +103,7 @@ let test_string_suffix () =
   assert_bool "not string_suffix,,foo" (not (string_suffix "" "foo"))
 
 (* Test Common_utils.string_find. *)
-let test_string_find () =
+let test_string_find ctx =
   assert_equal_int 0 (string_find "" "");
   assert_equal_int 0 (string_find "foo" "");
   assert_equal_int 1 (string_find "foo" "o");
@@ -112,7 +112,7 @@ let test_string_find () =
   assert_equal_int (-1) (string_find "foobar" "baz")
 
 (* Test Common_utils.string_lines_split. *)
-let test_string_lines_split () =
+let test_string_lines_split ctx =
   assert_equal_stringlist [""] (string_lines_split "");
   assert_equal_stringlist ["A"] (string_lines_split "A");
   assert_equal_stringlist ["A"; ""] (string_lines_split "A\n");
@@ -129,24 +129,16 @@ let test_string_lines_split () =
 
 (* Suites declaration. *)
 let suite =
-  TestList ([
-    "numeric" >::: [
-      "le32" >:: test_le32;
-    ];
-    "sizes" >::: [
-      "parse_resize" >:: test_parse_resize;
-      "human_size" >:: test_human_size;
-    ];
-    "strings" >::: [
-      "prefix" >:: test_string_prefix;
-      "suffix" >:: test_string_suffix;
-      "find" >:: test_string_find;
-      "string_lines_split" >:: test_string_lines_split;
-    ];
-  ])
-
-let _ =
-  run_test_tt_main suite
+  "mllib Common_utils" >:::
+    [
+      "numeric.le32" >:: test_le32;
+      "sizes.parse_resize" >:: test_parse_resize;
+      "sizes.human_size" >:: test_human_size;
+      "strings.prefix" >:: test_string_prefix;
+      "strings.suffix" >:: test_string_suffix;
+      "strings.find" >:: test_string_find;
+      "strings.string_lines_split" >:: test_string_lines_split;
+    ]
 
 let () =
-  Printf.fprintf stderr "\n"
+  run_test_tt_main suite
-- 
2.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]