Repository navigation
Add specs for Ruby 4.0 features and changes - #1401
SergiuLupaiescu wants to merge 8 commits into
Conversation
…Error backtrace in Ruby 4.0
…uler CRuby treats a truthy return value from Fiber::Scheduler#io_close as 'the scheduler already closed the file descriptor' and does not close it. The test scheduler returned the events Array, so descriptors were never closed and the CHECK_LEAKS check failed on CI.
| it "returns false for the \"it\" parameter" do | ||
| eval("proc { it; binding.local_variable_defined?(:it) }").call(1).should == false | ||
| end | ||
| end |
There was a problem hiding this comment.
Similar specs were added in language/numbered_parameters_spec.rb (see truffleruby/truffleruby#4313). I'd say it's OK to have them duplicated.
| it "returns a String representation in the #<Set: {...}> format" do | ||
| Set[1, 2, 3].inspect.should == "#<Set: {1, 2, 3}>" | ||
| end | ||
| end |
There was a problem hiding this comment.
The specs for #inspect were moved to specs for #to_s in 3e241de (#inspect is just an alias) and the exact format is tested indirectly.
| out.should.include?("add(1)") | ||
| out.should.include?("def add(x, y)") | ||
| end | ||
| end |
There was a problem hiding this comment.
This seems to be error_highlight gem functionality, so it would be better to test it in a dedicated directory under library/ (e.g., library/error_highlight/).
| e.backtrace_locations.first.label.should == "ExceptionSpecs::Arity#bar" | ||
| } | ||
| end | ||
| end |
There was a problem hiding this comment.
It seems the original description is a bit incorrect:
A backtrace for ArgumentError of "wrong number of arguments" now
include the receiver's class or module name (e.g., in Foo#bar
instead of in bar). [[Bug #21698](https://bugs.ruby-lang.org/issues/21698)]
Actually what was discussed in the #21698 issue is a message of ArgumentError exception, not a backtrace.
The change in Ruby 4.0 in a message is from
`add': wrong number of arguments (given 1, expected 2) (ArgumentError)
to
'FooBar#add': wrong number of arguments (given 0, expected 2) (ArgumentError)
So a case in message_spec.rb or a dedicated file core/exception/argument_error_spec.rb can be added instead.
JFYI A module/class name was added in a backtrace in Ruby 3.4 and is tested in core/thread/backtrace/location/label_spec.rb
| describe "Fiber::Scheduler hooks" do | ||
| ruby_version_is "4.0" do | ||
| describe "#fiber_interrupt" do | ||
| it "is called with the blocked fiber and an IOError when its IO is closed by another fiber" do |
There was a problem hiding this comment.
There are already some specs for Fiber hooks and they are grouped around blocking operations (like IO reading and writing). A couple of examples - eecf44f, 0da5077. It makes sense to follow this approach.
The Fiber::Scheduler class is public so if you want to cover its methods with specs in isolation - it's convenient to have a separate directory for a class and test each its method in a dedicated file.
|
|
||
| static VALUE thread_spec_rb_thread_call_with_gvl_from_without_gvl(VALUE self) { | ||
| return (VALUE)rb_thread_call_without_gvl(without_gvl_calling_with_gvl_func, NULL, RUBY_UBF_IO, NULL); | ||
| } |
There was a problem hiding this comment.
Not sure if it's a proper way to test rb_thread_call_with_gvl in cases with and without GVL being held:
- I suppose that by default GVL is already held for a user provided code (so nothing special should be done for "rb_thread_call_with_gvl")
- and GVL should be released explicitly (e.g. with
gvl_release) and then acquired back for "rb_thread_call_with_gvl_from_without_gvl"
| return Qnil; | ||
| } | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Does it mean that the spec will actually test rb_thread_fd_close only on GCC? In this case I wouldn't bother with adding such tests at all. Testing deprecations usually has very little value.
|
Sorry for such delay of the review. |
Part of #1351
ruby_version_is "4.0"guards.Covers:
&&,||,and,or)Binding#local_variable*:local_variablesno longer includes them, andlocal_variable_get,local_variable_setandlocal_variable_defined?reject them. This is marked done in Write specs for new Ruby 4.0 features and changes #1351 but had no spec.Set#inspect, Pathname as a core class, CGI reduced tocgi/escape, ErrorHighlight caller/callee snippets forArgumentError, and the "wrong number of arguments" backtrace label.Fiber::Schedulerhooks:fiber_interrupt,yield,io_closeandio_write.rb_thread_call_with_gvl(with and without the GVL) andrb_thread_fd_close(deprecated no-op).