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

ruby-changes:56715

From: Yusuke <ko1@a...>
Date: Wed, 31 Jul 2019 11:53:42 +0900 (JST)
Subject: [ruby-changes:56715] Yusuke Endoh: 816e5055c9 (master): test/ruby/test_io.rb (test_binmode_pipe): close all pipes explicitly

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

From 816e5055c90de327d99fe7f1d2cc4cfe86acd887 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Wed, 31 Jul 2019 11:52:59 +0900
Subject: test/ruby/test_io.rb (test_binmode_pipe): close all pipes explicitly

to suppress the leak checker.

diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 8c57ad3..f91b8c8 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -116,47 +116,62 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L116
   def test_binmode_pipe
     EnvUtil.with_default_internal(Encoding::UTF_8) do
       EnvUtil.with_default_external(Encoding::UTF_8) do
-        reader, writer = IO.pipe
-        reader.binmode
-        writer.binmode
-
-        reader1, writer1 = IO.pipe
-
-        reader2, writer2 = IO.pipe(binmode: true)
-        assert_predicate writer, :binmode?
-        assert_predicate writer2, :binmode?
-        assert_equal writer.binmode?, writer2.binmode?
-        assert_equal writer.external_encoding, writer2.external_encoding
-        assert_equal writer.internal_encoding, writer2.internal_encoding
-        assert_predicate reader, :binmode?
-        assert_predicate reader2, :binmode?
-        assert_equal reader.binmode?, reader2.binmode?
-        assert_equal reader.external_encoding, reader2.external_encoding
-        assert_equal reader.internal_encoding, reader2.internal_encoding
-
-        reader3, writer3 = IO.pipe("UTF-8:UTF-8", binmode: true)
-        assert_predicate writer3, :binmode?
-        assert_equal writer1.external_encoding, writer3.external_encoding
-        assert_equal writer1.internal_encoding, writer3.internal_encoding
-        assert_predicate reader3, :binmode?
-        assert_equal reader1.external_encoding, reader3.external_encoding
-        assert_equal reader1.internal_encoding, reader3.internal_encoding
-
-        reader4, writer4 = IO.pipe("UTF-8:UTF-8", binmode: true)
-        assert_predicate writer4, :binmode?
-        assert_equal writer1.external_encoding, writer4.external_encoding
-        assert_equal writer1.internal_encoding, writer4.internal_encoding
-        assert_predicate reader4, :binmode?
-        assert_equal reader1.external_encoding, reader4.external_encoding
-        assert_equal reader1.internal_encoding, reader4.internal_encoding
-
-        reader5, writer5 = IO.pipe("UTF-8", "UTF-8", binmode: true)
-        assert_predicate writer5, :binmode?
-        assert_equal writer1.external_encoding, writer5.external_encoding
-        assert_equal writer1.internal_encoding, writer5.internal_encoding
-        assert_predicate reader5, :binmode?
-        assert_equal reader1.external_encoding, reader5.external_encoding
-        assert_equal reader1.internal_encoding, reader5.internal_encoding
+        begin
+          reader, writer = IO.pipe
+          reader.binmode
+          writer.binmode
+
+          reader1, writer1 = IO.pipe
+
+          reader2, writer2 = IO.pipe(binmode: true)
+          assert_predicate writer, :binmode?
+          assert_predicate writer2, :binmode?
+          assert_equal writer.binmode?, writer2.binmode?
+          assert_equal writer.external_encoding, writer2.external_encoding
+          assert_equal writer.internal_encoding, writer2.internal_encoding
+          assert_predicate reader, :binmode?
+          assert_predicate reader2, :binmode?
+          assert_equal reader.binmode?, reader2.binmode?
+          assert_equal reader.external_encoding, reader2.external_encoding
+          assert_equal reader.internal_encoding, reader2.internal_encoding
+
+          reader3, writer3 = IO.pipe("UTF-8:UTF-8", binmode: true)
+          assert_predicate writer3, :binmode?
+          assert_equal writer1.external_encoding, writer3.external_encoding
+          assert_equal writer1.internal_encoding, writer3.internal_encoding
+          assert_predicate reader3, :binmode?
+          assert_equal reader1.external_encoding, reader3.external_encoding
+          assert_equal reader1.internal_encoding, reader3.internal_encoding
+
+          reader4, writer4 = IO.pipe("UTF-8:UTF-8", binmode: true)
+          assert_predicate writer4, :binmode?
+          assert_equal writer1.external_encoding, writer4.external_encoding
+          assert_equal writer1.internal_encoding, writer4.internal_encoding
+          assert_predicate reader4, :binmode?
+          assert_equal reader1.external_encoding, reader4.external_encoding
+          assert_equal reader1.internal_encoding, reader4.internal_encoding
+
+          reader5, writer5 = IO.pipe("UTF-8", "UTF-8", binmode: true)
+          assert_predicate writer5, :binmode?
+          assert_equal writer1.external_encoding, writer5.external_encoding
+          assert_equal writer1.internal_encoding, writer5.internal_encoding
+          assert_predicate reader5, :binmode?
+          assert_equal reader1.external_encoding, reader5.external_encoding
+          assert_equal reader1.internal_encoding, reader5.internal_encoding
+        ensure
+          reader.close if reader
+          writer.close if writer
+          reader1.close if reader1
+          writer1.close if writer1
+          reader2.close if reader2
+          writer2.close if writer2
+          reader3.close if reader3
+          writer3.close if writer3
+          reader4.close if reader4
+          writer4.close if writer4
+          reader5.close if reader5
+          writer5.close if writer5
+        end
       end
     end
   end
-- 
cgit v0.10.2


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

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