1
0
Fork 0
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:
Nobuyoshi Nakada 2020-04-03 09:44:40 +09:00
parent f49a24201c
commit 18f7d3c9a6
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
Notes: git 2020-04-03 10:37:05 +09:00
9 changed files with 197 additions and 163 deletions

View file

@ -14,7 +14,7 @@ describe "The -l command line option" do
it "chomps last line based on $/" do it "chomps last line based on $/" do
ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l", escape: true, ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l", escape: true,
args: " < #{@names}").should == args: " < #{@names}").should ==
"alice j\nbob field\njames grey\n" "alice j\nbob field\njames grey\n"
end end
it "sets $\\ to the value of $/" do it "sets $\\ to the value of $/" do

View file

@ -296,10 +296,10 @@ describe :dir_glob, shared: true do
@mock_dir = File.expand_path tmp('dir_glob_mock') @mock_dir = File.expand_path tmp('dir_glob_mock')
%w[ %w[
a/b/x a/b/x
a/b/c/y a/b/c/y
a/b/c/d/z a/b/c/d/z
].each do |path| ].each do |path|
file = File.join @mock_dir, path file = File.join @mock_dir, path
mkdir_p File.dirname(file) mkdir_p File.dirname(file)
touch file touch file

View file

@ -3,7 +3,7 @@ require_relative '../../spec_helper'
describe "File.utime" do describe "File.utime" do
before :all do before :all do
@time_is_float = /mswin|mingw/ =~ RUBY_PLATFORM && RUBY_VERSION >= '2.5' @time_is_float = /mswin|mingw/ =~ RUBY_PLATFORM
end end
before :each do before :each do

View file

@ -23,8 +23,8 @@ describe "Integer#pow" do
end end
it "handles sign like #divmod does" do it "handles sign like #divmod does" do
2.pow(5, 12).should == 8 2.pow(5, 12).should == 8
2.pow(5, -12).should == -4 2.pow(5, -12).should == -4
-2.pow(5, 12).should == 4 -2.pow(5, 12).should == 4
-2.pow(5, -12).should == -8 -2.pow(5, -12).should == -8
end end

View file

@ -1,5 +1,25 @@
require_relative '../fixtures/classes' 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 describe :integer_arithmetic_coerce_not_rescue, shared: true do
it "does not rescue exception raised in other#coerce" do it "does not rescue exception raised in other#coerce" do
b = mock("numeric with failed #coerce") b = mock("numeric with failed #coerce")

View file

@ -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 it "is executed when an exception is raised in it's corresponding begin block" do
-> { -> {
eval(<<-ruby).call eval(<<-ruby).call
lambda do lambda do
ScratchPad << :begin ScratchPad << :begin
raise EnsureSpec::Error raise EnsureSpec::Error
ensure ensure
ScratchPad << :ensure ScratchPad << :ensure
end end
ruby ruby
}.should raise_error(EnsureSpec::Error) }.should raise_error(EnsureSpec::Error)
ScratchPad.recorded.should == [:begin, :ensure] 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 it "is executed when an exception is raised and rescued in it's corresponding begin block" do
eval(<<-ruby).call eval(<<-ruby).call
lambda do lambda do
ScratchPad << :begin ScratchPad << :begin
raise "An exception occurred!" raise "An exception occurred!"
rescue rescue
ScratchPad << :rescue ScratchPad << :rescue
ensure ensure
ScratchPad << :ensure ScratchPad << :ensure
end end
ruby ruby
ScratchPad.recorded.should == [:begin, :rescue, :ensure] ScratchPad.recorded.should == [:begin, :rescue, :ensure]
end 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 it "is executed even when a symbol is thrown in it's corresponding begin block" do
catch(:symbol) do catch(:symbol) do
eval(<<-ruby).call eval(<<-ruby).call
lambda do lambda do
ScratchPad << :begin ScratchPad << :begin
throw(:symbol) throw(:symbol)
rescue rescue
ScratchPad << :rescue ScratchPad << :rescue
ensure ensure
ScratchPad << :ensure ScratchPad << :ensure
end end
ruby ruby
end end
ScratchPad.recorded.should == [:begin, :ensure] 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 it "is executed when nothing is raised or thrown in it's corresponding begin block" do
eval(<<-ruby).call eval(<<-ruby).call
lambda do lambda do
ScratchPad << :begin ScratchPad << :begin
rescue rescue
ScratchPad << :rescue ScratchPad << :rescue
ensure ensure
ScratchPad << :ensure ScratchPad << :ensure
end end
ruby ruby
ScratchPad.recorded.should == [:begin, :ensure] ScratchPad.recorded.should == [:begin, :ensure]
end end
it "has no return value" do it "has no return value" do
result = eval(<<-ruby).call result = eval(<<-ruby).call
lambda do lambda do
:begin :begin
ensure ensure
:ensure :ensure
end end
ruby ruby
result.should == :begin result.should == :begin
end end

