Skip to content

Commit b3d4395

Browse files
committed
Add unittest
1 parent e55367f commit b3d4395

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

std/file.d

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5163,15 +5163,41 @@ auto dirEntries(bool useDIP1000 = dip1000Enabled)
51635163

51645164
// https://issues.dlang.org/show_bug.cgi?id=15146
51655165
dirEntries("", SpanMode.shallow).walkLength();
5166+
}
51665167

5167-
// https://github.com/dlang/phobos/issues/9584
5168-
string cwd = getcwd();
5169-
foreach (string entry; dirEntries(testdir, SpanMode.shallow))
5170-
{
5171-
if (entry.isDir)
5172-
chdir(entry);
5173-
}
5174-
chdir(cwd); // needed for the directories to be removed
5168+
// https://github.com/dlang/phobos/issues/9584
5169+
@safe unittest
5170+
{
5171+
import std.path : absolutePath, buildPath;
5172+
5173+
string root = deleteme();
5174+
mkdirRecurse(root);
5175+
scope (exit) rmdirRecurse(root);
5176+
5177+
mkdirRecurse(root.buildPath("1", "2"));
5178+
mkdirRecurse(root.buildPath("3", "4"));
5179+
mkdirRecurse(root.buildPath("3", "5", "6"));
5180+
5181+
const origWD = getcwd();
5182+
chdir(root);
5183+
scope(exit) chdir(origWD);
5184+
5185+
// When issue #9584 is triggered,
5186+
// one of the `isDir` calls fails with "No such file or directory".
5187+
foreach (string entry; ".".dirEntries(SpanMode.shallow))
5188+
{
5189+
if (entry.isDir)
5190+
{
5191+
foreach (string subentry; dirEntries(entry, SpanMode.shallow))
5192+
{
5193+
if (subentry.isDir)
5194+
{
5195+
chdir(absolutePath(subentry));
5196+
assert(absolutePath(subentry));
5197+
}
5198+
}
5199+
}
5200+
}
51755201
}
51765202

51775203
/// Ditto

0 commit comments

Comments
 (0)