From fb0951e67aa8f650f76d6e9bddf4f93c42c57735 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 8 Apr 2012 10:21:50 -0400 Subject: [PATCH] spawn: Improve test coverage Add a test that excercises the script execution code. Unfortunately, much of this code only runs in the forked child, and therefore its execution does not get caught by gcov. --- glib/tests/echo-script | 1 + glib/tests/spawn-singlethread.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 glib/tests/echo-script diff --git a/glib/tests/echo-script b/glib/tests/echo-script new file mode 100755 index 0000000..c732ed9 --- /dev/null +++ b/glib/tests/echo-script @@ -0,0 +1 @@ +echo "echo" diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index 42d88e6..e63e789 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -27,6 +27,7 @@ #include static char *echo_prog_path; +static char *echo_script_path; typedef struct { GMainLoop *loop; @@ -164,6 +165,25 @@ test_spawn_sync (void) g_ptr_array_free (argv, TRUE); } +static void +test_spawn_script (void) +{ + GError *error = NULL; + GPtrArray *argv; + char *stdout_str; + int estatus; + + argv = g_ptr_array_new (); + g_ptr_array_add (argv, echo_script_path); + g_ptr_array_add (argv, NULL); + + g_spawn_sync (NULL, (char**)argv->pdata, NULL, 0, NULL, NULL, &stdout_str, NULL, &estatus, &error); + g_assert_no_error (error); + g_assert_cmpstr ("echo\n", ==, stdout_str); + g_free (stdout_str); + g_ptr_array_free (argv, TRUE); +} + int main (int argc, char *argv[]) @@ -174,17 +194,29 @@ main (int argc, dirname = g_path_get_dirname (argv[0]); echo_prog_path = g_build_filename (dirname, "test-spawn-echo", NULL); + echo_script_path = g_build_filename (dirname, "echo-script", NULL); if (!g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)) { g_free (echo_prog_path); echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo", NULL); } + if (!g_file_test (echo_script_path, G_FILE_TEST_EXISTS)) + { + gchar *tmp; + /* strip .libs */ + tmp = g_path_get_dirname (dirname); + g_free (echo_script_path); + echo_script_path = g_build_filename (tmp, "echo-script", NULL); + g_free (tmp); + } g_free (dirname); g_assert (g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)); + g_assert (g_file_test (echo_script_path, G_FILE_TEST_EXISTS)); g_test_add_func ("/gthread/spawn-single-sync", test_spawn_sync); g_test_add_func ("/gthread/spawn-single-async", test_spawn_async); + g_test_add_func ("/gthread/spawn-script", test_spawn_script); return g_test_run(); } -- 2.7.4