Skip to content
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

add spec for Dir.glob / Dir.[] result being sorted by default #861

Merged
merged 2 commits into from
Oct 8, 2021

Conversation

lxxxvi
Copy link
Contributor

@lxxxvi lxxxvi commented Oct 7, 2021

Hello 👋

From #823 :

Dir.glob and Dir.[] now sort the results by default, and
accept the sort: keyword option. [Feature #8709]

I am not sure if or how to add a spec for sorted: false. As far as I understand the result may or may not differ depending on OS. Is there a reliable/deterministic sorting logic behind sorted: false?

end

it "result is sorted by default" do
Dir.send(@method,'*').should == @sorted_files
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Dir.send(@method,'*').should == @sorted_files
Dir.send(@method, '*').should == @sorted_files

@@ -38,6 +38,32 @@
end
end

ruby_version_is "3.0" do
before :each do
@sorted_files = %w[
Copy link
Member

@eregon eregon Oct 7, 2021

Choose a reason for hiding this comment

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

It's better to just get the result and then result.should == results.sort.
That way we don't hardcode filenames here, could you do that?

@eregon
Copy link
Member

eregon commented Oct 7, 2021

We could add Dir.glob(..., sorted: false).sort.should == Dir.glob(...).sort, at least it makes sure the same files are returned.

It seems on Linux at least files aren't sorted, but they might luckily still be in sorted order so I don't think we can test that.

@lxxxvi lxxxvi force-pushed the dir-glob-sorts-result-by-default branch from d2c11ad to e28eb3d Compare October 8, 2021 07:03
@lxxxvi
Copy link
Contributor Author

lxxxvi commented Oct 8, 2021

@eregon Thank you for your feedback, I pushed the changes you suggested. 👍

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

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

Thank you!

@eregon eregon merged commit 72f2cf2 into ruby:master Oct 8, 2021
@lxxxvi lxxxvi deleted the dir-glob-sorts-result-by-default branch January 12, 2023 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants