From 826f44834fe11f3f9c52343443a15b6c83466889 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 8 Feb 2020 19:43:27 +0900 Subject: Drop support for ruby 2.4 from ruby/spec --- spec/ruby/language/return_spec.rb | 214 ++++++++++++++++---------------------- 1 file changed, 88 insertions(+), 126 deletions(-) (limited to 'spec/ruby/language/return_spec.rb') diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb index 7eef6d06ca..6b428c3f56 100644 --- a/spec/ruby/language/return_spec.rb +++ b/spec/ruby/language/return_spec.rb @@ -250,31 +250,30 @@ describe "The return keyword" do end end - ruby_version_is '2.4.2' do - describe "at top level" do - before :each do - @filename = tmp("top_return.rb") - ScratchPad.record [] - end + describe "at top level" do + before :each do + @filename = tmp("top_return.rb") + ScratchPad.record [] + end - after do - rm_r @filename - end + after do + rm_r @filename + end - it "stops file execution" do - ruby_exe(<<-END_OF_CODE).should == "before return\n" + it "stops file execution" do + ruby_exe(<<-END_OF_CODE).should == "before return\n" puts "before return" return puts "after return" END_OF_CODE - $?.exitstatus.should == 0 - end + $?.exitstatus.should == 0 + end - describe "within if" do - it "is allowed" do - File.write(@filename, <<-END_OF_CODE) + describe "within if" do + it "is allowed" do + File.write(@filename, <<-END_OF_CODE) ScratchPad << "before if" if true return @@ -283,14 +282,14 @@ describe "The return keyword" do ScratchPad << "after if" END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before if"] - end + load @filename + ScratchPad.recorded.should == ["before if"] end + end - describe "within while loop" do - it "is allowed" do - File.write(@filename, <<-END_OF_CODE) + describe "within while loop" do + it "is allowed" do + File.write(@filename, <<-END_OF_CODE) ScratchPad << "before while" while true return @@ -299,14 +298,14 @@ describe "The return keyword" do ScratchPad << "after while" END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before while"] - end + load @filename + ScratchPad.recorded.should == ["before while"] end + end - describe "within a begin" do - it "is allowed in begin block" do - File.write(@filename, <<-END_OF_CODE) + describe "within a begin" do + it "is allowed in begin block" do + File.write(@filename, <<-END_OF_CODE) ScratchPad << "before begin" begin return @@ -315,12 +314,12 @@ describe "The return keyword" do ScratchPad << "after begin" END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before begin"] - end + load @filename + ScratchPad.recorded.should == ["before begin"] + end - it "is allowed in ensure block" do - File.write(@filename, <<-END_OF_CODE) + it "is allowed in ensure block" do + File.write(@filename, <<-END_OF_CODE) ScratchPad << "before begin" begin ensure @@ -330,12 +329,12 @@ describe "The return keyword" do ScratchPad << "after begin" END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before begin"] - end + load @filename + ScratchPad.recorded.should == ["before begin"] + end - it "is allowed in rescue block" do - File.write(@filename, <<-END_OF_CODE) + it "is allowed in rescue block" do + File.write(@filename, <<-END_OF_CODE) ScratchPad << "before begin" begin raise @@ -346,12 +345,12 @@ describe "The return keyword" do ScratchPad << "after begin" END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before begin"] - end + load @filename + ScratchPad.recorded.should == ["before begin"] + end - it "fires ensure block before returning" do - ruby_exe(<<-END_OF_CODE).should == "within ensure\n" + it "fires ensure block before returning" do + ruby_exe(<<-END_OF_CODE).should == "within ensure\n" begin return ensure @@ -360,28 +359,10 @@ describe "The return keyword" do puts "after begin" END_OF_CODE - end - - ruby_bug "#14061", "2.4"..."2.5" do - 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 + end - it "swallows exception if returns in ensure block" do - File.write(@filename, <<-END_OF_CODE) + it "swallows exception if returns in ensure block" do + File.write(@filename, <<-END_OF_CODE) begin raise ensure @@ -390,45 +371,28 @@ describe "The return keyword" do end END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before return"] - end + load @filename + ScratchPad.recorded.should == ["before return"] end + end - describe "within a block" do - it "is allowed" do - File.write(@filename, <<-END_OF_CODE) + describe "within a block" do + it "is allowed" do + File.write(@filename, <<-END_OF_CODE) ScratchPad << "before call" proc { return }.call ScratchPad << "after call" END_OF_CODE - load @filename - ScratchPad.recorded.should == ["before call"] - end + load @filename + ScratchPad.recorded.should == ["before call"] end + end - describe "within a class" do - ruby_version_is ""..."2.5" do - it "is allowed" do - File.write(@filename, <<-END_OF_CODE) - class ReturnSpecs::A - ScratchPad << "before return" - return - - ScratchPad << "after return" - end - END_OF_CODE - - load @filename - ScratchPad.recorded.should == ["before return"] - end - end - - ruby_version_is "2.5" do - it "raises a SyntaxError" do - File.write(@filename, <<-END_OF_CODE) + describe "within a class" do + it "raises a SyntaxError" do + File.write(@filename, <<-END_OF_CODE) class ReturnSpecs::A ScratchPad << "before return" return @@ -437,15 +401,14 @@ describe "The return keyword" do end END_OF_CODE - -> { load @filename }.should raise_error(SyntaxError) - end - end + -> { load @filename }.should raise_error(SyntaxError) end + end - describe "within a block within a class" do - ruby_version_is "2.7" do - it "is not allowed" do - File.write(@filename, <<-END_OF_CODE) + describe "within a block within a class" 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 } @@ -453,57 +416,56 @@ describe "The return keyword" do end END_OF_CODE - -> { load @filename }.should raise_error(LocalJumpError) - end + -> { load @filename }.should raise_error(LocalJumpError) end end + end - describe "file loading" do - it "stops file loading and execution" do - File.write(@filename, <<-END_OF_CODE) + 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 - load @filename - ScratchPad.recorded.should == ["before return"] - end + load @filename + ScratchPad.recorded.should == ["before return"] end + end - describe "file requiring" do - it "stops file loading and execution" do - File.write(@filename, <<-END_OF_CODE) + 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 - require @filename - ScratchPad.recorded.should == ["before return"] - end + require @filename + ScratchPad.recorded.should == ["before return"] end + end - describe "return with argument" do - ruby_version_is ""..."2.7" do - it "does not affect exit status" do - ruby_exe(<<-END_OF_CODE).should == "" + describe "return with argument" 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 - $?.exitstatus.should == 0 - end + $?.exitstatus.should == 0 end + end - ruby_version_is "2.7" do - it "warns but does not affect exit status" do - err = ruby_exe(<<-END_OF_CODE, args: "2>&1") + 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 - $?.exitstatus.should == 0 + $?.exitstatus.should == 0 - err.should =~ /warning: argument of top-level return is ignored/ - end + err.should =~ /warning: argument of top-level return is ignored/ end end end -- cgit v1.2.3