From: Richard Jones Date: Thu, 3 Jun 2010 13:30:36 +0000 (+0100) Subject: tests: Factor out common code into 'is_available' function. X-Git-Tag: 1.2.10~12 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=bfe89cafcb4bba84d48ce8cbe09b53b9dcabca3b;p=libguestfs.git tests: Factor out common code into 'is_available' function. This commit is just code motion. (cherry picked from commit cbe80b2bcfdee437d195f25aaf6f5d96329ab360) --- diff --git a/src/generator.ml b/src/generator.ml index 9c13d40..3c4c8b1 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -6459,6 +6459,19 @@ static void print_table (char const *const *argv) } */ +static int +is_available (const char *group) +{ + const char *groups[] = { group, NULL }; + int r; + + suppress_error = 1; + r = guestfs_available (g, (char **) groups); + suppress_error = 0; + + return r == 0; +} + "; (* Generate a list of commands which are not tested anywhere. *) @@ -6701,16 +6714,9 @@ static int %s (void) List.iter ( function | Optional group -> - pr " {\n"; - pr " const char *groups[] = { \"%s\", NULL };\n" group; - pr " int r;\n"; - pr " suppress_error = 1;\n"; - pr " r = guestfs_available (g, (char **) groups);\n"; - pr " suppress_error = 0;\n"; - pr " if (r == -1) {\n"; - pr " printf (\" %%s skipped (reason: group %%s not available in daemon)\\n\", \"%s\", groups[0]);\n" test_name; - pr " return 0;\n"; - pr " }\n"; + pr " if (!is_available (\"%s\")) {\n" group; + pr " printf (\" %%s skipped (reason: group %%s not available in daemon)\\n\", \"%s\", \"%s\");\n" test_name group; + pr " return 0;\n"; pr " }\n"; | _ -> () ) flags;