summaryrefslogtreecommitdiff
path: root/test/ruby/test_exception.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-14 07:19:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-14 07:19:23 +0000
commite294f4cfdf56afaf956d782e72ca278f5afe0905 (patch)
treed6a54d49b46c5e4c91c34034a1132ac418aac704 /test/ruby/test_exception.rb
parentf061d403264013440070df52bba46588f2897148 (diff)
not overwrite cause
* eval.c (setup_exception): set the cause only if it is explicitly given or not set yet. [Bug #12068] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_exception.rb')
-rw-r--r--test/ruby/test_exception.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 8435c5a5ee..6a1e4864f0 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -625,6 +625,44 @@ end.join
assert_not_same(e, e.cause, "#{msg}: should not be recursive")
end
+ def test_cause_raised_in_rescue
+ e = assert_raise_with_message(RuntimeError, 'b') {
+ begin
+ raise 'a'
+ rescue => a
+ begin
+ raise 'b'
+ rescue => b
+ begin
+ raise 'c'
+ rescue
+ raise b
+ end
+ end
+ end
+ }
+ assert_equal('a', e.cause.message, 'cause should not be overwritten by reraise')
+ end
+
+ def test_cause_at_raised
+ e = assert_raise_with_message(RuntimeError, 'b') {
+ begin
+ raise 'a'
+ rescue => a
+ b = RuntimeError.new('b')
+ begin
+ raise 'c'
+ rescue
+ raise b
+ end
+ end
+ }
+ assert_equal('c', e.cause.message, 'cause should be the exception at raised')
+ end
+
+ def test_cause_at_raised
+ end
+
def test_raise_with_cause
msg = "[Feature #8257]"
cause = ArgumentError.new("foobar")
@@ -639,6 +677,25 @@ end.join
end
end
+ def test_raise_with_cause_in_rescue
+ e = assert_raise_with_message(RuntimeError, 'b') {
+ begin
+ raise 'a'
+ rescue => a
+ begin
+ raise 'b'
+ rescue => b
+ begin
+ raise 'c'
+ rescue
+ raise b, cause: ArgumentError.new('d')
+ end
+ end
+ end
+ }
+ assert_equal('d', e.cause.message, 'cause option should be honored always')
+ end
+
def test_unknown_option
bug = '[ruby-core:63203] [Feature #8257] should pass unknown options'