summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 05:38:08 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 05:38:08 +0000
commit22a97cbf830ff18042a8b59df8eaa03ab29bbc30 (patch)
tree26d34bf8e12784cbe30119d3a32aa5e199294c99 /test
parent82e65291b1851895fd2d6eedcf7ed53348e5d2a0 (diff)
merge revision(s) 53819,53822: [Backport #12068]
* 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/branches/ruby_2_2@54675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_exception.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 65d00e8bcd..5ca54ecbe1 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -618,6 +618,41 @@ 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_raise_with_cause
msg = "[Feature #8257]"
cause = ArgumentError.new("foobar")
@@ -632,6 +667,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'