diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-08-10 17:03:12 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-08-11 09:16:05 +0200 |
commit | a14af47e64ca811c17470e021b22d05a16f4d46e (patch) | |
tree | 69a78adcddda2ce4495a1b0fea1a78ec99483ce2 /src/test/test-env-util.c | |
parent | 43cadb64d47ffc1d72571b2a2e494f383d8df83a (diff) | |
download | systemd-a14af47e64ca811c17470e021b22d05a16f4d46e.tar.gz |
basic/env-util: add a mode where we pull in the variable value from environment
Diffstat (limited to 'src/test/test-env-util.c')
-rw-r--r-- | src/test/test-env-util.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index 91c3c252de..c689d5590e 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -105,6 +105,7 @@ static void test_strv_env_replace_strdup(void) { assert_se(strv_env_replace_strdup(&a, "a=a") == 1); assert_se(strv_env_replace_strdup(&a, "b=b") == 1); assert_se(strv_env_replace_strdup(&a, "a=A") == 0); + assert_se(strv_env_replace_strdup(&a, "c") == -EINVAL); assert_se(strv_length(a) == 2); strv_sort(a); @@ -112,6 +113,27 @@ static void test_strv_env_replace_strdup(void) { assert_se(streq(a[1], "b=b")); } +static void test_strv_env_replace_strdup_passthrough(void) { + log_info("/* %s */", __func__); + + _cleanup_strv_free_ char **a = NULL; + + assert_se(putenv((char*) "a=a") == 0); + assert_se(putenv((char*) "b=") == 0); + assert_se(unsetenv("c") == 0); + + assert_se(strv_env_replace_strdup_passthrough(&a, "a") == 1); + assert_se(strv_env_replace_strdup_passthrough(&a, "b") == 1); + assert_se(strv_env_replace_strdup_passthrough(&a, "c") == 1); + assert_se(strv_env_replace_strdup_passthrough(&a, "a") == 0); + assert_se(strv_env_replace_strdup_passthrough(&a, "$a") == -EINVAL); + + assert_se(strv_length(a) == 3); + assert_se(streq(a[0], "a=a")); + assert_se(streq(a[1], "b=")); + assert_se(streq(a[2], "c=")); +} + static void test_strv_env_assign(void) { log_info("/* %s */", __func__); @@ -415,6 +437,7 @@ int main(int argc, char *argv[]) { test_strv_env_unset(); test_strv_env_merge(); test_strv_env_replace_strdup(); + test_strv_env_replace_strdup_passthrough(); test_strv_env_assign(); test_env_strv_get_n(); test_replace_env(false); |