Be strict about commands which don't test themselves, warn about missing tests.
authorRichard Jones <rjones@redhat.com>
Wed, 15 Apr 2009 15:04:27 +0000 (16:04 +0100)
committerRichard Jones <rjones@redhat.com>
Wed, 15 Apr 2009 15:04:27 +0000 (16:04 +0100)
src/generator.ml
tests.c

index c20e43f..f686e66 100755 (executable)
@@ -1258,6 +1258,12 @@ let mapi f xs =
 let name_of_argt = function
   | String n | OptString n | StringList n | Bool n | Int n -> n
 
 let name_of_argt = function
   | String n | OptString n | StringList n | Bool n | Int n -> n
 
+let seq_of_test = function
+  | TestRun s | TestOutput (s, _) | TestOutputList (s, _)
+  | TestOutputInt (s, _) | TestOutputTrue s | TestOutputFalse s
+  | TestOutputLength (s, _) | TestOutputStruct (s, _)
+  | TestLastFail s -> s
+
 (* Check function names etc. for consistency. *)
 let check_functions () =
   let contains_uppercase str =
 (* Check function names etc. for consistency. *)
 let check_functions () =
   let contains_uppercase str =
@@ -1359,7 +1365,31 @@ let check_functions () =
        failwithf "%s and %s have conflicting procedure numbers (%d, %d)"
          name1 name2 nr1 nr2
   in
        failwithf "%s and %s have conflicting procedure numbers (%d, %d)"
          name1 name2 nr1 nr2
   in
-  loop proc_nrs
+  loop proc_nrs;
+
+  (* Check tests. *)
+  List.iter (
+    function
+      (* Ignore functions that have no tests.  We generate a
+       * warning when the user does 'make check' instead.
+       *)
+    | name, _, _, _, [], _, _ -> ()
+    | name, _, _, _, tests, _, _ ->
+       let funcs =
+         List.map (
+           fun (_, test) ->
+             match seq_of_test test with
+             | [] ->
+                 failwithf "%s has a test containing an empty sequence" name
+             | cmds -> List.map List.hd cmds
+         ) tests in
+       let funcs = List.flatten funcs in
+
+       let tested = List.mem name funcs in
+
+       if not tested then
+         failwithf "function %s has tests but does not test itself" name
+  ) all_functions
 
 (* 'pr' prints to the current output file. *)
 let chan = ref stdout
 
 (* 'pr' prints to the current output file. *)
 let chan = ref stdout
@@ -2303,8 +2333,20 @@ static void print_table (char * const * const argv)
     printf (\"%%s: %%s\\n\", argv[i], argv[i+1]);
 }
 
     printf (\"%%s: %%s\\n\", argv[i], argv[i+1]);
 }
 
+static void no_test_warnings (void)
+{
 ";
 
 ";
 
+  List.iter (
+    function
+    | name, _, _, _, [], _, _ ->
+       pr "  fprintf (stderr, \"warning: \\\"%s\\\" has no tests\\n\");\n" name
+    | name, _, _, _, tests, _, _ -> ()
+  ) all_functions;
+
+  pr "}\n";
+  pr "\n";
+
   let test_names =
     List.map (
       fun (name, _, _, _, tests, _, _) ->
   let test_names =
     List.map (
       fun (name, _, _, _, tests, _, _) ->
@@ -2323,6 +2365,8 @@ int main (int argc, char *argv[])
   char buf[256];
   int nr_tests;
 
   char buf[256];
   int nr_tests;
 
+  no_test_warnings ();
+
   g = guestfs_create ();
   if (g == NULL) {
     printf (\"guestfs_create FAILED\\n\");
   g = guestfs_create ();
   if (g == NULL) {
     printf (\"guestfs_create FAILED\\n\");
diff --git a/tests.c b/tests.c
index 2791145..aef5dd0 100644 (file)
--- a/tests.c
+++ b/tests.c
@@ -53,6 +53,46 @@ static void print_table (char * const * const argv)
     printf ("%s: %s\n", argv[i], argv[i+1]);
 }
 
     printf ("%s: %s\n", argv[i], argv[i+1]);
 }
 
+static void no_test_warnings (void)
+{
+  fprintf (stderr, "warning: \"launch\" has no tests\n");
+  fprintf (stderr, "warning: \"wait_ready\" has no tests\n");
+  fprintf (stderr, "warning: \"kill_subprocess\" has no tests\n");
+  fprintf (stderr, "warning: \"add_drive\" has no tests\n");
+  fprintf (stderr, "warning: \"add_cdrom\" has no tests\n");
+  fprintf (stderr, "warning: \"config\" has no tests\n");
+  fprintf (stderr, "warning: \"set_path\" has no tests\n");
+  fprintf (stderr, "warning: \"get_path\" has no tests\n");
+  fprintf (stderr, "warning: \"set_autosync\" has no tests\n");
+  fprintf (stderr, "warning: \"get_autosync\" has no tests\n");
+  fprintf (stderr, "warning: \"set_verbose\" has no tests\n");
+  fprintf (stderr, "warning: \"get_verbose\" has no tests\n");
+  fprintf (stderr, "warning: \"ll\" has no tests\n");
+  fprintf (stderr, "warning: \"pvs_full\" has no tests\n");
+  fprintf (stderr, "warning: \"vgs_full\" has no tests\n");
+  fprintf (stderr, "warning: \"lvs_full\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_init\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_close\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_defvar\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_defnode\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_get\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_set\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_insert\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_rm\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_mv\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_match\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_save\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_load\" has no tests\n");
+  fprintf (stderr, "warning: \"aug_ls\" has no tests\n");
+  fprintf (stderr, "warning: \"chmod\" has no tests\n");
+  fprintf (stderr, "warning: \"chown\" has no tests\n");
+  fprintf (stderr, "warning: \"sfdisk\" has no tests\n");
+  fprintf (stderr, "warning: \"lvm_remove_all\" has no tests\n");
+  fprintf (stderr, "warning: \"command\" has no tests\n");
+  fprintf (stderr, "warning: \"command_lines\" has no tests\n");
+  fprintf (stderr, "warning: \"tune2fs_l\" has no tests\n");
+}
+
 static int test_mount_0 (void)
 {
   /* InitEmpty for mount (0) */
 static int test_mount_0 (void)
 {
   /* InitEmpty for mount (0) */
@@ -3723,6 +3763,8 @@ int main (int argc, char *argv[])
   char buf[256];
   int nr_tests;
 
   char buf[256];
   int nr_tests;
 
+  no_test_warnings ();
+
   g = guestfs_create ();
   if (g == NULL) {
     printf ("guestfs_create FAILED\n");
   g = guestfs_create ();
   if (g == NULL) {
     printf ("guestfs_create FAILED\n");