diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-09-11 17:43:05 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-20 12:11:10 +0200 |
commit | 585352ec8acac3d2e91b41ee2963c9d0d89fab37 (patch) | |
tree | eab68f8958d8aa20370914a5f84dbba03435d859 | |
parent | c9d593803402ac0aac1250e97c9aed94d78d32a5 (diff) | |
download | systemd-585352ec8acac3d2e91b41ee2963c9d0d89fab37.tar.gz |
test-fileio: test test strings with shell, too
(cherry picked from commit df8b14b59119c61f660037710bbb3899db441ef7)
(cherry picked from commit e2c0023dd2c18500ffa9a07522b9a860f358311f)
-rw-r--r-- | src/test/test-fileio.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 22238945bb..b342623134 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -149,6 +149,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", @@ -174,6 +186,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); |