Skip to content

Commit a9a7498

Browse files
committed
[libcxx] [test] Allow C:\System Volume Information to be missing
If running in a Windows Container, there is no such directory at all. If running from within bash on Windows Server, the directory seems to be fully accessible. (The mechanics of this isn't fully understood, and it doesn't seem to happen on desktop versions.) If the directory isn't available with the expected behaviour, mark those individual tests as unsupported. (The test as a whole is considered to pass, but the unsupported test is mentioned in a test summary printed on stdout.) Differential Revision: https://reviews.llvm.org/D98960
1 parent 4e83e59 commit a9a7498

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.cons/path.pass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
// UNSUPPORTED: c++03
1010

11-
// XFAIL: LIBCXX-WINDOWS-FIXME
12-
1311
// <filesystem>
1412

1513
// class directory_entry
@@ -155,7 +153,8 @@ TEST_CASE(path_ctor_cannot_resolve) {
155153
// reading directories; test using a special inaccessible directory
156154
// instead.
157155
const path dir = GetWindowsInaccessibleDir();
158-
TEST_REQUIRE(!dir.empty());
156+
if (dir.empty())
157+
TEST_UNSUPPORTED();
159158
const path file = dir / "file";
160159
{
161160
std::error_code ec = GetTestEC();

libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/ctor.pass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
// UNSUPPORTED: c++03
1010

11-
// XFAIL: LIBCXX-WINDOWS-FIXME
12-
1311
// <filesystem>
1412

1513
// class directory_iterator
@@ -94,7 +92,8 @@ TEST_CASE(access_denied_test_case)
9492
// reading directories; test using a special inaccessible directory
9593
// instead.
9694
const path testDir = GetWindowsInaccessibleDir();
97-
TEST_REQUIRE(!testDir.empty());
95+
if (testDir.empty())
96+
TEST_UNSUPPORTED();
9897
#else
9998
scoped_test_env env;
10099
path const testDir = env.make_env_path("dir1");

libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.members/ctor.pass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
// UNSUPPORTED: c++03
1010

11-
// XFAIL: LIBCXX-WINDOWS-FIXME
12-
1311
// <filesystem>
1412

1513
// class directory_iterator
@@ -95,7 +93,8 @@ TEST_CASE(access_denied_test_case)
9593
// reading directories; test using a special inaccessible directory
9694
// instead.
9795
const path testDir = GetWindowsInaccessibleDir();
98-
TEST_REQUIRE(!testDir.empty());
96+
if (testDir.empty())
97+
TEST_UNSUPPORTED();
9998
#else
10099
scoped_test_env env;
101100
path const testDir = env.make_env_path("dir1");

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
// UNSUPPORTED: c++03
1010

11-
// XFAIL: LIBCXX-WINDOWS-FIXME
12-
1311
// <filesystem>
1412

1513
// bool exists(file_status s) noexcept
@@ -91,7 +89,8 @@ TEST_CASE(test_exists_fails)
9189
// reading directories; test using a special inaccessible directory
9290
// instead.
9391
const path p = GetWindowsInaccessibleDir();
94-
TEST_REQUIRE(!p.empty());
92+
if (p.empty())
93+
TEST_UNSUPPORTED();
9594
#else
9695
scoped_test_env env;
9796
const path dir = env.create_dir("dir");

libcxx/test/support/filesystem_test_helper.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -678,22 +678,28 @@ inline fs::path GetWindowsInaccessibleDir() {
678678
const fs::path dir("C:\\System Volume Information");
679679
std::error_code ec;
680680
const fs::path root("C:\\");
681-
fs::directory_iterator it(root, ec);
682-
if (ec)
683-
return fs::path();
684-
const fs::directory_iterator endIt{};
685-
while (it != endIt) {
686-
const fs::directory_entry &ent = *it;
687-
if (ent == dir) {
688-
// Basic sanity checks on the directory_entry
689-
if (!ent.exists())
690-
return fs::path();
691-
if (!ent.is_directory())
692-
return fs::path();
693-
return ent;
681+
for (const auto &ent : fs::directory_iterator(root, ec)) {
682+
if (ent != dir)
683+
continue;
684+
// Basic sanity checks on the directory_entry
685+
if (!ent.exists() || !ent.is_directory()) {
686+
fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
687+
"but doesn't behave as expected, skipping tests "
688+
"regarding it\n", dir.string().c_str());
689+
return fs::path();
694690
}
695-
++it;
691+
// Check that it indeed is inaccessible as expected
692+
(void)fs::exists(ent, ec);
693+
if (!ec) {
694+
fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
695+
"but seems to be accessible, skipping tests "
696+
"regarding it\n", dir.string().c_str());
697+
return fs::path();
698+
}
699+
return ent;
696700
}
701+
fprintf(stderr, "No inaccessible directory \"%s\" found, skipping tests "
702+
"regarding it\n", dir.string().c_str());
697703
return fs::path();
698704
}
699705

0 commit comments

Comments
 (0)