-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libstd]: add Dir.Iterator tests #5755
Conversation
SourceHut config seems broken -- see #5756. |
#5653 is proving its worth with every PR. 🙂 Looks like this test is uncovering another bug. Windows is getting:
EDIT: Within the loop, the entry is correct, it's only after it's appended to entries that it becomes corrupted. Looks like the EDIT#2: Maybe not a bug, this is the doc comment for
EDIT#3: Alternate implementation that fixes the test on Windows: test "Dir.Iterator" {
var tmp_dir = tmpDir(.{ .iterate = true });
defer tmp_dir.cleanup();
// First, create a couple of entries to iterate over.
const file = try tmp_dir.dir.createFile("some_file", .{});
file.close();
try tmp_dir.dir.makeDir("some_dir");
var iter = tmp_dir.dir.iterate();
var len: usize = 0;
while (try iter.next()) |entry| {
switch (entry.kind) {
.File => testing.expectEqualSlices(u8, "some_file", entry.name),
.Directory => testing.expectEqualSlices(u8, "some_dir", entry.name),
else => unreachable,
}
len += 1;
}
testing.expect(len == 2); // note that the Iterator skips '.' and '..'
} EDIT#4: Also worth noting that the doc comment for |
Wow, thanks for the in-depth analysis @squeek502! I've actually had the same observations just didn't get a chance to write that up yet. Indeed, Now, this still doesn't change the fact we should be able to make the test pass without resorting to testing for equality within the
It's obviously not the case. Anyhow, I tried copying the bytes out manually yesterday, and I'd still get memory corruption somewhere for some reason. It was late though, so maybe I'll have better luck at some point later today. If anything comes back, I shall drop a line or two here. EDIT: OK, |
OK, 9b29218 should fix the memory corruption bug in the test. While we're here, do you think it would be useful to have EDIT: OK, I've now submitted an issue to track this proposal: #5768 |
This commit adds some `std.fs.Dir.Iterator` tests.
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
Unless anyone else has anything else to add, could we merge this into upstream? |
Might be worth addressing this in this PR. |
Good catch, thanks! Done in 417c928. |
This commit adds some
std.fs.Dir.Iterator
tests.Partially addresses #5653.