diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-env-util.c | 31 | ||||
-rw-r--r-- | src/test/test-fileio.c | 14 |
2 files changed, 39 insertions, 6 deletions
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index f44cb3d57b..77a5219d82 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -142,7 +142,32 @@ static void test_env_strv_get_n(void) { getenv("PATH"))); } -static void test_replace_env_arg(void) { +static void test_replace_env(bool braceless) { + const char *env[] = { + "FOO=BAR BAR", + "BAR=waldo", + NULL + }; + _cleanup_free_ char *t = NULL, *s = NULL, *q = NULL, *r = NULL, *p = NULL; + unsigned flags = REPLACE_ENV_ALLOW_BRACELESS*braceless; + + t = replace_env("FOO=$FOO=${FOO}", (char**) env, flags); + assert_se(streq(t, braceless ? "FOO=BAR BAR=BAR BAR" : "FOO=$FOO=BAR BAR")); + + s = replace_env("BAR=$BAR=${BAR}", (char**) env, flags); + assert_se(streq(s, braceless ? "BAR=waldo=waldo" : "BAR=$BAR=waldo")); + + q = replace_env("BARBAR=$BARBAR=${BARBAR}", (char**) env, flags); + assert_se(streq(q, braceless ? "BARBAR==" : "BARBAR=$BARBAR=")); + + q = replace_env("BAR=$BAR$BAR${BAR}${BAR}", (char**) env, flags); + assert_se(streq(q, braceless ? "BAR=waldowaldowaldowaldo" : "BAR=$BAR$BARwaldowaldo")); + + p = replace_env("${BAR}$BAR$BAR", (char**) env, flags); + assert_se(streq(p, braceless ? "waldowaldowaldo" : "waldo$BAR$BAR")); +} + +static void test_replace_env_argv(void) { const char *env[] = { "FOO=BAR BAR", "BAR=waldo", @@ -256,7 +281,9 @@ int main(int argc, char *argv[]) { test_strv_env_set(); test_strv_env_merge(); test_env_strv_get_n(); - test_replace_env_arg(); + test_replace_env(false); + test_replace_env(true); + test_replace_env_argv(); test_env_clean(); test_env_name_is_valid(); test_env_value_is_valid(); diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 84f394a713..c204cbae22 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -226,7 +226,10 @@ static void test_merge_env_file(void) { "twelve=${one}2\n" "twentyone=2${one}\n" "one=2\n" - "twentytwo=2${one}\n", false); + "twentytwo=2${one}\n" + "xxx_minus_three=$xxx - 3\n" + "xxx=0x$one$one$one\n" + , false); assert(r >= 0); r = merge_env_file(&a, NULL, t); @@ -240,8 +243,9 @@ static void test_merge_env_file(void) { assert_se(streq(a[1], "twelve=12")); assert_se(streq(a[2], "twentyone=21")); assert_se(streq(a[3], "twentytwo=22")); - assert_se(a[4] == NULL); - + assert_se(streq(a[4], "xxx=0x222")); + assert_se(streq(a[5], "xxx_minus_three= - 3")); + assert_se(a[6] == NULL); r = merge_env_file(&a, NULL, t); assert_se(r >= 0); @@ -254,7 +258,9 @@ static void test_merge_env_file(void) { assert_se(streq(a[1], "twelve=12")); assert_se(streq(a[2], "twentyone=21")); assert_se(streq(a[3], "twentytwo=22")); - assert_se(a[4] == NULL); + assert_se(streq(a[4], "xxx=0x222")); + assert_se(streq(a[5], "xxx_minus_three=0x222 - 3")); + assert_se(a[6] == NULL); } static void test_executable_is_script(void) { |