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

ruby-changes:54362

From: mame <ko1@a...>
Date: Wed, 26 Dec 2018 18:04:18 +0900 (JST)
Subject: [ruby-changes:54362] mame:r66576 (trunk): object.c (rb_obj_match): use rb_warn for deprecation warning

mame	2018-12-26 18:04:12 +0900 (Wed, 26 Dec 2018)

  New Revision: 66576

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66576

  Log:
    object.c (rb_obj_match): use rb_warn for deprecation warning
    
    Now the warning is printed even without -w option.

  Modified files:
    trunk/object.c
    trunk/test/minitest/test_minitest_unit.rb
    trunk/test/ruby/test_object.rb
Index: object.c
===================================================================
--- object.c	(revision 66575)
+++ object.c	(revision 66576)
@@ -1687,8 +1687,8 @@ rb_false(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L1687
 static VALUE
 rb_obj_match(VALUE obj1, VALUE obj2)
 {
-    rb_warning("deprecated Object#=~ is called on %"PRIsVALUE
-               "; it always returns nil", rb_obj_class(obj1));
+    rb_warn("deprecated Object#=~ is called on %"PRIsVALUE
+            "; it always returns nil", rb_obj_class(obj1));
     return Qnil;
 }
 
Index: test/minitest/test_minitest_unit.rb
===================================================================
--- test/minitest/test_minitest_unit.rb	(revision 66575)
+++ test/minitest/test_minitest_unit.rb	(revision 66576)
@@ -1529,7 +1529,9 @@ class TestMiniTestUnitTestCase < MiniTes https://github.com/ruby/ruby/blob/trunk/test/minitest/test_minitest_unit.rb#L1529
   def test_refute_match_matcher_object
     @assertion_count = 2
     non_verbose do
-      @tc.refute_match Object.new, 5 # default #=~ returns false
+      obj = Object.new
+      def obj.=~(other); false; end
+      @tc.refute_match obj, 5
     end
   end
 
Index: test/ruby/test_object.rb
===================================================================
--- test/ruby/test_object.rb	(revision 66575)
+++ test/ruby/test_object.rb	(revision 66576)
@@ -946,4 +946,13 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L946
       end
     EOS
   end
+
+  def test_matcher
+    assert_warning(/deprecated Object#=~ is called on Object/) do
+      assert_equal(Object.new =~ 42, nil)
+    end
+    assert_warning(/deprecated Object#=~ is called on Array/) do
+      assert_equal([] =~ 42, nil)
+    end
+  end
 end

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

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