Skip to content

Commit

Permalink
Update specs from Ruby 3.4 HEAD temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 31, 2024
1 parent 97e39d6 commit 62a2c85
Show file tree
Hide file tree
Showing 58 changed files with 674 additions and 292 deletions.
2 changes: 1 addition & 1 deletion spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ end
platform_is_not :linux, :darwin do # Not Linux and not Darwin
end

platform_is wordsize: 64 do
platform_is pointer_size: 64 do
# 64-bit platform
end

Expand Down
1 change: 0 additions & 1 deletion spec/ruby/command_line/fixtures/debug_info.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
a = 'string'
b = a
c = b
Expand Down
13 changes: 11 additions & 2 deletions spec/ruby/command_line/frozen_strings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,18 @@

describe "The --debug flag produces" do
it "debugging info on attempted frozen string modification" do
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1")
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--enable-frozen-string-literal --debug', args: "2>&1")
error_str.should include("can't modify frozen String")
error_str.should include("created at")
error_str.should include("command_line/fixtures/debug_info.rb:2")
error_str.should include("command_line/fixtures/debug_info.rb:1")
end

guard -> { ruby_version_is "3.4" and !"test".frozen? } do
it "debugging info on mutating chilled string" do
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '-w --debug', args: "2>&1")
error_str.should include("literal string will be frozen in the future")
error_str.should include("the string was created here")
error_str.should include("command_line/fixtures/debug_info.rb:1")
end
end
end
48 changes: 48 additions & 0 deletions spec/ruby/core/array/fetch_values_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "Array#fetch_values" do
before :each do
@array = [:a, :b, :c]
end

ruby_version_is "3.4" do
describe "with matched indexes" do
it "returns the values for indexes" do
@array.fetch_values(0).should == [:a]
@array.fetch_values(0, 2).should == [:a, :c]
end

it "returns the values for indexes ordered in the order of the requested indexes" do
@array.fetch_values(2, 0).should == [:c, :a]
end
end

describe "with unmatched indexes" do
it "raises a index error if no block is provided" do
-> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError)
end

it "returns the default value from block" do
@array.fetch_values(44) { |index| "`#{index}' is not found" }.should == ["`44' is not found"]
@array.fetch_values(0, 44) { |index| "`#{index}' is not found" }.should == [:a, "`44' is not found"]
end
end

describe "without keys" do
it "returns an empty Array" do
@array.fetch_values.should == []
end
end

it "tries to convert the passed argument to an Integer using #to_int" do
obj = mock('to_int')
obj.should_receive(:to_int).and_return(2)
@array.fetch_values(obj).should == [:c]
end

