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

ruby-changes:73903

From: Sutou <ko1@a...>
Date: Fri, 7 Oct 2022 15:21:01 +0900 (JST)
Subject: [ruby-changes:73903] 824c474c95 (master): [ruby/fiddle] test: ensure freeing closure

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

From 824c474c95969f8255f293dc927ea081907aa0c2 Mon Sep 17 00:00:00 2001
From: Sutou Kouhei <kou@c...>
Date: Thu, 15 Sep 2022 06:44:07 +0900
Subject: [ruby/fiddle] test: ensure freeing closure

GitHub: GH-102

This also improves freed closures assertions.

https://github.com/ruby/fiddle/commit/0495624caf
---
 test/fiddle/test_function.rb | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb
index 0a1159b7bc..847df3793a 100644
--- a/test/fiddle/test_function.rb
+++ b/test/fiddle/test_function.rb
@@ -18,8 +18,11 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L18
     def teardown
       # Ensure freeing all closures.
       # See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
-      GC.start
-      assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {})
+      not_freed_closures = []
+      ObjectSpace.each_object(Fiddle::Closure) do |closure|
+        not_freed_closures << closure unless closure.freed?
+      end
+      assert_equal([], not_freed_closures)
     end
 
     def test_default_abi
@@ -82,18 +85,20 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L85
     end
 
     def test_argument_count
-      closure = Class.new(Closure) {
+      closure_class = Class.new(Closure) do
         def call one
           10 + one
         end
-      }.new(TYPE_INT, [TYPE_INT])
-      func = Function.new(closure, [TYPE_INT], TYPE_INT)
-
-      assert_raise(ArgumentError) do
-        func.call(1,2,3)
       end
-      assert_raise(ArgumentError) do
-        func.call
+      closure_class.create(TYPE_INT, [TYPE_INT]) do |closure|
+        func = Function.new(closure, [TYPE_INT], TYPE_INT)
+
+        assert_raise(ArgumentError) do
+          func.call(1,2,3)
+        end
+        assert_raise(ArgumentError) do
+          func.call
+        end
       end
     end
 
-- 
cgit v1.2.1


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

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