Skip to content

Commit c9fc1a9

Browse files
committed
[libcxx] [test] Explicitly check that some env vars are ignored in the temp_dir_path test
This was suggested in the review of D98139. Differential Revision: https://reviews.llvm.org/D98696
1 parent d09adfd commit c9fc1a9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.temp_dir_path/temp_directory_path.pass.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ TEST_CASE(basic_tests)
6464
{"TMP", env.create_dir("dir2")},
6565
{"TEMP", env.create_dir("dir3")},
6666
{"TEMPDIR", env.create_dir("dir4")}
67+
#endif
68+
};
69+
TestCase ignored_cases[] = {
70+
#ifdef _WIN32
71+
{"TMPDIR", env.create_dir("dir5")},
72+
{"TEMPDIR", env.create_dir("dir6")},
73+
#else
74+
{"USERPROFILE", env.create_dir("dir5")},
6775
#endif
6876
};
6977
for (auto& TC : cases) {
@@ -114,6 +122,7 @@ TEST_CASE(basic_tests)
114122
UnsetEnv(TC.name);
115123
}
116124
// No env variables are defined
125+
path fallback;
117126
{
118127
std::error_code ec = GetTestEC();
119128
path ret = temp_directory_path(ec);
@@ -123,6 +132,20 @@ TEST_CASE(basic_tests)
123132
TEST_CHECK(ret == "/tmp");
124133
#endif
125134
TEST_CHECK(is_directory(ret));
135+
fallback = ret;
136+
}
137+
for (auto& TC : ignored_cases) {
138+
// Check that certain variables are ignored
139+
PutEnv(TC.name, TC.p);
140+
std::error_code ec = GetTestEC();
141+
path ret = temp_directory_path(ec);
142+
TEST_CHECK(!ec);
143+
144+
// Check that we return the same as above when no vars were defined.
145+
TEST_CHECK(ret == fallback);
146+
147+
// Finally erase this env variable
148+
UnsetEnv(TC.name);
126149
}
127150
}
128151

0 commit comments

Comments
 (0)