Skip to content

Commit ad29b9e

Browse files
committed
[GR-14806] Update ruby/spec
PullRequest: truffleruby/4504
2 parents 2a415cf + 30d2b3c commit ad29b9e

File tree

241 files changed

+2939
-3245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+2939
-3245
lines changed

ci.jsonnet

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,8 @@ local part_definitions = {
312312
"CHECK_LEAKS": "true",
313313
"RUBY_SPEC_TEST_ZLIB_CRC_TABLE": "false", # CRuby was built on OL6 and is used on OL7
314314
},
315-
run+: jt(["-u", "ruby", "mspec", "spec/ruby"]) +
316-
jt(["-u", "/cm/shared/apps-ol7/ruby/3.1.2/bin/ruby", "mspec", "spec/ruby"]) +
317-
jt(["-u", "/cm/shared/apps/ruby/3.0.2/bin/ruby", "mspec", "spec/ruby"]),
315+
run+: jt(["-u", "ruby", "mspec", "spec/ruby"]) + # 3.2.2
316+
jt(["-u", "/cm/shared/apps-ol7/ruby/3.1.2/bin/ruby", "mspec", "spec/ruby"]),
318317
},
319318

320319
test_fast: {

spec/mspec/tool/remove_old_guards.rb

100644100755
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
#!/usr/bin/env ruby
2+
13
# Removes old version guards in ruby/spec.
24
# Run it from the ruby/spec repository root.
35
# The argument is the new minimum supported version.
6+
#
7+
# cd spec
8+
# ../mspec/tool/remove_old_guards.rb <ruby-version>
9+
#
10+
# where <ruby-version> is a version guard with which should be removed
11+
#
12+
# Example:
13+
# tool/remove_old_guards.rb 3.1
14+
#
15+
# As a result guards like
16+
# ruby_version_is "3.1" do
17+
# # ...
18+
# end
19+
#
20+
# will be removed.
421

522
def dedent(line)
623
if line.start_with?(" ")
@@ -105,6 +122,8 @@ def search(regexp)
105122
end
106123
end
107124

125+
abort "usage: #{$0} <ruby-version>" if ARGV.empty?
126+
108127
version = Regexp.escape(ARGV.fetch(0))
109128
version += "(?:\\.0)?" if version.count(".") < 2
110129
remove_guards(/ruby_version_is (["'])#{version}\1 do/, true)

spec/ruby/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ ruby/spec is known to be tested in these implementations for every commit:
3030
* [Opal](https://github.com/opal/opal/tree/master/spec)
3131
* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
3232

33-
ruby/spec describes the behavior of Ruby 3.0 and more recent Ruby versions.
34-
More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.0.x, 3.1.x, 3.2.x, etc), and those are tested in CI.
33+
ruby/spec describes the behavior of Ruby 3.1 and more recent Ruby versions.
34+
More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.1.x, 3.2.x, etc), and those are tested in CI.
3535

3636
### Synchronization with Ruby Implementations
3737

@@ -62,6 +62,7 @@ For older specs try these commits:
6262
* Ruby 2.5.9 - [Suite](https://github.com/ruby/spec/commit/c503335d3d9f6ec6ef24de60a0716c34af69b64f) using [MSpec](https://github.com/ruby/mspec/commit/0091e8a62e954717cd54641f935eaf1403692041)
6363
* Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661)
6464
* Ruby 2.7.8 - [Suite](https://github.com/ruby/spec/commit/93787e6035c925b593a9c0c6fb0e7e07a6f1df1f) using [MSpec](https://github.com/ruby/mspec/commit/1d8cf64722d8a7529f7cd205be5f16a89b7a67fd)
65+
* Ruby 3.0.7 - [Suite](https://github.com/ruby/spec/commit/affef93d9940f615e4836f64b011da211f570913) using [MSpec](https://github.com/ruby/mspec/commit/0aabb3e548eb5ea6cad0125f8f46cee34542b6b7)
6566

6667
### Running the specs
6768

spec/ruby/command_line/dash_upper_u_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
describe "ruby -U" do
44
it "sets Encoding.default_internal to UTF-8" do
5-
ruby_exe('print Encoding.default_internal.name',
6-
options: '-U').should == 'UTF-8'
5+
ruby_exe('print Encoding.default_internal.name',
6+
options: '-U').should == 'UTF-8'
77
end
88

99
it "sets Encoding.default_internal to UTF-8 when RUBYOPT is empty or only spaces" do
@@ -14,25 +14,25 @@
1414
end
1515

1616
it "does nothing different if specified multiple times" do
17-
ruby_exe('print Encoding.default_internal.name',
18-
options: '-U -U').should == 'UTF-8'
17+
ruby_exe('print Encoding.default_internal.name',
18+
options: '-U -U').should == 'UTF-8'
1919
end
2020

2121
it "is overruled by Encoding.default_internal=" do
22-
ruby_exe('Encoding.default_internal="ascii"; print Encoding.default_internal.name',
23-
options: '-U').should == 'US-ASCII'
22+
ruby_exe('Encoding.default_internal="ascii"; print Encoding.default_internal.name',
23+
options: '-U').should == 'US-ASCII'
2424
end
2525

2626
it "does not affect the default external encoding" do
27-
ruby_exe('Encoding.default_external="ascii"; print Encoding.default_external.name',
28-
options: '-U').should == 'US-ASCII'
27+
ruby_exe('Encoding.default_external="ascii"; print Encoding.default_external.name',
28+
options: '-U').should == 'US-ASCII'
2929
end
3030

3131
it "does not affect the source encoding" do
32-
ruby_exe("print __ENCODING__.name",
33-
options: '-U -KE').should == 'EUC-JP'
34-
ruby_exe("print __ENCODING__.name",
35-
options: '-KE -U').should == 'EUC-JP'
32+
ruby_exe("print __ENCODING__.name",
33+
options: '-U -KE').should == 'EUC-JP'
34+
ruby_exe("print __ENCODING__.name",
35+
options: '-KE -U').should == 'EUC-JP'
3636
end
3737

3838
# I assume IO redirection will break on Windows...

spec/ruby/core/array/drop_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
end
88

99
it "raises an ArgumentError if the number of elements specified is negative" do
10-
-> { [1, 2].drop(-3) }.should raise_error(ArgumentError)
10+
-> { [1, 2].drop(-3) }.should raise_error(ArgumentError)
1111
end
1212

1313
it "returns an empty Array if all elements are dropped" do

spec/ruby/core/array/fetch_values_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
it "returns the values for indexes" do
1212
@array.fetch_values(0).should == [:a]
1313
@array.fetch_values(0, 2).should == [:a, :c]
14+
@array.fetch_values(-1).should == [:c]
1415
end
1516

1617
it "returns the values for indexes ordered in the order of the requested indexes" do

spec/ruby/core/array/intersect_spec.rb

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,63 @@
22
require_relative 'fixtures/classes'
33

44
describe 'Array#intersect?' do
5-
ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198
6-
describe 'when at least one element in two Arrays is the same' do
7-
it 'returns true' do
8-
[1, 2].intersect?([2, 3, 4]).should == true
9-
[2, 3, 4].intersect?([1, 2]).should == true
10-
end
5+
describe 'when at least one element in two Arrays is the same' do
6+
it 'returns true' do
7+
[1, 2].intersect?([2, 3, 4]).should == true
8+
[2, 3, 4].intersect?([1, 2]).should == true
119
end
10+
end
1211

13-
describe 'when there are no elements in common between two Arrays' do
14-
it 'returns false' do
15-
[0, 1, 2].intersect?([3, 4]).should == false
16-
[3, 4].intersect?([0, 1, 2]).should == false
17-
[3, 4].intersect?([]).should == false
18-
[].intersect?([0, 1, 2]).should == false
19-
end
12+
describe 'when there are no elements in common between two Arrays' do
13+
it 'returns false' do
14+
[0, 1, 2].intersect?([3, 4]).should == false
15+
[3, 4].intersect?([0, 1, 2]).should == false
16+
[3, 4].intersect?([]).should == false
17+
[].intersect?([0, 1, 2]).should == false
2018
end
19+
end
2120

22-
it "tries to convert the passed argument to an Array using #to_ary" do
23-
obj = mock('[1,2,3]')
24-
obj.should_receive(:to_ary).and_return([1, 2, 3])
21+
it "tries to convert the passed argument to an Array using #to_ary" do
22+
obj = mock('[1,2,3]')
23+
obj.should_receive(:to_ary).and_return([1, 2, 3])
2524

26-
[1, 2].intersect?(obj).should == true
27-
end
25+
[1, 2].intersect?(obj).should == true
26+
end
2827

29-
it "determines equivalence between elements in the sense of eql?" do
30-
obj1 = mock('1')
31-
obj2 = mock('2')
32-
obj1.stub!(:hash).and_return(0)
33-
obj2.stub!(:hash).and_return(0)
34-
obj1.stub!(:eql?).and_return(true)
35-
obj2.stub!(:eql?).and_return(true)
28+
it "determines equivalence between elements in the sense of eql?" do
29+
obj1 = mock('1')
30+
obj2 = mock('2')
31+
obj1.stub!(:hash).and_return(0)
32+
obj2.stub!(:hash).and_return(0)
33+
obj1.stub!(:eql?).and_return(true)
34+
obj2.stub!(:eql?).and_return(true)
3635

37-
[obj1].intersect?([obj2]).should == true
36+
[obj1].intersect?([obj2]).should == true
3837

39-
obj1 = mock('3')
40-
obj2 = mock('4')
41-
obj1.stub!(:hash).and_return(0)
42-
obj2.stub!(:hash).and_return(0)
43-
obj1.stub!(:eql?).and_return(false)
44-
obj2.stub!(:eql?).and_return(false)
38+
obj1 = mock('3')
39+
obj2 = mock('4')
40+
obj1.stub!(:hash).and_return(0)
41+
obj2.stub!(:hash).and_return(0)
42+
obj1.stub!(:eql?).and_return(false)
43+
obj2.stub!(:eql?).and_return(false)
4544

46-
[obj1].intersect?([obj2]).should == false
47-
end
45+
[obj1].intersect?([obj2]).should == false
46+
end
4847

49-
it "does not call to_ary on array subclasses" do
50-
[5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true
51-
end
48+
it "does not call to_ary on array subclasses" do
49+
[5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true
50+
end
5251

53-
it "properly handles an identical item even when its #eql? isn't reflexive" do
54-
x = mock('x')
55-
x.stub!(:hash).and_return(42)
56-
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
52+
it "properly handles an identical item even when its #eql? isn't reflexive" do
53+
x = mock('x')
54+
x.stub!(:hash).and_return(42)
55+
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
5756

58-
[x].intersect?([x]).should == true
59-
end
57+
[x].intersect?([x]).should == true
58+
end
6059

61-
it "has semantic of !(a & b).empty?" do
62-
[].intersect?([]).should == false
63-
[nil].intersect?([nil]).should == true
64-
end
60+
it "has semantic of !(a & b).empty?" do
61+
[].intersect?([]).should == false
62+
[nil].intersect?([nil]).should == true
6563
end
6664
end

spec/ruby/core/array/sample_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@
114114

115115
-> { [1, 2].sample(random: random) }.should raise_error(RangeError)
116116
end
117+
118+
it "raises a RangeError if the value is greater than the Array size" do
119+
random = mock("array_sample_random")
120+
random.should_receive(:rand).and_return(3)
121+
122+
-> { [1, 2].sample(random: random) }.should raise_error(RangeError)
123+
end
117124
end
118125
end
119126

spec/ruby/core/array/shuffle_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,18 @@
6969
-> { [1, 2].shuffle(random: random) }.should raise_error(RangeError)
7070
end
7171

72-
it "raises a RangeError if the value is equal to one" do
72+
it "raises a RangeError if the value is equal to the Array size" do
7373
value = mock("array_shuffle_random_value")
74-
value.should_receive(:to_int).at_least(1).times.and_return(1)
74+
value.should_receive(:to_int).at_least(1).times.and_return(2)
75+
random = mock("array_shuffle_random")
76+
random.should_receive(:rand).at_least(1).times.and_return(value)
77+
78+
-> { [1, 2].shuffle(random: random) }.should raise_error(RangeError)
79+
end
80+
81+
it "raises a RangeError if the value is greater than the Array size" do
82+
value = mock("array_shuffle_random_value")
83+
value.should_receive(:to_int).at_least(1).times.and_return(3)
7584
random = mock("array_shuffle_random")
7685
random.should_receive(:rand).at_least(1).times.and_return(value)
7786

spec/ruby/core/basicobject/instance_eval_spec.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,11 @@ class B; end
141141
caller.get_constant_with_string(receiver).should == :singleton_class
142142
end
143143

144-
ruby_version_is ""..."3.1" do
145-
it "looks in the caller scope next" do
146-
receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new
147-
caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new
144+
it "looks in the receiver class next" do
145+
receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new
146+
caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new
148147

149-
caller.get_constant_with_string(receiver).should == :Caller
150-
end
151-
end
152-
153-
ruby_version_is "3.1" do
154-
it "looks in the receiver class next" do
155-
receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new
156-
caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new
157-
158-
caller.get_constant_with_string(receiver).should == :Receiver
159-
end
148+
caller.get_constant_with_string(receiver).should == :Receiver
160149
end
161150

162151
it "looks in the caller class next" do

spec/ruby/core/basicobject/singleton_method_added_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def self.foo
9696
end
9797
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for/)
9898
end
99+
ensure
100+
BasicObjectSpecs.send(:remove_const, :NoSingletonMethodAdded)
99101
end
100102

101103
it "raises NoMethodError for a singleton instance" do

spec/ruby/core/class/dup_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def self.message
5959
it "stores the new name if assigned to a constant" do
6060
CoreClassSpecs::RecordCopy = CoreClassSpecs::Record.dup
6161
CoreClassSpecs::RecordCopy.name.should == "CoreClassSpecs::RecordCopy"
62+
ensure
63+
CoreClassSpecs.send(:remove_const, :RecordCopy)
6264
end
6365

6466
it "raises TypeError if called on BasicObject" do
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module CoreClassSpecs
2+
module Callbacks
3+
class Base
4+
def self.inherited(subclass)
5+
subclass.const_set(:INHERITED_NAME, subclass.name)
6+
ORDER << [
7+
:inherited,
8+
subclass,
9+
eval("defined?(#{subclass.name})"),
10+
Object.const_source_location(subclass.name) ? :location : :unknown_location,
11+
]
12+
super
13+
end
14+
end
15+
16+
ORDER = []
17+
18+
def self.const_added(const_name)
19+
ORDER << [
20+
:const_added,
21+
const_name,
22+
eval("defined?(#{const_name})"),
23+
const_source_location(const_name) ? :location : :unknown_location,
24+
]
25+
super
26+
end
27+
28+
class Child < Base
29+
end
30+
end
31+
end

spec/ruby/core/class/inherited_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/classes'
3+
require_relative 'fixtures/callback_order'
34

45
describe "Class.inherited" do
56

@@ -98,4 +99,16 @@ class << top; protected :inherited; end
9899
-> { Class.new(top) }.should_not raise_error
99100
end
100101

102+
it "is invoked after the class is named when using class definition syntax" do
103+
CoreClassSpecs::Callbacks::Child::INHERITED_NAME.should == "CoreClassSpecs::Callbacks::Child"
104+
end
105+
106+
ruby_version_is "3.5" do # https://bugs.ruby-lang.org/issues/21143
107+
it "is invoked before `const_added`" do
108+
CoreClassSpecs::Callbacks::ORDER.should == [
109+
[:inherited, CoreClassSpecs::Callbacks::Child, "constant", :location],
110+
[:const_added, :Child, "constant", :location],
111+
]
112+
end
113+
end
101114
end

spec/ruby/core/class/new_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def message2; "hello"; end
8383
a = Class.new
8484
MyClass::NestedClass = a
8585
MyClass::NestedClass.name.should == "MyClass::NestedClass"
86+
ensure
87+
Object.send(:remove_const, :MyClass)
8688
end
8789

8890
it "sets the new class' superclass to the given class" do

0 commit comments

Comments
 (0)