From: Lennart Poettering Date: Fri, 11 Sep 2020 15:43:05 +0000 (+0200) Subject: test-fileio: test test strings with shell, too X-Git-Tag: v247-rc1~243^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df8b14b59119c61f660037710bbb3899db441ef7;p=thirdparty%2Fsystemd.git test-fileio: test test strings with shell, too --- diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 3e6413ec47e..9c0b3533c24 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -151,6 +151,18 @@ static void test_parse_env_file(void) { assert_se(r >= 0); } +static void test_one_shell_var(const char *file, const char *variable, const char *value) { + _cleanup_free_ char *cmd = NULL, *from_shell = NULL; + _cleanup_fclose_ FILE *f = NULL; + size_t sz; + + assert_se(cmd = strjoin(". ", file, " && /bin/echo -n \"$", variable, "\"")); + assert_se(f = popen(cmd, "re")); + assert_se(read_full_stream(f, &from_shell, &sz) >= 0); + assert_se(sz == strlen(value)); + assert_se(streq(from_shell, value)); +} + static void test_parse_multiline_env_file(void) { _cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-in-XXXXXX", @@ -176,6 +188,10 @@ static void test_parse_multiline_env_file(void) { assert_se(fflush_and_check(f) >= 0); fclose(f); + test_one_shell_var(t, "one", "BAR VAR\tGAR"); + test_one_shell_var(t, "two", "bar var\tgar"); + test_one_shell_var(t, "tri", "bar var \tgar "); + r = load_env_file(NULL, t, &a); assert_se(r >= 0);