diff options
| author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-25 09:55:46 +0000 |
|---|---|---|
| committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-25 09:55:46 +0000 |
| commit | 58281065f229f02e78d56873a21c1d2b3cc80a1c (patch) | |
| tree | 33b08b6865f18ae196faa1ea3f14ddeed9aa66bf | |
| parent | 3772fc484b7c48dabccaff8c002b7da7a8726b84 (diff) | |
merges r20866 and r20968 from trunk into ruby_1_9_1.
* error.c (exc_equal): duck typing equal to make it transitive.
[ruby-dev:34880]
--
* error.c (exc_equal): == method should not raise Exception.
[ruby-dev:37519]
* sample/test.rb: fix test
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@21025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 12 | ||||
| -rw-r--r-- | error.c | 26 | ||||
| -rw-r--r-- | sample/test.rb | 8 |
3 files changed, 39 insertions, 7 deletions
@@ -1,3 +1,15 @@ +Wed Dec 24 20:59:12 2008 Koichi Sasada <ko1@atdot.net> + + * error.c (exc_equal): == method should not raise Exception. + [ruby-dev:37519] + + * sample/test.rb: fix test + +Fri Dec 19 07:45:37 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * error.c (exc_equal): duck typing equal to make it transitive. + [ruby-dev:34880] + Wed Dec 24 20:33:45 2008 Koichi Sasada <ko1@atdot.net> * vm_insnhelper.c (vm_call_method): use class of method defined @@ -554,15 +554,33 @@ exc_set_backtrace(VALUE exc, VALUE bt) static VALUE exc_equal(VALUE exc, VALUE obj) { + VALUE mesg, backtrace; ID id_mesg; if (exc == obj) return Qtrue; - if (rb_obj_class(exc) != rb_obj_class(obj)) - return Qfalse; CONST_ID(id_mesg, "mesg"); - if (!rb_equal(rb_attr_get(exc, id_mesg), rb_attr_get(obj, id_mesg))) + + if (rb_obj_class(exc) != rb_obj_class(obj)) { + ID id_message, id_backtrace; + CONST_ID(id_message, "message"); + CONST_ID(id_backtrace, "backtrace"); + + if (rb_respond_to(obj, id_message) && rb_respond_to(obj, id_backtrace)) { + mesg = rb_funcall(obj, id_message, 0, 0); + backtrace = rb_funcall(obj, id_backtrace, 0, 0); + } + else { + return Qfalse; + } + } + else { + mesg = rb_attr_get(obj, id_mesg); + backtrace = exc_backtrace(obj); + } + + if (!rb_equal(rb_attr_get(exc, id_mesg), mesg)) return Qfalse; - if (!rb_equal(exc_backtrace(exc), exc_backtrace(obj))) + if (!rb_equal(exc_backtrace(exc), backtrace)) return Qfalse; return Qtrue; } diff --git a/sample/test.rb b/sample/test.rb index 34e96204a..21656885f 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -660,10 +660,12 @@ begin raise $string end test_ok(false) -rescue - test_ok(true) if $! == $string +rescue => e + test_ok($! == e) + test_ok(e.message == $string) + test_ok(e != $string) end - + # exception in ensure clause begin begin |
