Skip to content

Commit 9e4987f

Browse files
authored
Merge branch 'master' into mask_native_for_mri_stderr
2 parents 8a256b7 + c6e6679 commit 9e4987f

File tree

281 files changed

+3153
-1631
lines changed

Some content is hidden

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

281 files changed

+3153
-1631
lines changed

spec/mspec/tool/tag_from_output.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
NUMBER = /^\d+\)$/
2222
ERROR_OR_FAILED = / (ERROR|FAILED)$/
23-
SPEC_FILE = /^(\/.+_spec\.rb)\:\d+/
23+
SPEC_FILE = /^((?:\/|[CD]:\/).+_spec\.rb)\:\d+/
2424

2525
output.slice_before(NUMBER).select { |number, *rest|
2626
number =~ NUMBER and rest.any? { |line| line =~ ERROR_OR_FAILED }

spec/ruby/.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Style/Lambda:
197197
- 'language/lambda_spec.rb'
198198
- 'language/proc_spec.rb'
199199
- 'language/numbered_parameters_spec.rb'
200+
- 'language/it_parameter_spec.rb'
200201
- 'core/kernel/lambda_spec.rb'
201202

202203
Style/EmptyLambdaParameter:

spec/ruby/command_line/dash_0_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ruby_exe("puts $/, $-0", options: "-072").should == ":\n:\n"
66
end
77

8-
ruby_version_is "3.5" do
8+
ruby_version_is "4.0" do
99
it "sets $/ and $-0 as a frozen string" do
1010
ruby_exe("puts $/.frozen?, $-0.frozen?", options: "-072").should == "true\ntrue\n"
1111
end

spec/ruby/command_line/frozen_strings_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,28 @@
4242
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
4343
end
4444

45-
it "if file has no frozen_string_literal comment produce different mutable strings each time" do
46-
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
45+
context "if file has no frozen_string_literal comment" do
46+
it "produce different mutable strings each time" do
47+
ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
48+
end
49+
50+
guard -> { ruby_version_is "3.4" and !"test".frozen? } do
51+
it "complain about modification of produced mutable strings" do
52+
-> { eval(<<~RUBY) }.should complain(/warning: literal string will be frozen in the future \(run with --debug-frozen-string-literal for more information\)/)
53+
"test" << "!"
54+
RUBY
55+
end
56+
57+
it "does not complain about modification if Warning[:deprecated] is false" do
58+
deprecated = Warning[:deprecated]
59+
Warning[:deprecated] = false
60+
-> { eval(<<~RUBY) }.should_not complain
61+
"test" << "!"
62+
RUBY
63+
ensure
64+
Warning[:deprecated] = deprecated
65+
end
66+
end
4767
end
4868

4969
it "if file has frozen_string_literal:true comment produce same frozen strings each time" do

spec/ruby/core/array/pack/shared/basic.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@
3333
end
3434

3535
ruby_version_is ""..."3.3" do
36-
# https://bugs.ruby-lang.org/issues/19150
37-
# NOTE: it's just a plan of the Ruby core team
3836
it "warns that a directive is unknown" do
3937
# additional directive ('a') is required for the X directive
40-
-> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/)
41-
-> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/)
42-
-> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/)
38+
-> { [@obj, @obj].pack("a K" + pack_format) }.should complain(/unknown pack directive 'K' in 'a K#{pack_format}'/)
39+
-> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0' in 'a 0#{pack_format}'/)
40+
-> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':' in 'a :#{pack_format}'/)
4341
end
4442
end
4543

4644
ruby_version_is "3.3" do
47-
# https://bugs.ruby-lang.org/issues/19150
48-
# NOTE: Added this case just to not forget about the decision in the ticket
4945
it "raise ArgumentError when a directive is unknown" do
5046
# additional directive ('a') is required for the X directive
5147
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)

spec/ruby/core/builtin_constants/builtin_constants_spec.rb

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
end
4747
end
4848

49+
describe "RUBY_ENGINE_VERSION" do
50+
it "is a String" do
51+
RUBY_ENGINE_VERSION.should be_kind_of(String)
52+
end
53+
54+
it "is frozen" do
55+
RUBY_ENGINE_VERSION.should.frozen?
56+
end
57+
end
58+
4959
describe "RUBY_PLATFORM" do
5060
it "is a String" do
5161
RUBY_PLATFORM.should be_kind_of(String)
@@ -75,3 +85,67 @@
7585
RUBY_REVISION.should.frozen?
7686
end
7787
end
88+
89+
ruby_version_is "4.0" do
90+
context "The constant" do
91+
describe "Ruby" do
92+
it "is a Module" do
93+
Ruby.should.instance_of?(Module)
94+
end
95+
end
96+
97+
describe "Ruby::VERSION" do
98+
it "is equal to RUBY_VERSION" do
99+
Ruby::VERSION.should equal(RUBY_VERSION)
100+
end
101+
end
102+
103+
describe "RUBY::PATCHLEVEL" do
104+
it "is equal to RUBY_PATCHLEVEL" do
105+
Ruby::PATCHLEVEL.should equal(RUBY_PATCHLEVEL)
106+
end
107+
end
108+
109+
describe "Ruby::COPYRIGHT" do
110+
it "is equal to RUBY_COPYRIGHT" do
111+
Ruby::COPYRIGHT.should equal(RUBY_COPYRIGHT)
112+
end
113+
end
114+
115+
describe "Ruby::DESCRIPTION" do
116+
it "is equal to RUBY_DESCRIPTION" do
117+
Ruby::DESCRIPTION.should equal(RUBY_DESCRIPTION)
118+
end
119+
end
120+
121+
describe "Ruby::ENGINE" do
122+
it "is equal to RUBY_ENGINE" do
123+
Ruby::ENGINE.should equal(RUBY_ENGINE)
124+
end
125+
end
126+
127+
describe "Ruby::ENGINE_VERSION" do
128+
it "is equal to RUBY_ENGINE_VERSION" do
129+
Ruby::ENGINE_VERSION.should equal(RUBY_ENGINE_VERSION)
130+
end
131+
end
132+
133+
describe "Ruby::PLATFORM" do
134+
it "is equal to RUBY_PLATFORM" do
135+
Ruby::PLATFORM.should equal(RUBY_PLATFORM)
136+
end
137+
end
138+
139+
describe "Ruby::RELEASE_DATE" do
140+
it "is equal to RUBY_RELEASE_DATE" do
141+
Ruby::RELEASE_DATE.should equal(RUBY_RELEASE_DATE)
142+
end
143+
end
144+
145+
describe "Ruby::REVISION" do
146+
it "is equal to RUBY_REVISION" do
147+
Ruby::REVISION.should equal(RUBY_REVISION)
148+
end
149+
end
150+
end
151+
end

