Skip to content

Commit 0495624

Browse files
committed
test: ensure freeing closure
GitHub: GH-102 This also improves freed closures assertions.
1 parent e122129 commit 0495624

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

test/fiddle/test_function.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ def setup
1818
def teardown
1919
# Ensure freeing all closures.
2020
# See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
21-
GC.start
22-
assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {})
21+
not_freed_closures = []
22+
ObjectSpace.each_object(Fiddle::Closure) do |closure|
23+
not_freed_closures << closure unless closure.freed?
24+
end
25+
assert_equal([], not_freed_closures)
2326
end
2427

2528
def test_default_abi
@@ -82,18 +85,20 @@ def test_call
8285
end
8386

8487
def test_argument_count
85-
closure = Class.new(Closure) {
88+
closure_class = Class.new(Closure) do
8689
def call one
8790
10 + one
8891
end
89-
}.new(TYPE_INT, [TYPE_INT])
90-
func = Function.new(closure, [TYPE_INT], TYPE_INT)
91-
92-
assert_raise(ArgumentError) do
93-
func.call(1,2,3)
9492
end
95-
assert_raise(ArgumentError) do
96-
func.call
93+
closure_class.create(TYPE_INT, [TYPE_INT]) do |closure|
94+
func = Function.new(closure, [TYPE_INT], TYPE_INT)
95+
96+
assert_raise(ArgumentError) do
97+
func.call(1,2,3)
98+
end
99+
assert_raise(ArgumentError) do
100+
func.call
101+
end
97102
end
98103
end
99104

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy