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 tests for warnings when passing block to creation of new IO object #1087

Merged
merged 3 commits into from
Sep 30, 2023

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Sep 28, 2023

I think these were all IO subclasses, which means I probably missed half of them.
I used the syntax IO::open instead of IO.open in the descriptions of the tests, since that is what the warnings say.

@herwinw herwinw force-pushed the io_new_block_warning branch 2 times, most recently from 205beee to 7b9bb21 Compare September 29, 2023 05:23
@andrykonchin
Copy link
Member

Looks good.

It seems this case is missing also for TCPSocket and StringIO classes

@herwinw
Copy link
Member Author

herwinw commented Sep 29, 2023

https://github.com/ruby/spec/blob/master/library/stringio/new_spec.rb

StringIO already has this test (which I did not know until 10 seconds agon).

@herwinw herwinw force-pushed the io_new_block_warning branch from 7b9bb21 to ba2ad56 Compare September 29, 2023 16:38
@herwinw
Copy link
Member Author

herwinw commented Sep 29, 2023

Added TCPSocket (the specs for new are in initialize_spec, that's why I missed it at first glance). I updated the StringIO spec to match the style of the other ones, and added a raise in the block to verify that the block is not used.

@@ -2,5 +2,13 @@
require_relative 'shared/new'

describe "UNIXServer.new" do
it_behaves_like :unixserver_new, :new
platform_is_not :windows do
Copy link
Member

Choose a reason for hiding this comment

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

Could you move the platform_is_not outside? Because UNIXServer is not even defined on Windows (actually it is in some cases but we are ignoring that so far to keep things simple). Same below.

Copy link
Member Author

Choose a reason for hiding this comment

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

I extended this one a little bit to keep things consistent:

  • Replace platform_is_not :windows with with_feature :unix_socket, which looks a bit more generic. The current code had both in use. This could resolve the "in some cases on Windows", dependign on the implementation of with_feature.
  • Move these guards to the outer block in all spec files, and remove them from the shared files.

Copy link
Member

Choose a reason for hiding this comment

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

Great, that's even better, thank you!

Normalize to `with_feature :unix_socket`, which is more descriptive and
generic than checking for windows.
Normalize to `with_feature :unix_socket`, which is more descriptive and
generic than checking for windows.
Update the spec for StringIO.new to match the style of the other ones,
and include the check to see the block is not used.
@herwinw herwinw force-pushed the io_new_block_warning branch from ba2ad56 to 61167fd Compare September 30, 2023 13:05
@eregon eregon merged commit e7c3c53 into ruby:master Sep 30, 2023
10 checks passed
@herwinw herwinw deleted the io_new_block_warning branch September 30, 2023 15:32
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.

3 participants