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

Extend specs of IO#pwrite #1093

Merged
merged 2 commits into from
Oct 28, 2023
Merged

Extend specs of IO#pwrite #1093

merged 2 commits into from
Oct 28, 2023

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Oct 14, 2023

No description provided.

core/io/pwrite_spec.rb Outdated Show resolved Hide resolved
core/io/pwrite_spec.rb Outdated Show resolved Hide resolved
-> {
@file.pwrite(BasicObject.new, 0)
}.should raise_error(NoMethodError, /undefined method `to_s'/)
end
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: there is another case that makes sense to cover.

When #to_s returns non-String value - then it's ignored and object is still converted to String with rb_any_to_s CRuby function:

VALUE
rb_any_to_s(VALUE obj)
{
    VALUE str;
    VALUE cname = rb_class_name(CLASS_OF(obj));

    str = rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)obj);

    return str;
}

that prints object in the following way:

"#<Object:0x0000000106095428>"

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'm not sure if this is something we need to test here, if we add it here it should also be added to IO#print, IO#write, IO#syswrite and all other IO methods I'm forgetting. But this code is unrelated to IO, so I guess this should be tested in object/to_s_spec.rb or something else that's more generic.

@andrykonchin andrykonchin merged commit fb68990 into ruby:master Oct 28, 2023
10 checks passed
@andrykonchin
Copy link
Member

Thank you!

@herwinw herwinw deleted the io_pwrite branch October 28, 2023 16:36
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