summaryrefslogtreecommitdiff
path: root/test/ruby/test_eval.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_eval.rb')
-rw-r--r--test/ruby/test_eval.rb50
1 files changed, 48 insertions, 2 deletions
diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb
index af255c05c8..d2145bec5d 100644
--- a/test/ruby/test_eval.rb
+++ b/test/ruby/test_eval.rb
@@ -535,6 +535,12 @@ class TestEval < Test::Unit::TestCase
assert_equal(fname, eval("__FILE__", nil, fname, 1))
end
+ def test_eval_invalid_block_exit_bug_20597
+ assert_raise(SyntaxError){eval("break if false")}
+ assert_raise(SyntaxError){eval("next if false")}
+ assert_raise(SyntaxError){eval("redo if false")}
+ end
+
def test_eval_location_fstring
o = Object.new
o.instance_eval "def foo() end", "generated code"
@@ -547,8 +553,8 @@ class TestEval < Test::Unit::TestCase
end
def test_eval_location_binding
- assert_equal(['(eval)', 1], eval("[__FILE__, __LINE__]", nil))
- assert_equal(['(eval)', 1], eval("[__FILE__, __LINE__]", binding))
+ assert_equal(["(eval at #{__FILE__}:#{__LINE__})", 1], eval("[__FILE__, __LINE__]", nil))
+ assert_equal(["(eval at #{__FILE__}:#{__LINE__})", 1], eval("[__FILE__, __LINE__]", binding))
assert_equal(['foo', 1], eval("[__FILE__, __LINE__]", nil, 'foo'))
assert_equal(['foo', 1], eval("[__FILE__, __LINE__]", binding, 'foo'))
assert_equal(['foo', 2], eval("[__FILE__, __LINE__]", nil, 'foo', 2))
@@ -606,4 +612,44 @@ class TestEval < Test::Unit::TestCase
x = orphan_lambda
assert_equal(:ok, x.call)
end
+
+ def test_syntax_error_no_memory_leak
+ assert_no_memory_leak([], "#{<<~'begin;'}", "#{<<~'end;'}", rss: true)
+ begin;
+ 100_000.times do
+ eval("/[/=~s")
+ rescue SyntaxError
+ else
+ raise "Expected SyntaxError to be raised"
+ end
+ end;
+
+ assert_no_memory_leak([], "#{<<~'begin;'}", "#{<<~'end;'}", rss: true)
+ begin;
+ a = 1
+
+ 100_000.times do
+ eval("if a in [0, 0] | [0, a]; end")
+ rescue SyntaxError
+ else
+ raise "Expected SyntaxError to be raised"
+ end
+ end;
+ end
+
+ def test_outer_local_variable_under_gc_compact_stress
+ omit "compaction is not supported on this platform" unless GC.respond_to?(:compact)
+ omit "compaction is not supported on s390x" if /s390x/ =~ RUBY_PLATFORM
+
+ assert_separately([], <<~RUBY)
+ o = Object.new
+ def o.m = 1
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ EnvUtil.under_gc_compact_stress do
+ assert_equal(1, eval("o.m"))
+ end
+ RUBY
+ end
end