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

ruby-changes:73511

From: Benoit <ko1@a...>
Date: Sat, 10 Sep 2022 20:14:30 +0900 (JST)
Subject: [ruby-changes:73511] 92b907d12d (master): Enable deprecation warnings for test-all

https://git.ruby-lang.org/ruby.git/commit/?id=92b907d12d

From 92b907d12d6de6f74f1efa6d8cd4fed8fa50763e Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Sat, 3 Sep 2022 15:47:49 +0200
Subject: Enable deprecation warnings for test-all

* So deprecated methods/constants/functions are dealt with early,
  instead of many tests breaking suddenly when removing a deprecated
  method/constant/function.
* Follows https://bugs.ruby-lang.org/issues/17591
---
 test/ruby/test_exception.rb |  2 +-
 tool/lib/test/unit.rb       | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 0b05ff7c51..f041067137 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -1053,7 +1053,7 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1053
           warning << [str, category]
         end
       else
-        define_method(:warn) do |str|
+        define_method(:warn) do |str, category: nil|
           warning << str
         end
       end
diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb
index 8cb6d8f651..b2190843c8 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -1,5 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/test/unit.rb#L1
 # frozen_string_literal: true
 
+# Enable deprecation warnings for test-all, so deprecated methods/constants/functions are dealt with early.
+Warning[:deprecated] = true
+
+if ENV['BACKTRACE_FOR_DEPRECATION_WARNINGS']
+  Warning.extend Module.new {
+    def warn(message, category: nil, **kwargs)
+      if category == :deprecated and $stderr.respond_to?(:puts)
+        $stderr.puts nil, message, caller, nil
+      else
+        super
+      end
+    end
+  }
+end
+
 require_relative '../envutil'
 require_relative '../colorize'
 require_relative '../leakchecker'
-- 
cgit v1.2.1


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

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