Skip to content

Commit 4150571

Browse files
committed
Add unittest
1 parent e55367f commit 4150571

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

std/file.d

+34-8
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; entry.dirEntries(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)