[前][次][番号順一覧][スレッド一覧]

ruby-changes:32581

From: nagachika <ko1@a...>
Date: Mon, 20 Jan 2014 02:14:07 +0900 (JST)
Subject: [ruby-changes:32581] nagachika:r44660 (ruby_2_0_0): merge revision(s) 44609, 44610, 44612, 44613, 44617:

nagachika	2014-01-20 02:14:02 +0900 (Mon, 20 Jan 2014)

  New Revision: 44660

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44660

  Log:
    merge revision(s) 44609,44610,44612,44613,44617:
    
    test_numeric.rb: coercion failures
    
    * test/ruby/test_numeric.rb (test_coerce): new assertions for
      failure of coercion.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/numeric.c
    branches/ruby_2_0_0/test/ruby/test_numeric.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/numeric.c
===================================================================
--- ruby_2_0_0/numeric.c	(revision 44659)
+++ ruby_2_0_0/numeric.c	(revision 44660)
@@ -223,17 +223,19 @@ coerce_body(VALUE *x) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L223
     return rb_funcall(x[1], id_coerce, 1, x[0]);
 }
 
+NORETURN(static void coerce_failed(VALUE x, VALUE y));
+static void
+coerce_failed(VALUE x, VALUE y)
+{
+    rb_raise(rb_eTypeError, "%"PRIsVALUE" can't be coerced into %"PRIsVALUE,
+	     (rb_special_const_p(y)? rb_inspect(y) : rb_obj_class(y)),
+	     rb_obj_class(x));
+}
+
 static VALUE
 coerce_rescue(VALUE *x)
 {
-    volatile VALUE v = rb_inspect(x[1]);
-
-    rb_raise(rb_eTypeError, "%s can't be coerced into %s",
-	     rb_special_const_p(x[1])?
-	     RSTRING_PTR(v):
-	     rb_obj_classname(x[1]),
-	     rb_obj_classname(x[0]));
-
+    coerce_failed(x[0], x[1]);
     return Qnil;		/* dummy */
 }
 
@@ -306,9 +308,9 @@ num_sadded(VALUE x, VALUE name) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L308
     /* Numerics should be values; singleton_methods should not be added to them */
     rb_remove_method_id(rb_singleton_class(x), mid);
     rb_raise(rb_eTypeError,
-	     "can't define singleton method \"%s\" for %s",
-	     rb_id2name(mid),
-	     rb_obj_classname(x));
+	     "can't define singleton method \"%"PRIsVALUE"\" for %"PRIsVALUE,
+	     rb_id2str(mid),
+	     rb_obj_class(x));
 
     UNREACHABLE;
 }
@@ -318,7 +320,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L320
 num_init_copy(VALUE x, VALUE y)
 {
     /* Numerics are immutable values, which should not be copied */
-    rb_raise(rb_eTypeError, "can't copy %s", rb_obj_classname(x));
+    rb_raise(rb_eTypeError, "can't copy %"PRIsVALUE, rb_obj_class(x));
 
     UNREACHABLE;
 }
@@ -3196,11 +3198,7 @@ bit_coerce(VALUE *x, VALUE *y, int err) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/numeric.c#L3198
 	if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM)
 	    && !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
 	    if (!err) return FALSE;
-	    rb_raise(rb_eTypeError,
-		     "%s can't be coerced into %s for bitwise arithmetic",
-		     rb_special_const_p(*y) ?
-			RSTRING_PTR(rb_inspect(*y)) : rb_obj_classname(*y),
-		     rb_obj_classname(*x));
+	    coerce_failed(*x, *y);
 	}
     }
     return TRUE;
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 44659)
+++ ruby_2_0_0/version.h	(revision 44660)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-01-20"
-#define RUBY_PATCHLEVEL 387
+#define RUBY_PATCHLEVEL 388
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 1
Index: ruby_2_0_0/test/ruby/test_numeric.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_numeric.rb	(revision 44659)
+++ ruby_2_0_0/test/ruby/test_numeric.rb	(revision 44660)
@@ -1,9 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_numeric.rb#L1
 require 'test/unit'
+require_relative 'envutil'
 
 class TestNumeric < Test::Unit::TestCase
   class DummyNumeric < Numeric
   end
 
+  def assert_raise_with_message(exc, pattern, &blk)
+    e = assert_raise(exc, &blk)
+    assert_match(pattern, e.message)
+  end
+
   def test_coerce
     a, b = 1.coerce(2)
     assert_equal(Fixnum, a.class)
@@ -14,6 +20,24 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_numeric.rb#L20
     assert_equal(Float, b.class)
 
     assert_raise(TypeError) { -Numeric.new }
+
+    assert_raise_with_message(TypeError, /can't be coerced into /) {1+:foo}
+    assert_raise_with_message(TypeError, /can't be coerced into /) {1&:foo}
+    assert_raise_with_message(TypeError, /can't be coerced into /) {1|:foo}
+    assert_raise_with_message(TypeError, /can't be coerced into /) {1^:foo}
+
+    EnvUtil.with_default_external(Encoding::UTF_8) do
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
+    end
+    EnvUtil.with_default_external(Encoding::US_ASCII) do
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
+    end
   end
 
   def test_dummynumeric
@@ -46,11 +70,20 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_numeric.rb#L70
     end
   end
 
-  def test_numeric
+  def test_singleton_method
+    a = Numeric.new
+    assert_raise_with_message(TypeError, /foo/) { def a.foo; end }
+    assert_raise_with_message(TypeError, /\u3042/) { eval("def a.\u3042; end") }
+  end
+
+  def test_dup
     a = Numeric.new
-    assert_raise(TypeError) { def a.foo; end }
-    assert_raise(TypeError) { eval("def a.\u3042; end") }
     assert_raise(TypeError) { a.dup }
+
+    c = Module.new do
+      break eval("class C\u{3042} < Numeric; self; end")
+    end
+    assert_raise_with_message(TypeError, /C\u3042/) {c.new.dup}
   end
 
   def test_quo

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44609-44610,44612-44613,44617


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]