summaryrefslogtreecommitdiffstats
path: root/src/test/test-env-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-21 05:21:26 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-21 05:35:19 +0100
commitf50ce8fc4b2619d73b3118ea202b112035e713c1 (patch)
treeb0cc0776992be61c847d3494da8f02472cb9bf43 /src/test/test-env-util.c
parentbasic: support default and alternate values for env expansion (diff)
downloadsystemd-f50ce8fc4b2619d73b3118ea202b112035e713c1.tar.xz
systemd-f50ce8fc4b2619d73b3118ea202b112035e713c1.zip
test-env-util: add more tests for "extended syntax"
This is only the tip of the iceberg. It would be great to test all kinds of nesting, handling of invalid syntax, etc., but I'm leaving that for later.
Diffstat (limited to '')
-rw-r--r--src/test/test-env-util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c
index dfcd9cb724..4f44cf8711 100644
--- a/src/test/test-env-util.c
+++ b/src/test/test-env-util.c
@@ -167,6 +167,34 @@ static void test_replace_env(bool braceless) {
assert_se(streq(p, braceless ? "waldowaldowaldo" : "waldo$BAR$BAR"));
}
+static void test_replace_env2(bool extended) {
+ const char *env[] = {
+ "FOO=foo",
+ "BAR=bar",
+ NULL
+ };
+ _cleanup_free_ char *t = NULL, *s = NULL, *q = NULL, *r = NULL, *p = NULL, *x = NULL;
+ unsigned flags = REPLACE_ENV_ALLOW_EXTENDED*extended;
+
+ t = replace_env("FOO=${FOO:-${BAR}}", (char**) env, flags);
+ assert_se(streq(t, extended ? "FOO=foo" : "FOO=${FOO:-bar}"));
+
+ s = replace_env("BAR=${XXX:-${BAR}}", (char**) env, flags);
+ assert_se(streq(s, extended ? "BAR=bar" : "BAR=${XXX:-bar}"));
+
+ q = replace_env("XXX=${XXX:+${BAR}}", (char**) env, flags);
+ assert_se(streq(q, extended ? "XXX=" : "XXX=${XXX:+bar}"));
+
+ r = replace_env("FOO=${FOO:+${BAR}}", (char**) env, flags);
+ assert_se(streq(r, extended ? "FOO=bar" : "FOO=${FOO:+bar}"));
+
+ p = replace_env("FOO=${FOO:-${BAR}post}", (char**) env, flags);
+ assert_se(streq(p, extended ? "FOO=foo" : "FOO=${FOO:-barpost}"));
+
+ x = replace_env("XXX=${XXX:+${BAR}post}", (char**) env, flags);
+ assert_se(streq(x, extended ? "XXX=" : "XXX=${XXX:+barpost}"));
+}
+
static void test_replace_env_argv(void) {
const char *env[] = {
"FOO=BAR BAR",
@@ -295,6 +323,8 @@ int main(int argc, char *argv[]) {
test_env_strv_get_n();
test_replace_env(false);
test_replace_env(true);
+ test_replace_env2(false);
+ test_replace_env2(true);
test_replace_env_argv();
test_env_clean();
test_env_name_is_valid();