it "raises a TypeError when the passed argument can't be coerced to Integer" do
-> { [].fetch_values("cat") }.should raise_error(TypeError)
end
end
end
16 changes: 8 additions & 8 deletions spec/ruby/core/array/pack/l_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
it_behaves_like :array_pack_32bit_be, 'L>'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'L<_'
it_behaves_like :array_pack_32bit_le, 'L_<'
Expand All @@ -51,7 +51,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'L<_'
it_behaves_like :array_pack_64bit_le, 'L_<'
Expand Down Expand Up @@ -83,7 +83,7 @@
it_behaves_like :array_pack_32bit_be, 'l>'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'l<_'
it_behaves_like :array_pack_32bit_le, 'l_<'
Expand All @@ -105,7 +105,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'l<_'
it_behaves_like :array_pack_64bit_le, 'l_<'
Expand Down Expand Up @@ -137,7 +137,7 @@
it_behaves_like :array_pack_32bit_le, 'l'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'L_'
end
Expand All @@ -155,7 +155,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'L_'
end
Expand Down Expand Up @@ -183,7 +183,7 @@
it_behaves_like :array_pack_32bit_be, 'l'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'L_'
end
Expand All @@ -201,7 +201,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'L_'
end
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/array/pack/shared/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78"
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
it "encodes the least significant 32 bits of a number that is greater than 32 bits" do
[ [[0xff_7865_4321], "\x21\x43\x65\x78"],
[[-0xff_7865_4321], "\xdf\xbc\x9a\x87"]
Expand All @@ -299,7 +299,7 @@
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21"
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
it "encodes the least significant 32 bits of a number that is greater than 32 bits" do
[ [[0xff_7865_4321], "\x78\x65\x43\x21"],
[[-0xff_7865_4321], "\x87\x9a\xbc\xdf"]
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/file/shared/update_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
end

platform_is :linux do
platform_is wordsize: 64 do
platform_is pointer_size: 64 do
it "allows Time instances in the far future to set mtime and atime (but some filesystems limit it up to 2446-05-10 or 2038-01-19 or 2486-07-02)" do
# https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Timestamps
# "Therefore, timestamps should not overflow until May 2446."
Expand Down
20 changes: 19 additions & 1 deletion spec/ruby/core/hash/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
-> { Hash.new(nil) { 0 } }.should raise_error(ArgumentError)
end

ruby_version_is "3.3" do
ruby_version_is "3.3"..."3.4" do
it "emits a deprecation warning if keyword arguments are passed" do
-> { Hash.new(unknown: true) }.should complain(
Regexp.new(Regexp.escape("Calling Hash.new with keyword arguments is deprecated and will be removed in Ruby 3.4; use Hash.new({ key: value }) instead"))
Expand All @@ -46,4 +46,22 @@
Hash.new({ unknown: true }).default.should == { unknown: true }
end
end

ruby_version_is "3.4" do
it "accepts a capacity: argument" do
Hash.new(5, capacity: 42).default.should == 5
Hash.new(capacity: 42).default.should == nil
(Hash.new(capacity: 42) { 1 }).default_proc.should_not == nil
end

it "ignores negative capacity" do
-> { Hash.new(capacity: -42) }.should_not raise_error
end

it "raises an error if unknown keyword arguments are passed" do
-> { Hash.new(unknown: true) }.should raise_error(ArgumentError)
-> { Hash.new(1, unknown: true) }.should raise_error(ArgumentError)
-> { Hash.new(unknown: true) { 0 } }.should raise_error(ArgumentError)
end
end
end
46 changes: 22 additions & 24 deletions spec/ruby/core/hash/shared/to_s.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,49 @@
describe :hash_to_s, shared: true do
it "returns a string representation with same order as each()" do
h = { a: [1, 2], b: -2, d: -6, nil => nil }

pairs = []
h.each do |key, value|
pairs << key.inspect + '=>' + value.inspect
end

str = '{' + pairs.join(', ') + '}'
h.send(@method).should == str
expected = ruby_version_is("3.4") ? "{a: [1, 2], b: -2, d: -6, nil => nil}" : "{:a=>[1, 2], :b=>-2, :d=>-6, nil=>nil}"
h.send(@method).should == expected
end

it "calls #inspect on keys and values" do
key = mock('key')
val = mock('val')
key.should_receive(:inspect).and_return('key')
val.should_receive(:inspect).and_return('val')

{ key => val }.send(@method).should == '{key=>val}'
expected = ruby_version_is("3.4") ? "{key => val}" : "{key=>val}"
{ key => val }.send(@method).should == expected
end

it "does not call #to_s on a String returned from #inspect" do
str = +"abc"
str.should_not_receive(:to_s)

{ a: str }.send(@method).should == '{:a=>"abc"}'
expected = ruby_version_is("3.4") ? '{a: "abc"}' : '{:a=>"abc"}'
{ a: str }.send(@method).should == expected
end

it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
obj = mock("Hash#inspect/to_s calls #to_s")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_return("abc")

{ a: obj }.send(@method).should == "{:a=>abc}"
expected = ruby_version_is("3.4") ? "{a: abc}" : "{:a=>abc}"
{ a: obj }.send(@method).should == expected
end

it "does not call #to_str on the object returned from #inspect when it is not a String" do
obj = mock("Hash#inspect/to_s does not call #to_str")
obj.should_receive(:inspect).and_return(obj)
obj.should_not_receive(:to_str)

{ a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
expected_pattern = ruby_version_is("3.4") ? /^\{a: #<MockObject:0x[0-9a-f]+>\}$/ : /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
{ a: obj }.send(@method).should =~ expected_pattern
end

it "does not call #to_str on the object returned from #to_s when it is not a String" do
obj = mock("Hash#inspect/to_s does not call #to_str on #to_s result")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_return(obj)
obj.should_not_receive(:to_str)

{ a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
expected_pattern = ruby_version_is("3.4") ? /^\{a: #<MockObject:0x[0-9a-f]+>\}$/ : /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
{ a: obj }.send(@method).should =~ expected_pattern
end

it "does not swallow exceptions raised by #to_s" do
Expand All @@ -66,24 +60,28 @@
it "handles hashes with recursive values" do
x = {}
x[0] = x
x.send(@method).should == '{0=>{...}}'
expected = ruby_version_is("3.4") ? '{0 => {...}}' : '{0=>{...}}'
x.send(@method).should == expected

x = {}
y = {}
x[0] = y
y[1] = x
x.send(@method).should == "{0=>{1=>{...}}}"
y.send(@method).should == "{1=>{0=>{...}}}"
expected_x = ruby_version_is("3.4") ? '{0 => {1 => {...}}}' : '{0=>{1=>{...}}}'
expected_y = ruby_version_is("3.4") ? '{1 => {0 => {...}}}' : '{1=>{0=>{...}}}'
x.send(@method).should == expected_x
y.send(@method).should == expected_y
end

it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))

{a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}'
expected = ruby_version_is("3.4") ? '{a: "utf_16be \u3042"}' : '{:a=>"utf_16be \u3042"}'
{a: utf_16be}.send(@method).should == expected
end

it "works for keys and values whose #inspect return a frozen String" do
{ true => false }.to_s.should == "{true=>false}"
expected = ruby_version_is("3.4") ? "{true => false}" : "{true=>false}"
{ true => false }.to_s.should == expected
end
end
6 changes: 2 additions & 4 deletions spec/ruby/core/integer/round_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
(-25 * 10**70).round(-71).should eql(-30 * 10**70)
end

platform_is_not wordsize: 32 do
it "raises a RangeError when passed a big negative value" do
-> { 42.round(fixnum_min) }.should raise_error(RangeError)
end
it "raises a RangeError when passed a big negative value" do
-> { 42.round(min_long - 1) }.should raise_error(RangeError)
end

it "raises a RangeError when passed Float::INFINITY" do
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/core/integer/size_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require_relative '../../spec_helper'

describe "Integer#size" do
platform_is wordsize: 32 do
platform_is c_long_size: 32 do
it "returns the number of bytes in the machine representation of self" do
-1.size.should == 4
0.size.should == 4
4091.size.should == 4
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
it "returns the number of bytes in the machine representation of self" do
-1.size.should == 8
0.size.should == 8
Expand Down
5 changes: 0 additions & 5 deletions spec/ruby/core/kernel/block_given_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
it "returns true if and only if a block is supplied" do
@object.accept_block {}.should == true
@object.accept_block_as_argument {}.should == true
@object.accept_block_inside_block {}.should == true
@object.accept_block_as_argument_inside_block {}.should == true

@object.accept_block.should == false
@object.accept_block_as_argument.should == false
@object.accept_block_inside_block.should == false
@object.accept_block_as_argument_inside_block.should == false
end

# Clarify: Based on http://www.ruby-forum.com/topic/137822 it appears
# that Matz wanted this to be true in 1.9.
it "returns false when a method defined by define_method is called with a block" do
@object.defined_block {}.should == false
@object.defined_block_inside_block {}.should == false
end
end

Expand Down
Loading

0 comments on commit 62a2c85

Please sign in to comment.