mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Refined "Drop support for ruby 2.4 from ruby/spec"
By using spec/mspec/tool/remove_old_guards.rb.
This commit is contained in:
parent
f49a24201c
commit
18f7d3c9a6
Notes:
git
2020-04-03 10:37:05 +09:00
9 changed files with 197 additions and 163 deletions
|
@ -14,7 +14,7 @@ describe "The -l command line option" do
|
|||
it "chomps last line based on $/" do
|
||||
ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"alice j\nbob field\njames grey\n"
|
||||
"alice j\nbob field\njames grey\n"
|
||||
end
|
||||
|
||||
it "sets $\\ to the value of $/" do
|
||||
|
|
|
@ -296,10 +296,10 @@ describe :dir_glob, shared: true do
|
|||
@mock_dir = File.expand_path tmp('dir_glob_mock')
|
||||
|
||||
%w[
|
||||
a/b/x
|
||||
a/b/c/y
|
||||
a/b/c/d/z
|
||||
].each do |path|
|
||||
a/b/x
|
||||
a/b/c/y
|
||||
a/b/c/d/z
|
||||
].each do |path|
|
||||
file = File.join @mock_dir, path
|
||||
mkdir_p File.dirname(file)
|
||||
touch file
|
||||
|
|
|
@ -3,7 +3,7 @@ require_relative '../../spec_helper'
|
|||
describe "File.utime" do
|
||||
|
||||
before :all do
|
||||
@time_is_float = /mswin|mingw/ =~ RUBY_PLATFORM && RUBY_VERSION >= '2.5'
|
||||
@time_is_float = /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
end
|
||||
|
||||
before :each do
|
||||
|
|
|
@ -23,8 +23,8 @@ describe "Integer#pow" do
|
|||
end
|
||||
|
||||
it "handles sign like #divmod does" do
|
||||
2.pow(5, 12).should == 8
|
||||
2.pow(5, -12).should == -4
|
||||
2.pow(5, 12).should == 8
|
||||
2.pow(5, -12).should == -4
|
||||
-2.pow(5, 12).should == 4
|
||||
-2.pow(5, -12).should == -8
|
||||
end
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
require_relative '../fixtures/classes'
|
||||
|
||||
describe :integer_arithmetic_coerce_rescue, shared: true do
|
||||
it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do
|
||||
b = mock("numeric with failed #coerce")
|
||||
b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
|
||||
|
||||
# e.g. 1 + b
|
||||
-> { 1.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Integer/)
|
||||
end
|
||||
|
||||
it "does not rescue Exception and StandardError siblings raised in other#coerce" do
|
||||
[Exception, NoMemoryError].each do |exception|
|
||||
b = mock("numeric with failed #coerce")
|
||||
b.should_receive(:coerce).and_raise(exception)
|
||||
|
||||
# e.g. 1 + b
|
||||
-> { 1.send(@method, b) }.should raise_error(exception)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe :integer_arithmetic_coerce_not_rescue, shared: true do
|
||||
it "does not rescue exception raised in other#coerce" do
|
||||
b = mock("numeric with failed #coerce")
|
||||
|
|
|
@ -259,13 +259,13 @@ describe "An ensure block inside 'do end' block" do
|
|||
it "is executed when an exception is raised in it's corresponding begin block" do
|
||||
-> {
|
||||
eval(<<-ruby).call
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
raise EnsureSpec::Error
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
raise EnsureSpec::Error
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
}.should raise_error(EnsureSpec::Error)
|
||||
|
||||
ScratchPad.recorded.should == [:begin, :ensure]
|
||||
|
@ -273,15 +273,15 @@ describe "An ensure block inside 'do end' block" do
|
|||
|
||||
it "is executed when an exception is raised and rescued in it's corresponding begin block" do
|
||||
eval(<<-ruby).call
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
raise "An exception occurred!"
|
||||
rescue
|
||||
ScratchPad << :rescue
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
raise "An exception occurred!"
|
||||
rescue
|
||||
ScratchPad << :rescue
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
|
||||
ScratchPad.recorded.should == [:begin, :rescue, :ensure]
|
||||
end
|
||||
|
@ -289,15 +289,15 @@ describe "An ensure block inside 'do end' block" do
|
|||
it "is executed even when a symbol is thrown in it's corresponding begin block" do
|
||||
catch(:symbol) do
|
||||
eval(<<-ruby).call
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
throw(:symbol)
|
||||
rescue
|
||||
ScratchPad << :rescue
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
throw(:symbol)
|
||||
rescue
|
||||
ScratchPad << :rescue
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
end
|
||||
|
||||
ScratchPad.recorded.should == [:begin, :ensure]
|
||||
|
@ -305,26 +305,26 @@ describe "An ensure block inside 'do end' block" do
|
|||
|
||||
it "is executed when nothing is raised or thrown in it's corresponding begin block" do
|
||||
eval(<<-ruby).call
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
rescue
|
||||
ScratchPad << :rescue
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
lambda do
|
||||
ScratchPad << :begin
|
||||
rescue
|
||||
ScratchPad << :rescue
|
||||
ensure
|
||||
ScratchPad << :ensure
|
||||
end
|
||||
ruby
|
||||
|
||||
ScratchPad.recorded.should == [:begin, :ensure]
|
||||
end
|
||||
|
||||
it "has no return value" do
|
||||
result = eval(<<-ruby).call
|
||||
lambda do
|
||||
:begin
|
||||
ensure
|
||||
:ensure
|
||||
end
|
||||
ruby
|
||||
lambda do
|
||||
:begin
|
||||
ensure
|
||||
:ensure
|
||||
end
|
||||
ruby
|
||||
|
||||
result.should == :begin
|
||||
end
|
||||
|
|
|
@ -437,12 +437,12 @@ describe "The rescue keyword" do
|
|||
|
||||
it "allows rescue in 'do end' block" do
|
||||
lambda = eval <<-ruby
|
||||
lambda do
|
||||
raise SpecificExampleException
|
||||
rescue SpecificExampleException
|
||||
ScratchPad << :caught
|
||||
end.call
|
||||
ruby
|
||||
lambda do
|
||||
raise SpecificExampleException
|
||||
rescue SpecificExampleException
|
||||
ScratchPad << :caught
|
||||
end.call
|
||||
ruby
|
||||
|
||||
ScratchPad.recorded.should == [:caught]
|
||||
end
|
||||
|
|
|
@ -262,11 +262,11 @@ describe "The return keyword" do
|
|||
|
||||
it "stops file execution" do
|
||||
ruby_exe(<<-END_OF_CODE).should == "before return\n"
|
||||
puts "before return"
|
||||
return
|
||||
puts "before return"
|
||||
return
|
||||
|
||||
puts "after return"
|
||||
END_OF_CODE
|
||||
puts "after return"
|
||||
END_OF_CODE
|
||||
|
||||
$?.exitstatus.should == 0
|
||||
end
|
||||
|
@ -274,13 +274,13 @@ describe "The return keyword" do
|
|||
describe "within if" do
|
||||
it "is allowed" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before if"
|
||||
if true
|
||||
return
|
||||
end
|
||||
ScratchPad << "before if"
|
||||
if true
|
||||
return
|
||||
end
|
||||
|
||||
ScratchPad << "after if"
|
||||
END_OF_CODE
|
||||
ScratchPad << "after if"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before if"]
|
||||
|
@ -290,13 +290,13 @@ describe "The return keyword" do
|
|||
describe "within while loop" do
|
||||
it "is allowed" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before while"
|
||||
while true
|
||||
return
|
||||
end
|
||||
ScratchPad << "before while"
|
||||
while true
|
||||
return
|
||||
end
|
||||
|
||||
ScratchPad << "after while"
|
||||
END_OF_CODE
|
||||
ScratchPad << "after while"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before while"]
|
||||
|
@ -306,13 +306,13 @@ describe "The return keyword" do
|
|||
describe "within a begin" do
|
||||
it "is allowed in begin block" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
return
|
||||
end
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
return
|
||||
end
|
||||
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before begin"]
|
||||
|
@ -320,14 +320,14 @@ describe "The return keyword" do
|
|||
|
||||
it "is allowed in ensure block" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
ensure
|
||||
return
|
||||
end
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
ensure
|
||||
return
|
||||
end
|
||||
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before begin"]
|
||||
|
@ -335,15 +335,15 @@ describe "The return keyword" do
|
|||
|
||||
it "is allowed in rescue block" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
raise
|
||||
rescue RuntimeError
|
||||
return
|
||||
end
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
raise
|
||||
rescue RuntimeError
|
||||
return
|
||||
end
|
||||
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before begin"]
|
||||
|
@ -351,25 +351,41 @@ describe "The return keyword" do
|
|||
|
||||
it "fires ensure block before returning" do
|
||||
ruby_exe(<<-END_OF_CODE).should == "within ensure\n"
|
||||
begin
|
||||
return
|
||||
ensure
|
||||
puts "within ensure"
|
||||
end
|
||||
begin
|
||||
return
|
||||
ensure
|
||||
puts "within ensure"
|
||||
end
|
||||
|
||||
puts "after begin"
|
||||
END_OF_CODE
|
||||
puts "after begin"
|
||||
END_OF_CODE
|
||||
end
|
||||
|
||||
it "fires ensure block before returning while loads file" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before begin"
|
||||
begin
|
||||
return
|
||||
ensure
|
||||
ScratchPad << "within ensure"
|
||||
end
|
||||
|
||||
ScratchPad << "after begin"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before begin", "within ensure"]
|
||||
end
|
||||
|
||||
it "swallows exception if returns in ensure block" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
begin
|
||||
raise
|
||||
ensure
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
end
|
||||
END_OF_CODE
|
||||
begin
|
||||
raise
|
||||
ensure
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
end
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before return"]
|
||||
|
@ -379,11 +395,11 @@ describe "The return keyword" do
|
|||
describe "within a block" do
|
||||
it "is allowed" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before call"
|
||||
proc { return }.call
|
||||
ScratchPad << "before call"
|
||||
proc { return }.call
|
||||
|
||||
ScratchPad << "after call"
|
||||
END_OF_CODE
|
||||
ScratchPad << "after call"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before call"]
|
||||
|
@ -393,13 +409,13 @@ describe "The return keyword" do
|
|||
describe "within a class" do
|
||||
it "raises a SyntaxError" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
class ReturnSpecs::A
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
class ReturnSpecs::A
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
|
||||
ScratchPad << "after return"
|
||||
end
|
||||
END_OF_CODE
|
||||
ScratchPad << "after return"
|
||||
end
|
||||
END_OF_CODE
|
||||
|
||||
-> { load @filename }.should raise_error(SyntaxError)
|
||||
end
|
||||
|
@ -409,12 +425,12 @@ describe "The return keyword" do
|
|||
ruby_version_is "2.7" do
|
||||
it "is not allowed" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
class ReturnSpecs::A
|
||||
ScratchPad << "before return"
|
||||
1.times { return }
|
||||
ScratchPad << "after return"
|
||||
end
|
||||
END_OF_CODE
|
||||
class ReturnSpecs::A
|
||||
ScratchPad << "before return"
|
||||
1.times { return }
|
||||
ScratchPad << "after return"
|
||||
end
|
||||
END_OF_CODE
|
||||
|
||||
-> { load @filename }.should raise_error(LocalJumpError)
|
||||
end
|
||||
|
@ -424,10 +440,10 @@ describe "The return keyword" do
|
|||
describe "file loading" do
|
||||
it "stops file loading and execution" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
ScratchPad << "after return"
|
||||
END_OF_CODE
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
ScratchPad << "after return"
|
||||
END_OF_CODE
|
||||
|
||||
load @filename
|
||||
ScratchPad.recorded.should == ["before return"]
|
||||
|
@ -437,10 +453,10 @@ describe "The return keyword" do
|
|||
describe "file requiring" do
|
||||
it "stops file loading and execution" do
|
||||
File.write(@filename, <<-END_OF_CODE)
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
ScratchPad << "after return"
|
||||
END_OF_CODE
|
||||
ScratchPad << "before return"
|
||||
return
|
||||
ScratchPad << "after return"
|
||||
END_OF_CODE
|
||||
|
||||
require @filename
|
||||
ScratchPad.recorded.should == ["before return"]
|
||||
|
@ -451,8 +467,8 @@ describe "The return keyword" do
|
|||
ruby_version_is ""..."2.7" do
|
||||
it "does not affect exit status" do
|
||||
ruby_exe(<<-END_OF_CODE).should == ""
|
||||
return 10
|
||||
END_OF_CODE
|
||||
return 10
|
||||
END_OF_CODE
|
||||
|
||||
$?.exitstatus.should == 0
|
||||
end
|
||||
|
@ -461,8 +477,8 @@ describe "The return keyword" do
|
|||
ruby_version_is "2.7" do
|
||||
it "warns but does not affect exit status" do
|
||||
err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
|
||||
return 10
|
||||
END_OF_CODE
|
||||
return 10
|
||||
END_OF_CODE
|
||||
$?.exitstatus.should == 0
|
||||
|
||||
err.should =~ /warning: argument of top-level return is ignored/
|
||||
|
|
|
@ -106,41 +106,39 @@ describe "ConditionVariable#wait" do
|
|||
owned.should == true
|
||||
end
|
||||
|
||||
ruby_bug '#14999', ''...'2.5' do
|
||||
it "reacquires the lock even if the thread is killed after being signaled" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
in_synchronize = false
|
||||
owned = nil
|
||||
it "reacquires the lock even if the thread is killed after being signaled" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
in_synchronize = false
|
||||
owned = nil
|
||||
|
||||
th = Thread.new do
|
||||
m.synchronize do
|
||||
in_synchronize = true
|
||||
begin
|
||||
cv.wait(m)
|
||||
ensure
|
||||
owned = m.owned?
|
||||
$stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
|
||||
end
|
||||
th = Thread.new do
|
||||
m.synchronize do
|
||||
in_synchronize = true
|
||||
begin
|
||||
cv.wait(m)
|
||||
ensure
|
||||
owned = m.owned?
|
||||
$stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
|
||||
end
|
||||
end
|
||||
|
||||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass until th.stop?
|
||||
|
||||
m.synchronize {
|
||||
cv.signal
|
||||
# Wait that the thread is blocked on acquiring the Mutex
|
||||
sleep 0.001
|
||||
# Kill the thread, yet the thread should first acquire the Mutex before going on
|
||||
th.kill
|
||||
}
|
||||
|
||||
th.join
|
||||
owned.should == true
|
||||
end
|
||||
|
||||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass until th.stop?
|
||||
|
||||
m.synchronize {
|
||||
cv.signal
|
||||
# Wait that the thread is blocked on acquiring the Mutex
|
||||
sleep 0.001
|
||||
# Kill the thread, yet the thread should first acquire the Mutex before going on
|
||||
th.kill
|
||||
}
|
||||
|
||||
th.join
|
||||
owned.should == true
|
||||
end
|
||||
|
||||
it "supports multiple Threads waiting on the same ConditionVariable and Mutex" do
|
||||
|
|
Loading…
Reference in a new issue