summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2023-01-17 10:08:06 +0900
committerNobuyoshi Nakada <[email protected]>2023-01-24 16:36:33 +0900
commit5a73e131d7458b3ede3d0f5a4447989a43ee915b (patch)
treeaa72942ccdb37f4a209447920f8ede7be35a3b4b
parent98081ac7cce12adac5b9fcadfba372498e118097 (diff)
Add tests for variables in `END` block shared with the toplevel
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7136
-rw-r--r--spec/ruby/language/END_spec.rb4
-rw-r--r--test/ruby/test_beginendblock.rb5
2 files changed, 9 insertions, 0 deletions
diff --git a/spec/ruby/language/END_spec.rb b/spec/ruby/language/END_spec.rb
index 762a8db0c0..787f602d88 100644
--- a/spec/ruby/language/END_spec.rb
+++ b/spec/ruby/language/END_spec.rb
@@ -12,4 +12,8 @@ describe "The END keyword" do
it "runs multiple ends in LIFO order" do
ruby_exe("END { puts 'foo' }; END { puts 'bar' }").should == "bar\nfoo\n"
end
+
+ it "is affected by the toplevel assignment" do
+ ruby_exe("foo = 'foo'; END { puts foo }").should == "foo\n"
+ end
end
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb
index eb8394864f..2b281645b5 100644
--- a/test/ruby/test_beginendblock.rb
+++ b/test/ruby/test_beginendblock.rb
@@ -14,6 +14,11 @@ class TestBeginEndBlock < Test::Unit::TestCase
assert_in_out_err(["-p", "-eBEGIN{p :begin}", "-eEND{p :end}"], "foo\nbar\n", %w(:begin foo bar :end))
end
+ def test_endblock_variable
+ assert_in_out_err(["-n", "-ea = :ok", "-eEND{p a}"], "foo\n", %w(:ok))
+ assert_in_out_err(["-p", "-ea = :ok", "-eEND{p a}"], "foo\n", %w(foo :ok))
+ end
+
def test_begininmethod
assert_raise_with_message(SyntaxError, /BEGIN is permitted only at toplevel/) do
eval("def foo; BEGIN {}; end")