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

ruby-changes:63134

From: Yusuke <ko1@a...>
Date: Fri, 25 Sep 2020 23:48:11 +0900 (JST)
Subject: [ruby-changes:63134] abdd3c5616 (master): test/ruby/test_enumerator.rb: check the deprecation warning

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

From abdd3c5616e82af487249ef5e9d3e42bc983de1c Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 25 Sep 2020 23:45:42 +0900
Subject: test/ruby/test_enumerator.rb: check the deprecation warning

by explicitly setting `Warning[:deprecated] = true`.
I removed "capture_io" at 79063d8cbfb7ce4740774289252a2a20dc9a5dc1, but
it printed the warning when `RUBYOPT=-w`.

This change makes the warnings enabled explicitly, capture and check the
warning.

diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 8544c42..5b634ef 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -69,7 +69,15 @@ class TestEnumerator < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enumerator.rb#L69
 
   def test_initialize
     assert_equal([1, 2, 3], @obj.to_enum(:foo, 1, 2, 3).to_a)
-    assert_equal([1, 2, 3], Enumerator.new(@obj, :foo, 1, 2, 3).to_a)
+    begin
+      deprecated_bak, Warning[:deprecated] = Warning[:deprecated], true
+      _, err = capture_io do
+        assert_equal([1, 2, 3], Enumerator.new(@obj, :foo, 1, 2, 3).to_a)
+      end
+      assert_match 'Enumerator.new without a block is deprecated', err
+    ensure
+      Warning[:deprecated] = deprecated_bak
+    end
     assert_equal([1, 2, 3], Enumerator.new { |y| i = 0; loop { y << (i += 1) } }.take(3))
     assert_raise(ArgumentError) { Enumerator.new }
 
-- 
cgit v0.10.2


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

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