Skip to content

Commit 7314b67

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/3414
2 parents dde1b60 + 32cda91 commit 7314b67

File tree

18 files changed

+230
-86
lines changed

18 files changed

+230
-86
lines changed

spec/mspec/lib/mspec/runner/shared.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
require 'mspec/runner/mspec'
22

33
def it_behaves_like(desc, meth, obj = nil)
4-
send :before, :all do
4+
before :all do
55
@method = meth
66
@object = obj
77
end
8+
after :all do
9+
@method = nil
10+
@object = nil
11+
end
812

9-
send :it_should_behave_like, desc.to_s
13+
it_should_behave_like desc.to_s
1014
end

spec/mspec/spec/helpers/ruby_exe_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class RubyExeSpecs
147147
@script = RubyExeSpecs.new
148148
allow(@script).to receive(:`).and_return('OUTPUT')
149149

150-
status_successful = double(Process::Status, exitstatus: 0)
150+
status_successful = double(Process::Status, exited?: true, exitstatus: 0)
151151
allow(Process).to receive(:last_status).and_return(status_successful)
152152
end
153153

@@ -176,24 +176,24 @@ class RubyExeSpecs
176176
code = "code"
177177
options = {}
178178

179-
status_failed = double(Process::Status, exitstatus: 4)
179+
status_failed = double(Process::Status, exited?: true, exitstatus: 4)
180180
allow(Process).to receive(:last_status).and_return(status_failed)
181181

182182
expect {
183183
@script.ruby_exe(code, options)
184184
}.to raise_error(%r{Expected exit status is 0 but actual is 4 for command ruby_exe\(.+\)})
185185
end
186186

187-
it "shows in the exception message if exitstatus is nil (e.g., signal)" do
187+
it "shows in the exception message if a signal killed the process" do
188188
code = "code"
189189
options = {}
190190

191-
status_failed = double(Process::Status, exitstatus: nil)
191+
status_failed = double(Process::Status, exited?: false, signaled?: true, termsig: Signal.list.fetch('TERM'))
192192
allow(Process).to receive(:last_status).and_return(status_failed)
193193

194194
expect {
195195
@script.ruby_exe(code, options)
196-
}.to raise_error(%r{Expected exit status is 0 but actual is nil for command ruby_exe\(.+\)})
196+
}.to raise_error(%r{Expected exit status is 0 but actual is :SIGTERM for command ruby_exe\(.+\)})
197197
end
198198

199199
describe "with :dir option" do
@@ -236,7 +236,7 @@ class RubyExeSpecs
236236

237237
describe "with :exit_status option" do
238238
before do
239-
status_failed = double(Process::Status, exitstatus: 4)
239+
status_failed = double(Process::Status, exited?: true, exitstatus: 4)
240240
allow(Process).to receive(:last_status).and_return(status_failed)
241241
end
242242

spec/ruby/.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Lint/DuplicateElsifCondition:
9999
Lint/OutOfRangeRegexpRef:
100100
Enabled: false
101101

102+
Lint/InheritException:
103+
Enabled: false
104+
102105
Lint/ElseLayout:
103106
Exclude:
104107
- 'language/if_spec.rb'

spec/ruby/.rubocop_todo.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ Lint/IneffectiveAccessModifier:
5050
- 'core/module/fixtures/classes.rb'
5151
- 'language/fixtures/private.rb'
5252

53-
# Offense count: 6
54-
# Cop supports --auto-correct.
55-
# Configuration parameters: EnforcedStyle.
56-
# SupportedStyles: runtime_error, standard_error
57-
Lint/InheritException:
58-
Exclude:
59-
- 'core/enumerator/lazy/fixtures/classes.rb'
60-
- 'core/exception/fixtures/common.rb'
61-
- 'core/module/fixtures/autoload_ex1.rb'
62-
- 'shared/kernel/raise.rb'
63-
6453
# Offense count: 72
6554
# Cop supports --auto-correct.
6655
Lint/LiteralInInterpolation:

spec/ruby/core/env/shared/update.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
ENV["bar"].should == "1"
1616
end
1717

18+
ruby_version_is "3.2" do
19+
it "adds the multiple parameter hashes to ENV, returning ENV" do
20+
ENV.send(@method, {"foo" => "0", "bar" => "1"}, {"baz" => "2"}).should equal(ENV)
21+
ENV["foo"].should == "0"
22+
ENV["bar"].should == "1"
23+
ENV["baz"].should == "2"
24+
end
25+
end
26+
1827
it "returns ENV when no block given" do
1928
ENV.send(@method, {"foo" => "0", "bar" => "1"}).should equal(ENV)
2029
end

spec/ruby/core/float/round_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
-4.809999999999999.round(5, half: :even).should eql(-4.81)
137137
end
138138

139-
ruby_bug "", ""..."3.2" do
139+
ruby_bug "", ""..."3.3" do
140140
# These numbers are neighbouring floating point numbers round a
141141
# precise value. They test that the rounding modes work correctly
142142
# round that value and precision is not lost which might cause

spec/ruby/core/io/shared/readlines.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
(result ? result : ScratchPad.recorded).should == IOSpecs.lines
8080
end
8181

82-
ruby_bug "#18767", ""..."3.2" do
82+
ruby_bug "#18767", ""..."3.3" do
8383
describe "when passed limit" do
8484
it "raises ArgumentError when passed 0 as a limit" do
8585
-> { IO.send(@method, @name, 0, &@object) }.should raise_error(ArgumentError)
@@ -256,4 +256,4 @@
256256
end
257257
end
258258
end
259-
end
259+
end

spec/ruby/core/math/ldexp_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
it "accepts any second argument that can be coerced with Integer()" do
4646
Math.ldexp(3.23, MathSpecs::Integer.new).should be_close(12.92, TOLERANCE)
4747
end
48+
49+
it "returns correct value that closes to the max value of double type" do
50+
Math.ldexp(0.5122058490966879, 1024).should == 9.207889385574391e+307
51+
Math.ldexp(0.9999999999999999, 1024).should == 1.7976931348623157e+308
52+
Math.ldexp(0.99999999999999999, 1024).should == Float::INFINITY
53+
end
4854
end
4955

5056
describe "Math#ldexp" do

spec/ruby/core/module/autoload_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,36 @@ class LexicalScope
577577
end
578578
end
579579

580+
ruby_version_is "3.2" do
581+
it "warns once in verbose mode if the constant was defined in a parent scope" do
582+
ScratchPad.record -> {
583+
ModuleSpecs::DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent
584+
}
585+
586+
module ModuleSpecs
587+
module Autoload
588+
autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
589+
self.autoload?(:DeclaredInCurrentDefinedInParent).should == fixture(__FILE__, "autoload_callback.rb")
590+
const_defined?(:DeclaredInCurrentDefinedInParent).should == true
591+
592+
-> {
593+
DeclaredInCurrentDefinedInParent
594+
}.should complain(
595+
/Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/,
596+
verbose: true,
597+
)
598+
599+
-> {
600+
DeclaredInCurrentDefinedInParent
601+
}.should_not complain(/.*/, verbose: true)
602+
self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
603+
const_defined?(:DeclaredInCurrentDefinedInParent).should == false
604+
ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true
605+
end
606+
end
607+
end
608+
end
609+
580610
ruby_version_is "3.1" do
581611
it "looks up in parent scope after failed autoload" do
582612
@remove << :DeclaredInCurrentDefinedInParent

spec/ruby/core/regexp/shared/new.rb

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ class RegexpSpecsSubclassTwo < Regexp; end
5858
end
5959
end
6060

61+
it "sets options from second argument if it is true" do
62+
r = Regexp.send(@method, 'Hi', true)
63+
(r.options & Regexp::IGNORECASE).should_not == 0
64+
(r.options & Regexp::MULTILINE).should == 0
65+
not_supported_on :opal do
66+
(r.options & Regexp::EXTENDED).should == 0
67+
end
68+
end
69+
6170
it "sets options from second argument if it is one of the Integer option constants" do
6271
r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE)
6372
(r.options & Regexp::IGNORECASE).should_not == 0
@@ -88,12 +97,67 @@ class RegexpSpecsSubclassTwo < Regexp; end
8897
(r.options & Regexp::EXTENDED).should_not == 0
8998
end
9099

91-
it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do
92-
r = Regexp.send(@method, 'Hi', Object.new)
93-
(r.options & Regexp::IGNORECASE).should_not == 0
94-
(r.options & Regexp::MULTILINE).should == 0
95-
not_supported_on :opal do
96-
(r.options & Regexp::EXTENDED).should == 0
100+
ruby_version_is ""..."3.2" do
101+
it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do
102+
r = Regexp.send(@method, 'Hi', Object.new)
103+
(r.options & Regexp::IGNORECASE).should_not == 0
104+
(r.options & Regexp::MULTILINE).should == 0
105+
not_supported_on :opal do
106+
(r.options & Regexp::EXTENDED).should == 0
107+
end
108+
end
109+
end
110+
111+
ruby_version_is "3.2" do
112+
it "warns any non-Integer, non-nil, non-false second argument" do
113+
r = nil
114+
-> {
115+
r = Regexp.send(@method, 'Hi', Object.new)
116+
}.should complain(/expected true or false as ignorecase/, {verbose: true})
117+
(r.options & Regexp::IGNORECASE).should_not == 0
118+
(r.options & Regexp::MULTILINE).should == 0
119+
not_supported_on :opal do
120+
(r.options & Regexp::EXTENDED).should == 0
121+
end
122+
end
123+
124+
it "accepts a String of supported flags as the second argument" do
125+
r = Regexp.send(@method, 'Hi', 'i')
126+
(r.options & Regexp::IGNORECASE).should_not == 0
127+
(r.options & Regexp::MULTILINE).should == 0
128+
not_supported_on :opal do
129+
(r.options & Regexp::EXTENDED).should == 0
130+
end
131+
132+
r = Regexp.send(@method, 'Hi', 'imx')
133+
(r.options & Regexp::IGNORECASE).should_not == 0
134+
(r.options & Regexp::MULTILINE).should_not == 0
135+
not_supported_on :opal do
136+
(r.options & Regexp::EXTENDED).should_not == 0
137+
end
138+
139+
r = Regexp.send(@method, 'Hi', 'mimi')
140+
(r.options & Regexp::IGNORECASE).should_not == 0
141+
(r.options & Regexp::MULTILINE).should_not == 0
142+
not_supported_on :opal do
143+
(r.options & Regexp::EXTENDED).should == 0
144+
end
145+
146+
r = Regexp.send(@method, 'Hi', '')
147+
(r.options & Regexp::IGNORECASE).should == 0
148+
(r.options & Regexp::MULTILINE).should == 0
149+
not_supported_on :opal do
150+
(r.options & Regexp::EXTENDED).should == 0
151+
end
152+
end
153+
154+
it "raises an Argument error if the second argument contains unsupported chars" do
155+
-> { Regexp.send(@method, 'Hi', 'e') }.should raise_error(ArgumentError)
156+
-> { Regexp.send(@method, 'Hi', 'n') }.should raise_error(ArgumentError)
157+
-> { Regexp.send(@method, 'Hi', 's') }.should raise_error(ArgumentError)
158+
-> { Regexp.send(@method, 'Hi', 'u') }.should raise_error(ArgumentError)
159+
-> { Regexp.send(@method, 'Hi', 'j') }.should raise_error(ArgumentError)
160+
-> { Regexp.send(@method, 'Hi', 'mjx') }.should raise_error(ArgumentError)
97161
end
98162
end
99163

0 commit comments

Comments
 (0)