summaryrefslogtreecommitdiff
path: root/src/test/test-fs-util.c
diff options
context:
space:
mode:
authorMarc-Antoine Perennou <Marc-Antoine@Perennou.com>2016-09-10 09:38:04 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-10 08:38:04 +0100
commit4245eb507295522699215e35418c4c2716d6687c (patch)
tree94337c470ed5e6582fe81124daeb7eedbfc935b6 /src/test/test-fs-util.c
parent47af450af09c36c0af06aedcc551691a3cb4cd3c (diff)
test-fs-util: also empty TEMP and TMP env vars (#4121)
A follow-up for #3818 (992e8f2).
Diffstat (limited to 'src/test/test-fs-util.c')
-rw-r--r--src/test/test-fs-util.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 93eec3ef9c..b3c4a2a2eb 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -83,7 +83,7 @@ static void test_get_files_in_directory(void) {
}
static void test_var_tmp(void) {
- _cleanup_free_ char *tmpdir_backup = NULL;
+ _cleanup_free_ char *tmpdir_backup = NULL, *temp_backup = NULL, *tmp_backup = NULL;
const char *tmp_dir = NULL, *t;
t = getenv("TMPDIR");
@@ -92,7 +92,21 @@ static void test_var_tmp(void) {
assert_se(tmpdir_backup);
}
+ t = getenv("TEMP");
+ if (t) {
+ temp_backup = strdup(t);
+ assert_se(temp_backup);
+ }
+
+ t = getenv("TMP");
+ if (t) {
+ tmp_backup = strdup(t);
+ assert_se(tmp_backup);
+ }
+
assert(unsetenv("TMPDIR") >= 0);
+ assert(unsetenv("TEMP") >= 0);
+ assert(unsetenv("TMP") >= 0);
assert_se(var_tmp_dir(&tmp_dir) >= 0);
assert_se(streq(tmp_dir, "/var/tmp"));
@@ -113,6 +127,16 @@ static void test_var_tmp(void) {
assert_se(setenv("TMPDIR", tmpdir_backup, true) >= 0);
assert_se(streq(getenv("TMPDIR"), tmpdir_backup));
}
+
+ if (temp_backup) {
+ assert_se(setenv("TEMP", temp_backup, true) >= 0);
+ assert_se(streq(getenv("TEMP"), temp_backup));
+ }
+
+ if (tmp_backup) {
+ assert_se(setenv("TMP", tmp_backup, true) >= 0);
+ assert_se(streq(getenv("TMP"), tmp_backup));
+ }
}
int main(int argc, char *argv[]) {