Skip to content
Snippets Groups Projects
Commit 9d86e38c authored by Simon McVittie's avatar Simon McVittie
Browse files

env-overlay test: Exercise environment variables with strange names


These are not syntactically valid shell variables, but they can still
exist in the environment.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent c8da7fc5
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,10 @@ setup (Fixture *f,
_srt_env_overlay_set (f->container_env, "STEAM_RUNTIME", NULL);
_srt_env_overlay_inherit (f->container_env, "LD_PRELOAD");
_srt_env_overlay_inherit (f->container_env, "FLATPAK_ID");
/* These are not syntactically valid shell variables, but they're allowed
* as environment variables */
_srt_env_overlay_set (f->container_env, "2weird", "starts with digit");
_srt_env_overlay_set (f->container_env, " ", "space");
}
static void
......@@ -62,12 +66,33 @@ teardown (Fixture *f,
g_clear_pointer (&f->container_env, _srt_env_overlay_unref);
}
static void
dump_envp (const char * const *envp)
{
gsize i;
g_test_message ("Environment:");
if (envp == NULL || envp[0] == NULL)
{
g_test_message ("\t(empty)");
return;
}
for (i = 0; envp[i] != NULL; i++)
g_test_message ("\t%s", envp[i]);
g_test_message ("\t.");
}
static void
test_apply (Fixture *f,
gconstpointer context)
{
static const char * const expected[] =
{
" =space", /* replaced */
"2weird=starts with digit", /* replaced */
"FLATPAK_ID=com.valvesoftware.Steam", /* inherited */
"G_MESSAGES_DEBUG=all", /* replaced */
"LD_AUDIT=audit2.so", /* replaced */
......@@ -81,6 +106,7 @@ test_apply (Fixture *f,
envp = g_strdupv ((gchar **) initial_envp);
envp = _srt_env_overlay_apply (f->container_env, envp);
qsort (envp, g_strv_length (envp), sizeof (char *), _srt_indirect_strcmp0);
dump_envp (_srt_const_strv (envp));
g_assert_cmpstrv (envp, (gchar **) expected);
}
......@@ -109,6 +135,8 @@ test_to_env0 (Fixture *f,
{
static const char * const expected[] =
{
" =space",
"2weird=starts with digit",
"G_MESSAGES_DEBUG=all",
"LD_AUDIT=audit2.so",
NULL
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment