diff --git a/glib/tests/utils.c b/glib/tests/utils.c index 3abef9312..e71d9a6ef 100644 --- a/glib/tests/utils.c +++ b/glib/tests/utils.c @@ -211,8 +211,27 @@ test_prgname_thread_safety (void) static void test_tmpdir (void) { + char **envp = NULL; + g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=627969"); - g_assert_cmpstr (g_get_tmp_dir (), !=, ""); + g_test_summary ("Test that g_get_tmp_dir() returns a correct default if TMPDIR is set to the empty string"); + + if (g_test_subprocess ()) + { + g_assert_cmpstr (g_get_tmp_dir (), !=, ""); + return; + } + + envp = g_get_environ (); + + envp = g_environ_setenv (g_steal_pointer (&envp), "TMPDIR", "", TRUE); + envp = g_environ_unsetenv (g_steal_pointer (&envp), "TMP"); + envp = g_environ_unsetenv (g_steal_pointer (&envp), "TEMP"); + + g_test_trap_subprocess_with_envp (NULL, (const gchar * const *) envp, + 0, G_TEST_SUBPROCESS_DEFAULT); + g_test_trap_assert_passed (); + g_strfreev (envp); } #if defined(__GNUC__) && (__GNUC__ >= 4) @@ -1309,11 +1328,6 @@ main (int argc, { argv0 = argv[0]; - /* for tmpdir test, need to do this early before g_get_any_init */ - g_setenv ("TMPDIR", "", TRUE); - g_unsetenv ("TMP"); - g_unsetenv ("TEMP"); - /* g_test_init() only calls g_set_prgname() if g_get_prgname() * returns %NULL, but g_get_prgname() on Windows never returns NULL. * So we need to do this by hand to make test_appname() work on