summaryrefslogtreecommitdiffstats
path: root/src/generator.ml
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-15 16:04:27 +0100
committerRichard Jones <rjones@redhat.com>2009-04-15 16:04:27 +0100
commit706c75629733d05a891a81eebe373d124409cfb8 (patch)
treecc05a1110d846f752928ab327a50e427d02c628e /src/generator.ml
parent52471f572ec036a76bc977bcf39cfab179dfbc13 (diff)
downloadlibguestfs-706c75629733d05a891a81eebe373d124409cfb8.tar.gz
libguestfs-706c75629733d05a891a81eebe373d124409cfb8.tar.xz
libguestfs-706c75629733d05a891a81eebe373d124409cfb8.zip
Be strict about commands which don't test themselves, warn about missing tests.
Diffstat (limited to 'src/generator.ml')
-rwxr-xr-xsrc/generator.ml46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/generator.ml b/src/generator.ml
index c20e43fc..f686e660 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -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 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 =
@@ -1359,7 +1365,31 @@ let check_functions () =
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
@@ -2303,8 +2333,20 @@ static void print_table (char * const * const argv)
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, _, _) ->
@@ -2323,6 +2365,8 @@ int main (int argc, char *argv[])
char buf[256];
int nr_tests;
+ no_test_warnings ();
+
g = guestfs_create ();
if (g == NULL) {
printf (\"guestfs_create FAILED\\n\");