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

Upstream specs #1240

Merged
merged 36 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9a8009f
Quarantine failing new specs that require investigation
andrykonchin Jan 7, 2025
f196750
Reapply "Suppress WIN32OLE deprecation warnings for the time being"
nobu Dec 19, 2024
5a90de7
Skip examples related with OpenStruct in ruby/spec
hsbt Jan 8, 2025
25162ad
[Feature #6012] Extend `source_location` for end position and columns
nobu Jan 9, 2025
8324eab
Restructured irb related example at spec/ruby
hsbt Jan 23, 2025
ad4f652
Prefer `uname -n` over `hostname`. (#12647)
ioquatix Jan 28, 2025
681b728
Add fallback for `hostname` if `uname` isn't available. (#12655)
ioquatix Jan 28, 2025
656a319
bin_path_spec.rb relied to available Ruby environment with after `mak…
hsbt Jan 30, 2025
04e354e
Handle environment where GEM_HOME is not available
hsbt Jan 30, 2025
0d88403
Add rb_data_define() C function
andrykonchin Dec 26, 2024
7041294
Refactor rb_io_open_descriptor()
andrykonchin Jan 10, 2025
8d4c32d
Add Range#overlap?
andrykonchin Jan 13, 2025
b10aaf1
Add missing specs for NoMethodError#message
andrykonchin Dec 18, 2024
deae4e6
Fix NoMethodError#message when receiver is an instance of an anonymou…
andrykonchin Dec 18, 2024
ba7f17c
Always use Module#name for non-anonymous module to create NoMethodErr…
andrykonchin Jan 15, 2025
eb95409
Refactor Truffle::ExceptionOperations.receiver_string and removed out…
andrykonchin Jan 15, 2025
1cffa0d
Socket `#recv*` methods return `nil` instead of an empty String on cl…
andrykonchin Dec 25, 2024
c8c3fd4
Fix Marshal.dump when a Float value is dumped repeatedly
andrykonchin Dec 17, 2024
1158caf
Dump Range instance variables in proper order
andrykonchin Dec 17, 2024
91a8e2c
Add specs for Marshal.dump and objects table
andrykonchin Dec 18, 2024
31c5d66
Add specs for Regexp used in REXML that was affected by ReDoS vulnera…
andrykonchin Jan 15, 2025
3f92a62
Fix Proc#clone and call #initialize_clone instead of #initialize_copy
andrykonchin Jan 16, 2025
2c1323c
Refactor specs for Dir.for_fd and use a mock instead of Object.new
andrykonchin Jan 16, 2025
981da7b
Refactor specs for Dir#chdir
andrykonchin Jan 16, 2025
a37d52d
Fix a spec for Dir#chdir that checks a case when an original director…
andrykonchin Jan 16, 2025
9e1b2a2
Fix validation of seconds in utc offset in String format
andrykonchin Nov 8, 2024
c61df54
Use ruby_version_is instead of ruby_bug for a spec for String#% that …
andrykonchin Nov 8, 2024
0851dbd
Fix Integer#/ with bignum argument
andrykonchin Jan 14, 2025
b4f1a91
Add Module#set_temporary_name method
andrykonchin Jan 16, 2025
3270443
Add more Module#set_temporary_name specs and fix edge case
eregon Jan 17, 2025
03ffa51
Add missing Ruby version guards for rb_data_define()'s specs
andrykonchin Jan 30, 2025
fbbb7d0
Quarantine some new specs for Socket#recvfrom_nonblock()
andrykonchin Jan 30, 2025
d4fccb6
Fix Rubocop's warnings
andrykonchin Jan 30, 2025
0ba6deb
Revert "Reapply "Suppress WIN32OLE deprecation warnings for the time …
andrykonchin Jan 30, 2025
ccc72c7
Skip some new specs for reading from a closed socket on Windows
andrykonchin Jan 30, 2025
cbbb3c8
Skip a new spec for Dir#chdir on Windows when original directory is r…
andrykonchin Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/binding/fixtures/irb.rb

This file was deleted.

47 changes: 24 additions & 23 deletions core/dir/chdir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def to_str; DirSpecs.mock_dir; end
end

it "raises an Errno::ENOENT if the original directory no longer exists" do
dir1 = tmp('/testdir1')
dir2 = tmp('/testdir2')
File.should_not.exist?(dir1)
File.should_not.exist?(dir2)
dir1 = tmp('testdir1')
dir2 = tmp('testdir2')
Dir.should_not.exist?(dir1)
Dir.should_not.exist?(dir2)
Dir.mkdir dir1
Dir.mkdir dir2
begin
Expand All @@ -108,8 +108,8 @@ def to_str; DirSpecs.mock_dir; end
end
}.should raise_error(Errno::ENOENT)
ensure
Dir.unlink dir1 if File.exist?(dir1)
Dir.unlink dir2 if File.exist?(dir2)
Dir.unlink dir1 if Dir.exist?(dir1)
Dir.unlink dir2 if Dir.exist?(dir2)
end
end

Expand Down Expand Up @@ -177,28 +177,29 @@ def to_str; DirSpecs.mock_dir; end
dir.close
end

it "raises an Errno::ENOENT if the original directory no longer exists" do
dir_name1 = tmp('/testdir1')
dir_name2 = tmp('/testdir2')
File.should_not.exist?(dir_name1)
File.should_not.exist?(dir_name2)
Dir.mkdir dir_name1
Dir.mkdir dir_name2
platform_is_not :windows do
it "does not raise an Errno::ENOENT if the original directory no longer exists" do
dir_name1 = tmp('testdir1')
dir_name2 = tmp('testdir2')
Dir.should_not.exist?(dir_name1)
Dir.should_not.exist?(dir_name2)
Dir.mkdir dir_name1
Dir.mkdir dir_name2

dir1 = Dir.new(dir_name1)
dir2 = Dir.new(dir_name2)

begin
-> {
dir1.chdir do
Dir.chdir(dir_name2) { Dir.unlink dir_name1 }
begin
Dir.chdir(dir_name1) do
dir2.chdir { Dir.unlink dir_name1 }
end
}.should raise_error(Errno::ENOENT)
Dir.pwd.should == @original
ensure
Dir.unlink dir_name1 if Dir.exist?(dir_name1)
Dir.unlink dir_name2 if Dir.exist?(dir_name2)
end
ensure
Dir.unlink dir_name1 if File.exist?(dir_name1)
Dir.unlink dir_name2 if File.exist?(dir_name2)
dir2.close
end
ensure
dir1.close
end

it "always returns to the original directory when given a block" do
Expand Down
6 changes: 4 additions & 2 deletions core/dir/for_fd_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'

quarantine! do # leads to "Errno::EBADF: Bad file descriptor - closedir" in DirSpecs.delete_mock_dirs
ruby_version_is '3.3' do
guard -> { Dir.respond_to? :for_fd } do
describe "Dir.for_fd" do
Expand Down Expand Up @@ -42,8 +43,8 @@

it "calls #to_int to convert a value to an Integer" do
dir = Dir.new(DirSpecs.mock_dir)
obj = Object.new
obj.singleton_class.define_method(:to_int) { dir.fileno }
obj = mock("fd")
obj.should_receive(:to_int).and_return(dir.fileno)

dir_new = Dir.for_fd(obj)
dir_new.fileno.should == dir.fileno
Expand Down Expand Up @@ -75,3 +76,4 @@
end
end
end
end
3 changes: 3 additions & 0 deletions core/exception/fixtures/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class NoMethodErrorD; end

class InstanceException < Exception
end

class AClass; end
module AModule; end
end

class NameErrorSpecs
Expand Down
204 changes: 165 additions & 39 deletions core/exception/no_method_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
end

ruby_version_is ""..."3.3" do
it "calls receiver.inspect only when calling Exception#message" do
it "calls #inspect when calling Exception#message" do
ScratchPad.record []
test_class = Class.new do
def inspect
Expand All @@ -76,19 +76,163 @@ def inspect
end
end
instance = test_class.new

begin
instance.bar
rescue Exception => e
e.name.should == :bar
ScratchPad.recorded.should == []
e.message.should =~ /undefined method.+\bbar\b/
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']bar' for <inspect>:#<Class:0x\h+>$/
ScratchPad.recorded.should == [:inspect_called]
end
end

it "fallbacks to a simpler representation of the receiver when receiver.inspect raises an exception" do
test_class = Class.new do
def inspect
raise NoMethodErrorSpecs::InstanceException
end
end
instance = test_class.new

begin
instance.bar
rescue NoMethodError => error
message = error.message
message.should =~ /undefined method.+\bbar\b/
message.should include test_class.inspect
end
end

it "uses #name to display the receiver if it is a class" do
klass = Class.new { def self.name; "MyClass"; end }

begin
klass.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for MyClass:Class$/
end
end

it "uses #name to display the receiver if it is a module" do
mod = Module.new { def self.name; "MyModule"; end }

begin
mod.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for MyModule:Module$/
end
end
end

ruby_version_is "3.3" do
it "does not call receiver.inspect even when calling Exception#message" do
it "uses a literal name when receiver is nil" do
begin
nil.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for nil\Z/
end
end

it "uses a literal name when receiver is true" do
begin
true.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for true\Z/
end
end

it "uses a literal name when receiver is false" do
begin
false.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for false\Z/
end
end

it "uses #name when receiver is a class" do
klass = Class.new { def self.name; "MyClass"; end }

begin
klass.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for class MyClass\Z/
end
end

it "uses class' string representation when receiver is an anonymous class" do
klass = Class.new

begin
klass.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for class #<Class:0x\h+>\Z/
end
end

it "uses class' string representation when receiver is a singleton class" do
obj = Object.new
singleton_class = obj.singleton_class

begin
singleton_class.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for class #<Class:#<Object:0x\h+>>\Z/
end
end

it "uses #name when receiver is a module" do
mod = Module.new { def self.name; "MyModule"; end }

begin
mod.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for module MyModule\Z/
end
end

it "uses module's string representation when receiver is an anonymous module" do
m = Module.new

begin
m.foo
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for module #<Module:0x\h+>\Z/
end
end

it "uses class #name when receiver is an ordinary object" do
klass = Class.new { def self.name; "MyClass"; end }
instance = klass.new

begin
instance.bar
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']bar' for an instance of MyClass\Z/
end
end

it "uses class string representation when receiver is an instance of anonymous class" do
klass = Class.new
instance = klass.new

begin
instance.bar
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']bar' for an instance of #<Class:0x\h+>\Z/
end
end

it "uses class name when receiver has a singleton class" do
instance = NoMethodErrorSpecs::NoMethodErrorA.new
def instance.foo; end

begin
instance.bar
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']bar' for #<NoMethodErrorSpecs::NoMethodErrorA:0x\h+>\Z/
end
end

it "does not call #inspect when calling Exception#message" do
ScratchPad.record []
test_class = Class.new do
def inspect
Expand All @@ -97,47 +241,29 @@ def inspect
end
end
instance = test_class.new

begin
instance.bar
rescue Exception => e
e.name.should == :bar
ScratchPad.recorded.should == []
e.message.should =~ /undefined method.+\bbar\b/
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']bar' for an instance of #<Class:0x\h+>\Z/
ScratchPad.recorded.should == []
end
end
end

it "fallbacks to a simpler representation of the receiver when receiver.inspect raises an exception" do
test_class = Class.new do
def inspect
raise NoMethodErrorSpecs::InstanceException
end
end
instance = test_class.new
begin
instance.bar
rescue Exception => e
e.name.should == :bar
message = e.message
message.should =~ /undefined method.+\bbar\b/
message.should include test_class.inspect
end
end
it "does not truncate long class names" do
class_name = 'ExceptionSpecs::A' + 'a'*100

it "uses #name to display the receiver if it is a class or a module" do
klass = Class.new { def self.name; "MyClass"; end }
begin
klass.foo
rescue NoMethodError => error
error.message.lines.first.chomp.should =~ /^undefined method [`']foo' for /
end
begin
eval <<~RUBY
class #{class_name}
end

mod = Module.new { def self.name; "MyModule"; end }
begin
mod.foo
rescue NoMethodError => error
error.message.lines.first.chomp.should =~ /^undefined method [`']foo' for /
obj = #{class_name}.new
obj.foo
RUBY
rescue NoMethodError => error
error.message.should =~ /\Aundefined method [`']foo' for an instance of #{class_name}\Z/
end
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions core/integer/divide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

it "supports dividing negative numbers" do
(-1 / 10).should == -1
(-1 / 10**10).should == -1
(-1 / 10**20).should == -1
end

it "preservers sign correctly" do
(4 / 3).should == 1
(4 / -3).should == -2
(-4 / 3).should == -2
(-4 / -3).should == 1
(0 / -3).should == 0
(0 / 3).should == 0
end

it "returns result the same class as the argument" do
Expand Down Expand Up @@ -58,6 +69,15 @@
((10**50) / -(10**40 + 1)).should == -10000000000
end

it "preservers sign correctly" do
(4 / bignum_value).should == 0
(4 / -bignum_value).should == -1
(-4 / bignum_value).should == -1
(-4 / -bignum_value).should == 0
(0 / bignum_value).should == 0
(0 / -bignum_value).should == 0
end

it "returns self divided by Float" do
not_supported_on :opal do
(bignum_value(88) / 4294967295.0).should be_close(4294967297.0, TOLERANCE)
Expand Down
Loading