aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-03 09:44:40 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-03 09:44:40 +0900
commit18f7d3c9a647f31f11e182d900b88edf5e34ea4b (patch)
tree8eb67d6720e79022a9102ffb5c4e17155f324995
parentf49a24201c8bbcf9fcb4349174e468a673d14b98 (diff)
downloadruby-18f7d3c9a647f31f11e182d900b88edf5e34ea4b.tar.gz
Refined "Drop support for ruby 2.4 from ruby/spec"
By using spec/mspec/tool/remove_old_guards.rb.
-rw-r--r--spec/ruby/command_line/dash_l_spec.rb2
-rw-r--r--spec/ruby/core/dir/shared/glob.rb8
-rw-r--r--spec/ruby/core/file/utime_spec.rb2
-rw-r--r--spec/ruby/core/integer/pow_spec.rb4
-rw-r--r--spec/ruby/core/integer/shared/arithmetic_coerce.rb20
-rw-r--r--spec/ruby/language/ensure_spec.rb76
-rw-r--r--spec/ruby/language/rescue_spec.rb12
-rw-r--r--spec/ruby/language/return_spec.rb174
-rw-r--r--spec/ruby/library/conditionvariable/wait_spec.rb60
9 files changed, 196 insertions, 162 deletions
diff --git a/spec/ruby/command_line/dash_l_spec.rb b/spec/ruby/command_line/dash_l_spec.rb
index 65d6592f22..5c1d3cf4cd 100644
--- a/spec/ruby/command_line/dash_l_spec.rb
+++ b/spec/ruby/command_line/dash_l_spec.rb
@@ -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
diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb
index 0fcfcc4eea..fcaa0d8a43 100644
--- a/spec/ruby/core/dir/shared/glob.rb
+++ b/spec/ruby/core/dir/shared/glob.rb
@@ -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
diff --git a/spec/ruby/core/file/utime_spec.rb b/spec/ruby/core/file/utime_spec.rb
index 9c198af18b..d703681115 100644
--- a/spec/ruby/core/file/utime_spec.rb
+++ b/spec/ruby/core/file/utime_spec.rb
@@ -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
diff --git a/spec/ruby/core/integer/pow_spec.rb b/spec/ruby/core/integer/pow_spec.rb
index f3fb1da916..d7561baf96 100644
--- a/spec/ruby/core/integer/pow_spec.rb
+++ b/spec/ruby/core/integer/pow_spec.rb
@@ -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
diff --git a/spec/ruby/core/integer/shared/arithmetic_coerce.rb b/spec/ruby/core/integer/shared/arithmetic_coerce.rb
index 1260192df1..4c0cbcb999 100644
--- a/spec/ruby/core/integer/shared/arithmetic_coerce.rb
+++ b/spec/ruby/core/integer/shared/arithmetic_coerce.rb
@@ -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")
diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb
index da2389e993..e94c523e82 100644
--- a/spec/ruby/language/ensure_spec.rb
+++ b/spec/ruby/language/ensure_spec.rb
@@ -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,42 +289,42 @@ 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
- end
-
- ScratchPad.recorded.should == [:begin, :ensure]
- end
-
- it "is executed when nothing is raised or thrown in it's corresponding begin block" do
- eval(<<-ruby).call
lambda do
ScratchPad << :begin
+ throw(:symbol)
rescue
ScratchPad << :rescue
ensure
ScratchPad << :ensure
end
ruby
+ end
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ 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
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
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index aa529328a5..7fa674d009 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -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
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 6b428c3f56..d8506834c8 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -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/
diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb
index b545c6c15e..9a68c2b5a1 100644
--- a/spec/ruby/library/conditionvariable/wait_spec.rb
+++ b/spec/ruby/library/conditionvariable/wait_spec.rb
@@ -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
-
- 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
+ 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
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
- }
+ # wait for m to acquire the mutex
+ Thread.pass until in_synchronize
+ # wait until th is sleeping (ie waiting)
+ Thread.pass until th.stop?
- th.join
- owned.should == true
- end
+ 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