Skip to content

Commit

Permalink
test: ensure freeing closure
Browse files Browse the repository at this point in the history
GitHub: GH-102

This also improves freed closures assertions.
  • Loading branch information
kou committed Sep 14, 2022
1 parent e122129 commit 0495624
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/fiddle/test_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def setup
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
Expand Down Expand Up @@ -82,18 +85,20 @@ def test_call
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

Expand Down

0 comments on commit 0495624

Please sign in to comment.