View file

@ -437,12 +437,12 @@ describe "The rescue keyword" do
it "allows rescue in 'do end' block" do it "allows rescue in 'do end' block" do
lambda = eval <<-ruby lambda = eval <<-ruby
lambda do lambda do
raise SpecificExampleException raise SpecificExampleException
rescue SpecificExampleException rescue SpecificExampleException
ScratchPad << :caught ScratchPad << :caught
end.call end.call
ruby ruby
ScratchPad.recorded.should == [:caught] ScratchPad.recorded.should == [:caught]
end end

View file

@ -262,11 +262,11 @@ describe "The return keyword" do
it "stops file execution" do it "stops file execution" do
ruby_exe(<<-END_OF_CODE).should == "before return\n" ruby_exe(<<-END_OF_CODE).should == "before return\n"
puts "before return" puts "before return"
return return
puts "after return" puts "after return"
END_OF_CODE END_OF_CODE
$?.exitstatus.should == 0 $?.exitstatus.should == 0
end end
@ -274,13 +274,13 @@ describe "The return keyword" do
describe "within if" do describe "within if" do
it "is allowed" do it "is allowed" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before if" ScratchPad << "before if"
if true if true
return return
end end
ScratchPad << "after if" ScratchPad << "after if"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before if"] ScratchPad.recorded.should == ["before if"]
@ -290,13 +290,13 @@ describe "The return keyword" do
describe "within while loop" do describe "within while loop" do
it "is allowed" do it "is allowed" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before while" ScratchPad << "before while"
while true while true
return return
end end
ScratchPad << "after while" ScratchPad << "after while"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before while"] ScratchPad.recorded.should == ["before while"]
@ -306,13 +306,13 @@ describe "The return keyword" do
describe "within a begin" do describe "within a begin" do
it "is allowed in begin block" do it "is allowed in begin block" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin" ScratchPad << "before begin"
begin begin
return return
end end
ScratchPad << "after begin" ScratchPad << "after begin"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before begin"] ScratchPad.recorded.should == ["before begin"]
@ -320,14 +320,14 @@ describe "The return keyword" do
it "is allowed in ensure block" do it "is allowed in ensure block" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin" ScratchPad << "before begin"
begin begin
ensure ensure
return return
end end
ScratchPad << "after begin" ScratchPad << "after begin"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before begin"] ScratchPad.recorded.should == ["before begin"]
@ -335,15 +335,15 @@ describe "The return keyword" do
it "is allowed in rescue block" do it "is allowed in rescue block" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin" ScratchPad << "before begin"
begin begin
raise raise
rescue RuntimeError rescue RuntimeError
return return
end end
ScratchPad << "after begin" ScratchPad << "after begin"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before begin"] ScratchPad.recorded.should == ["before begin"]
@ -351,25 +351,41 @@ describe "The return keyword" do
it "fires ensure block before returning" do it "fires ensure block before returning" do
ruby_exe(<<-END_OF_CODE).should == "within ensure\n" ruby_exe(<<-END_OF_CODE).should == "within ensure\n"
begin begin
return return
ensure ensure
puts "within ensure" puts "within ensure"
end end
puts "after begin" puts "after begin"
END_OF_CODE 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 end
it "swallows exception if returns in ensure block" do it "swallows exception if returns in ensure block" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
begin begin
raise raise
ensure ensure
ScratchPad << "before return" ScratchPad << "before return"
return return
end end
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before return"] ScratchPad.recorded.should == ["before return"]
@ -379,11 +395,11 @@ describe "The return keyword" do
describe "within a block" do describe "within a block" do
it "is allowed" do it "is allowed" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before call" ScratchPad << "before call"
proc { return }.call proc { return }.call
ScratchPad << "after call" ScratchPad << "after call"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before call"] ScratchPad.recorded.should == ["before call"]
@ -393,13 +409,13 @@ describe "The return keyword" do
describe "within a class" do describe "within a class" do
it "raises a SyntaxError" do it "raises a SyntaxError" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
class ReturnSpecs::A class ReturnSpecs::A
ScratchPad << "before return" ScratchPad << "before return"
return return
ScratchPad << "after return" ScratchPad << "after return"
end end
END_OF_CODE END_OF_CODE
-> { load @filename }.should raise_error(SyntaxError) -> { load @filename }.should raise_error(SyntaxError)
end end
@ -409,12 +425,12 @@ describe "The return keyword" do
ruby_version_is "2.7" do ruby_version_is "2.7" do
it "is not allowed" do it "is not allowed" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
class ReturnSpecs::A class ReturnSpecs::A
ScratchPad << "before return" ScratchPad << "before return"
1.times { return } 1.times { return }
ScratchPad << "after return" ScratchPad << "after return"
end end
END_OF_CODE END_OF_CODE
-> { load @filename }.should raise_error(LocalJumpError) -> { load @filename }.should raise_error(LocalJumpError)
end end
@ -424,10 +440,10 @@ describe "The return keyword" do
describe "file loading" do describe "file loading" do
it "stops file loading and execution" do it "stops file loading and execution" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before return" ScratchPad << "before return"
return return
ScratchPad << "after return" ScratchPad << "after return"
END_OF_CODE END_OF_CODE
load @filename load @filename
ScratchPad.recorded.should == ["before return"] ScratchPad.recorded.should == ["before return"]
@ -437,10 +453,10 @@ describe "The return keyword" do
describe "file requiring" do describe "file requiring" do
it "stops file loading and execution" do it "stops file loading and execution" do
File.write(@filename, <<-END_OF_CODE) File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before return" ScratchPad << "before return"
return return
ScratchPad << "after return" ScratchPad << "after return"
END_OF_CODE END_OF_CODE
require @filename require @filename
ScratchPad.recorded.should == ["before return"] ScratchPad.recorded.should == ["before return"]
@ -451,8 +467,8 @@ describe "The return keyword" do
ruby_version_is ""..."2.7" do ruby_version_is ""..."2.7" do
it "does not affect exit status" do it "does not affect exit status" do
ruby_exe(<<-END_OF_CODE).should == "" ruby_exe(<<-END_OF_CODE).should == ""
return 10 return 10
END_OF_CODE END_OF_CODE
$?.exitstatus.should == 0 $?.exitstatus.should == 0
end end
@ -461,8 +477,8 @@ describe "The return keyword" do
ruby_version_is "2.7" do ruby_version_is "2.7" do
it "warns but does not affect exit status" do it "warns but does not affect exit status" do
err = ruby_exe(<<-END_OF_CODE, args: "2>&1") err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
return 10 return 10
END_OF_CODE END_OF_CODE
$?.exitstatus.should == 0 $?.exitstatus.should == 0
err.should =~ /warning: argument of top-level return is ignored/ err.should =~ /warning: argument of top-level return is ignored/

View file

@ -106,41 +106,39 @@ describe "ConditionVariable#wait" do
owned.should == true owned.should == true
end end
ruby_bug '#14999', ''...'2.5' do it "reacquires the lock even if the thread is killed after being signaled" do
it "reacquires the lock even if the thread is killed after being signaled" do m = Mutex.new
m = Mutex.new cv = ConditionVariable.new
cv = ConditionVariable.new in_synchronize = false
in_synchronize = false owned = nil
owned = nil
th = Thread.new do th = Thread.new do
m.synchronize do m.synchronize do
in_synchronize = true in_synchronize = true
begin begin
cv.wait(m) cv.wait(m)
ensure ensure
owned = m.owned? owned = m.owned?
$stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned $stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
end
end end
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 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 end
it "supports multiple Threads waiting on the same ConditionVariable and Mutex" do it "supports multiple Threads waiting on the same ConditionVariable and Mutex" do