diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-17 04:24:48 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-17 04:24:48 +0000 |
commit | 41e331cc361a1ba89a5663d2cec7505f5bc82552 (patch) | |
tree | e9622482ff3d7beff75d46add87021f44e608a28 /test | |
parent | 3b243514ffc9f185000f0051fa109b9c3b534b46 (diff) | |
download | ruby-41e331cc361a1ba89a5663d2cec7505f5bc82552.tar.gz |
* enum.c: move work variables to objects not to let called blocks
access stack area out of scope. [Bug #5801]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enum.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index c8f2fad546..1d509b59de 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -13,6 +13,16 @@ class TestEnumerable < Test::Unit::TestCase yield 3 yield 1 yield 2 + self + end + end + @empty = Object.new + class << @empty + attr_reader :block + include Enumerable + def each(&block) + @block = block + self end end @verbose = $VERBOSE @@ -42,6 +52,10 @@ class TestEnumerable < Test::Unit::TestCase a = [] @obj.grep(2) {|x| a << x } assert_equal([2, 2], a) + + bug5801 = '[ruby-dev:45041]' + @empty.grep(//) + assert_nothing_raised(bug5801) {100.times {@empty.block.call}} end def test_count @@ -109,6 +123,7 @@ class TestEnumerable < Test::Unit::TestCase def test_first assert_equal(1, @obj.first) assert_equal([1, 2, 3], @obj.first(3)) + assert_nil(@empty.first) end def test_sort @@ -275,6 +290,10 @@ class TestEnumerable < Test::Unit::TestCase def test_take_while assert_equal([1,2], @obj.take_while {|x| x <= 2}) + + bug5801 = '[ruby-dev:45040]' + @empty.take_while {true} + assert_nothing_raised(bug5801) {100.times {@empty.block.call}} end def test_drop |