spec/ruby/core/comparable/clamp_spec.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@
4040
c.clamp(one, two).should equal(two)
4141
end
4242

43+
context 'max is nil' do
44+
it 'returns min if less than it' do
45+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
46+
c = ComparableSpecs::Weird.new(0)
47+
c.clamp(one, nil).should equal(one)
48+
end
49+
50+
it 'always returns self if greater than min' do
51+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
52+
c = ComparableSpecs::Weird.new(2)
53+
c.clamp(one, nil).should equal(c)
54+
end
55+
end
56+
57+
context 'min is nil' do
58+
it 'returns max if greater than it' do
59+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
60+
c = ComparableSpecs::Weird.new(2)
61+
c.clamp(nil, one).should equal(one)
62+
end
63+
64+
it 'always returns self if less than max' do
65+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
66+
c = ComparableSpecs::Weird.new(0)
67+
c.clamp(nil, one).should equal(c)
68+
end
69+
end
70+
71+
it 'always returns self when min is nil and max is nil' do
72+
c = ComparableSpecs::Weird.new(1)
73+
c.clamp(nil, nil).should equal(c)
74+
end
75+
4376
it 'returns self if within the given range parameters' do
4477
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
4578
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
@@ -76,6 +109,26 @@
76109
-> { c.clamp(one...two) }.should raise_error(ArgumentError)
77110
end
78111

112+
context 'with nil as the max argument' do
113+
it 'returns min argument if less than it' do
114+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
115+
zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
116+
c = ComparableSpecs::Weird.new(0)
117+
118+
c.clamp(one, nil).should equal(one)
119+
c.clamp(zero, nil).should equal(c)
120+
end
121+
122+
it 'always returns self if greater than min argument' do
123+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
124+
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
125+
c = ComparableSpecs::Weird.new(2)
126+
127+
c.clamp(one, nil).should equal(c)
128+
c.clamp(two, nil).should equal(c)
129+
end
130+
end
131+
79132
context 'with endless range' do
80133
it 'returns minimum value of the range parameters if less than it' do
81134
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
@@ -103,6 +156,24 @@
103156
end
104157
end
105158

159+
context 'with nil as the min argument' do
160+
it 'returns max argument if greater than it' do
161+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
162+
c = ComparableSpecs::Weird.new(2)
163+
164+
c.clamp(nil, one).should equal(one)
165+
end
166+
167+
it 'always returns self if less than max argument' do
168+
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
169+
zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
170+
c = ComparableSpecs::Weird.new(0)
171+
172+
c.clamp(nil, one).should equal(c)
173+
c.clamp(nil, zero).should equal(c)
174+
end
175+
end
176+
106177
context 'with beginless range' do
107178
it 'returns maximum value of the range parameters if greater than it' do
108179
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
@@ -128,6 +199,14 @@
128199
end
129200
end
130201

202+
context 'with nil as the min and the max argument' do
203+
it 'always returns self' do
204+
c = ComparableSpecs::Weird.new(1)
205+
206+
c.clamp(nil, nil).should equal(c)
207+
end
208+
end
209+
131210
context 'with beginless-and-endless range' do
132211
it 'always returns self' do
133212
c = ComparableSpecs::Weird.new(1)

spec/ruby/core/comparable/fixtures/classes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def initialize(value)
77
end
88

99
def <=>(other)
10+
return nil if other.nil?
1011
self.value <=> other.value
1112
end
1213
end

spec/ruby/core/data/fixtures/classes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ def initialize(*rest, **kw)
2424
ScratchPad.record [:initialize, rest, kw]
2525
end
2626
end
27+
28+
Area = Data.define(:width, :height, :area) do
29+
def initialize(width:, height:)
30+
super(width: width, height: height, area: width * height)
31+
end
32+
end
2733
end
2834
end

spec/ruby/core/data/initialize_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,15 @@ def initialize(*, **)
110110
DataSpecs::DataWithOverriddenInitialize[amount: 42, unit: "m"]
111111
ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
112112
end
113+
114+
# See https://github.com/ruby/psych/pull/765
115+
it "can be deserialized by calling Data.instance_method(:initialize)" do
116+
d1 = DataSpecs::Area.new(width: 2, height: 3)
117+
d1.area.should == 6
118+
119+
d2 = DataSpecs::Area.allocate
120+
Data.instance_method(:initialize).bind_call(d2, **d1.to_h)
121+
d2.should == d1
122+
end
113123
end
114124
end

0 commit comments

Comments
 (0)