summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-19 00:43:25 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-19 00:43:25 +0900
commit9c94db7cfc584e982a6449b72e58a1cf25024177 (patch)
tree721dd9af558bf8ee1a5c38511bc9dd3605946dfa
parentd6ad334d6ed55778961b05b1a4fa18912230bf12 (diff)
Add tests for `return` in `BEGIN` and `END` blocks
-rw-r--r--spec/ruby/language/return_spec.rb15
-rw-r--r--test/ruby/test_syntax.rb1
2 files changed, 16 insertions, 0 deletions
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 94c15b697e..a62ed1242d 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -435,6 +435,21 @@ describe "The return keyword" do
end
end
+ describe "within BEGIN" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ BEGIN {
+ ScratchPad << "before call"
+ return
+ ScratchPad << "after call"
+ }
+ END_OF_CODE
+
+ load @filename
+ ScratchPad.recorded.should == ["before call"]
+ end
+ end
+
describe "file loading" do
it "stops file loading and execution" do
File.write(@filename, <<-END_OF_CODE)
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index b920dacc4a..5c382fac7a 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1369,6 +1369,7 @@ eom
begin raise; ensure return; end and self
nil&defined?0--begin e=no_method_error(); return; 0;end
return puts('ignored') #=> ignored
+ BEGIN {return}
end;
.split(/\n/).map {|s|[(line+=1), *s.split(/#=> /, 2)]}
failed = proc do |n, s|