diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-11-09 20:33:24 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-11-09 22:48:47 +0000 |
commit | a270faefefe37752de12622bd072c32ea6042e78 (patch) | |
tree | 84426028d6887e50e3ff91628f13beb595d4fed3 | |
parent | 2deb235cf4d30e715507f02b02a0391e1d0c3ee9 (diff) | |
download | libguestfs-a270faefefe37752de12622bd072c32ea6042e78.tar.gz libguestfs-a270faefefe37752de12622bd072c32ea6042e78.tar.xz libguestfs-a270faefefe37752de12622bd072c32ea6042e78.zip |
tests: Use guestfs_{push,pop}_error_handler.
Replace the custom error handler with calls to
guestfs_{push,pop}_error_handler only where necessary. This
simplifies the generated code.
-rw-r--r-- | generator/tests_c_api.ml | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/generator/tests_c_api.ml b/generator/tests_c_api.ml index 67ad0fef..5fd47786 100644 --- a/generator/tests_c_api.ml +++ b/generator/tests_c_api.ml @@ -55,14 +55,6 @@ let rec generate_tests () = //#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) static guestfs_h *g; -static int suppress_error = 0; - -static void -print_error (guestfs_h *g, void *data, const char *msg) -{ - if (!suppress_error) - fprintf (stderr, \"%%s\\n\", msg); -} /* FIXME: nearly identical code appears in fish.c */ static void @@ -80,9 +72,9 @@ is_available (const char *group) const char *groups[] = { group, NULL }; int r; - suppress_error = 1; + guestfs_push_error_handler (g, NULL, NULL); r = guestfs_available (g, (char **) groups); - suppress_error = 0; + guestfs_pop_error_handler (g); return r == 0; } @@ -211,8 +203,6 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - guestfs_set_error_handler (g, print_error, NULL); - filename = \"test1.img\"; fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC|O_CLOEXEC, 0666); if (fd == -1) { @@ -901,7 +891,8 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = pr " size_t size;\n" ); - pr " suppress_error = %d;\n" (if expect_error then 1 else 0); + if expect_error then + pr " guestfs_push_error_handler (g, NULL, NULL);\n"; pr " r = %s (g" f.c_function; (* Generate the parameters. *) @@ -947,6 +938,9 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = pr ");\n"; + if expect_error then + pr " guestfs_pop_error_handler (g);\n"; + (match errcode_of_ret style_ret, expect_error with | `CannotReturnError, _ -> () | `ErrorIsMinusOne, false -> |