[DRE-commits] [ruby-rjb] 04/11: add Exception#cause test

Jérémy Bobbio lunar at moszumanska.debian.org
Thu Apr 10 18:57:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository ruby-rjb.

commit 12497f04cb5835235864300f523e91053a1ba393
Author: arton <artonx at yahoo.co.jp>
Date:   Fri Jan 3 18:57:24 2014 +0900

    add Exception#cause test
---
 ChangeLog          |   6 ++++++
 ext/rjbexception.c |   6 +++---
 test/Test.java     |   8 ++++++++
 test/rjbtest.jar   | Bin 5610 -> 5928 bytes
 test/test.rb       |  13 +++++++++++++
 5 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 85ebfb1..fc9b091 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jan 4 2014 arton
+ *test/Test.java
+ *test/rjbtest.jar
+	add inner exception test
+ *test/test.java
+	add inner exception test
 Fri Jan 3 2014 arton
  *ext/rjb.c
 	RJB_VERSION -> 1.4.9
diff --git a/ext/rjbexception.c b/ext/rjbexception.c
index 20560ae..b7f9cb0 100644
--- a/ext/rjbexception.c
+++ b/ext/rjbexception.c
@@ -34,7 +34,7 @@ static VALUE missing_delegate(int argc, VALUE* argv, VALUE self)
 
 static VALUE get_cause(VALUE self)
 {
-  return rb_ivar_get(self, rb_intern("@cause"));
+  return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rb_intern("cause"), 0);
 }
 
 static VALUE exception_to_s(VALUE self)
@@ -71,8 +71,8 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
     if (rexp == Qnil)
     {
 	rexp = rb_define_class(pcls, rb_eStandardError);
-	rb_define_method(rexp, "cause", get_cause, -1);
-        rb_define_method(rexp, "method_missing", missing_delegate, 0);
+	rb_define_method(rexp, "cause", get_cause, 0);
+        rb_define_method(rexp, "method_missing", missing_delegate, -1);
         rb_define_method(rexp, "to_str", exception_to_s, 0);
 #if defined(HAVE_RB_HASH_ASET) || defined(RUBINIUS)
 	rb_hash_aset(rjb_loaded_classes, cname, rexp);
diff --git a/test/Test.java b/test/Test.java
index ec221ba..679f163 100755
--- a/test/Test.java
+++ b/test/Test.java
@@ -126,6 +126,14 @@ public class Test {
                               u.getClass().getName() };
     }
 
+    public void causeException() {
+	try {
+	    throw new IllegalArgumentException("bad argument");
+	} catch (Exception e) {
+	    throw new IllegalStateException("outer exception", e);
+	}
+    }
+
     public String helloData = "Hello World !!";
 
     public static void main(String[] args) {
diff --git a/test/rjbtest.jar b/test/rjbtest.jar
old mode 100755
new mode 100644
index d6913bc..72f68d6
Binary files a/test/rjbtest.jar and b/test/rjbtest.jar differ
diff --git a/test/test.rb b/test/test.rb
index b563603..ed79ca1 100755
--- a/test/test.rb
+++ b/test/test.rb
@@ -810,6 +810,19 @@ class TestRjb < Test::Unit::TestCase
       end
    end
   end
+
+
+  def test_inner_exception
+    test = import('jp.co.infoseek.hp.arton.rjb.Test').new
+    begin
+      test.cause_exception
+      flunk("no exception")
+    rescue IllegalStateException => e
+      ia = e.cause
+      assert_equal('bad argument', ia.message)
+      assert_equal('java.lang.IllegalArgumentException', ia._classname)
+    end
+  end
   
   class CbTest
     def method(l, s, i, d, str)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-rjb.git



More information about the Pkg-ruby-extras-commits mailing list