Skip to content

Conversation

@stevenh
Copy link
Owner

@stevenh stevenh commented Aug 26, 2025

Update modules to latest versions, addressing dependabot alerts.

Update tools and modules to latest versions, addressing dependabot
alerts.
Add go version and env debug for issue raising.
@stevenh stevenh force-pushed the chore/mod-update branch 2 times, most recently from 293ac91 to 8eceb77 Compare August 26, 2025 20:47
Add a standalone test for the os.ReadDir issue.
Update all module dependencies and go to the latest versions.
Update GitHub Actions workflows to use the latest versions of actions
to address issue with golang 1.24 compatibility.
@stevenh
Copy link
Owner Author

stevenh commented Oct 28, 2025

Waiting on a release with golang/go#75157 in it, to fix the tests.

Copy link

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few suggestions on how the test cases can be updated to not run into issue golang/go#75157. It should work without needing to skip those tests.

require.ErrorIs(t, err, syscall.ENOTDIR)
require.Equal(t, []fs.DirEntry{}, dirs)
var expectedDirs []fs.DirEntry
require.Equal(t, expectedDirs, dirs)
Copy link

@dmitshur dmitshur Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider this modified test case:

-require.Equal(t, []fs.DirEntry{}, dirs)
+require.Equal(t, 0, len(dirs))

It still checks that the number of directories returned is as expected, zero, but it's not sensitive to whether the slice happens to be empty and non-nil, or nil.

The documentation at https://pkg.go.dev/io/fs#ReadDirFS.ReadDir states only that ReadDir "returns a list of directory entries". The documentation doesn't specify that a slice is nil or non-nil.

Since you're implementing your own interface, you could choose to add logic to detect when the slice has 0 elements and consistently make it a nil slice, but I suspect that behavior isn't going to be helpful to most callers that would at most range over the slice, and ranging over a nil slice behaves no different than ranging over an empty slice. Also see the Go style suggestion at https://go.dev/s/style#declaring-empty-slices:

When designing interfaces, avoid making a distinction between a nil slice and a non-nil, zero-length slice

dirs, err := os.ReadDir(name)
require.ErrorIs(t, err, syscall.ENOTDIR)
var expectedDirs []fs.DirEntry
require.Equal(t, expectedDirs, dirs)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this test is probably added in the context of issue golang/go#75157. Also noting here that https://pkg.go.dev/os#ReadDir doesn't specify whether the returned slice is nil or not. Its documented behavior only promises that "If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error."

Switch to using require.Empty for slice checks to avoid failure due to
inconsistent behaviour of ReadDir between platforms
@stevenh stevenh merged commit 33eb3ae into main Nov 6, 2025
3 checks passed
@stevenh stevenh deleted the chore/mod-update branch November 6, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants