summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-07 07:45:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-07 07:45:18 +0000
commit5f25ecd4b367ce85a3071e91369542587997d65a (patch)
tree0298b12f236266f2fd6d59c8fca9c9c5cf587b85 /test
parent233fa910d1231720b71dea10cecda84ab1365fa5 (diff)
test_optimization.rb: for r56208
* test/ruby/test_optimization.rb (test_tailcall_condition_block): test for r56208. [ruby-core:78015] [Bug #12905] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_optimization.rb33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 235ec53b57..502d12389e 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -210,7 +210,7 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_equal true, MyObj.new == nil
end
- def self.tailcall(klass, src, file = nil, path = nil, line = nil)
+ def self.tailcall(klass, src, file = nil, path = nil, line = nil, tailcall: true)
unless file
loc, = caller_locations(1, 1)
file = loc.path
@@ -218,7 +218,7 @@ class TestRubyOptimization < Test::Unit::TestCase
end
RubyVM::InstructionSequence.new("proc {|_|_.class_eval {#{src}}}",
file, (path || file), line,
- tailcall_optimization: true,
+ tailcall_optimization: tailcall,
trace_instruction: false)
.eval[klass]
end
@@ -357,6 +357,35 @@ EOS
assert_not_equal("SEGV", Signal.signame(status.termsig || 0), bug12576)
end unless /mswin|mingw/ =~ RUBY_PLATFORM
+ def test_tailcall_condition_block
+ bug = '[ruby-core:78015] [Bug #12905]'
+
+ src = "#{<<-"begin;"}\n#{<<-"end;"}"
+ begin;
+ def run(current, final)
+ if current < final
+ run(current+1, final)
+ else
+ nil
+ end
+ end
+ end;
+
+ obj = Object.new
+ self.class.tailcall(obj.singleton_class, src, tailcall: false)
+ e = assert_raise(SystemStackError) {
+ obj.run(1, Float::INFINITY)
+ }
+ level = e.backtrace_locations.size
+ obj = Object.new
+ self.class.tailcall(obj.singleton_class, src, tailcall: true)
+ level *= 2
+ mesg = message {"#{bug}: #{$!.backtrace_locations.size} / #{level} stack levels"}
+ assert_nothing_raised(SystemStackError, mesg) {
+ obj.run(1, level)
+ }
+ end
+
class Bug10557
def [](_)
block_given?