mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 06:32:10 +01:00
Improve test coverage for GSubprocess
This commit is contained in:
parent
f18138a9cf
commit
a688b2a9c0
@ -163,6 +163,18 @@ env_mode (int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
cwd_mode (int argc, char **argv)
|
||||
{
|
||||
char *cwd;
|
||||
|
||||
cwd = g_get_current_dir ();
|
||||
g_print ("%s\n", cwd);
|
||||
g_free (cwd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@ -208,6 +220,8 @@ main (int argc, char **argv)
|
||||
return write_to_fds (argc, argv);
|
||||
else if (strcmp (mode, "env") == 0)
|
||||
return env_mode (argc, argv);
|
||||
else if (strcmp (mode, "cwd") == 0)
|
||||
return cwd_mode (argc, argv);
|
||||
else
|
||||
{
|
||||
g_printerr ("Unknown MODE %s\n", argv[1]);
|
||||
|
@ -797,6 +797,35 @@ test_env (void)
|
||||
g_object_unref (proc);
|
||||
}
|
||||
|
||||
static void
|
||||
test_cwd (void)
|
||||
{
|
||||
GError *local_error = NULL;
|
||||
GError **error = &local_error;
|
||||
GSubprocessLauncher *launcher;
|
||||
GSubprocess *proc;
|
||||
GPtrArray *args;
|
||||
GInputStream *stdout;
|
||||
gchar *result;
|
||||
|
||||
args = get_test_subprocess_args ("cwd", NULL);
|
||||
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
|
||||
g_subprocess_launcher_set_flags (launcher, G_SUBPROCESS_FLAGS_STDOUT_PIPE);
|
||||
g_subprocess_launcher_set_cwd (launcher, "/tmp");
|
||||
|
||||
proc = g_subprocess_launcher_spawnv (launcher, (const char * const *)args->pdata, error);
|
||||
g_ptr_array_free (args, TRUE);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
stdout = g_subprocess_get_stdout_pipe (proc);
|
||||
|
||||
result = splice_to_string (stdout, error);
|
||||
|
||||
g_assert_cmpstr (result, ==, "/tmp" LINEEND);
|
||||
|
||||
g_free (result);
|
||||
g_object_unref (proc);
|
||||
}
|
||||
#ifdef G_OS_UNIX
|
||||
static void
|
||||
test_stdout_file (void)
|
||||
@ -1044,6 +1073,7 @@ main (int argc, char **argv)
|
||||
g_test_add_func ("/gsubprocess/communicate-utf8-invalid", test_communicate_utf8_invalid);
|
||||
g_test_add_func ("/gsubprocess/terminate", test_terminate);
|
||||
g_test_add_func ("/gsubprocess/env", test_env);
|
||||
g_test_add_func ("/gsubprocess/cwd", test_cwd);
|
||||
#ifdef G_OS_UNIX
|
||||
g_test_add_func ("/gsubprocess/stdout-file", test_stdout_file);
|
||||
g_test_add_func ("/gsubprocess/stdout-fd", test_stdout_fd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user