Commit 2b11af4f authored by Allison Karlitskaya's avatar Allison Karlitskaya

gsubprocess: test environment a bit more

Add a test for GSubprocess to test setting, unsetting and inheritance of
environment variables.  Use communicate() to give it a bit more of a
workout as well.
parent e767204e
......@@ -175,6 +175,22 @@ cwd_mode (int argc, char **argv)
return 0;
static int
printenv_mode (int argc, char **argv)
gint i;
for (i = 2; i < argc; i++)
const gchar *value = g_getenv (argv[i]);
if (value != NULL)
g_print ("%s=%s\n", argv[i], value);
return 0;
main (int argc, char **argv)
......@@ -222,6 +238,8 @@ main (int argc, char **argv)
return env_mode (argc, argv);
else if (strcmp (mode, "cwd") == 0)
return cwd_mode (argc, argv);
else if (strcmp (mode, "printenv") == 0)
return printenv_mode (argc, argv);
g_printerr ("Unknown MODE %s\n", argv[1]);
......@@ -1203,6 +1203,40 @@ test_pass_fd (void)
static void
test_launcher_environment (void)
GSubprocessLauncher *launcher;
GError *error = NULL;
GSubprocess *proc;
GPtrArray *args;
gchar *out;
g_setenv ("A", "B", TRUE);
g_setenv ("C", "D", TRUE);
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE);
/* unset a variable */
g_subprocess_launcher_unsetenv (launcher, "A");
/* and set a diffferent one */
g_subprocess_launcher_setenv (launcher, "E", "F", TRUE);
args = get_test_subprocess_args ("printenv", "A", "C", "E", NULL);
proc = g_subprocess_launcher_spawnv (launcher, (const gchar **) args->pdata, &error);
g_assert_no_error (error);
g_assert (proc);
g_subprocess_communicate_utf8 (proc, NULL, NULL, &out, NULL, &error);
g_assert_no_error (error);
g_assert_cmpstr (out, ==, "C=D\nE=F\n");
g_free (out);
g_object_unref (proc);
main (int argc, char **argv)
......@@ -1239,6 +1273,7 @@ main (int argc, char **argv)
g_test_add_func ("/gsubprocess/child-setup", test_child_setup);
g_test_add_func ("/gsubprocess/pass-fd", test_pass_fd);
g_test_add_func ("/gsubprocess/launcher-environment", test_launcher_environment);
return g_test_run ();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment