mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/fiddle] test: ensure freeing closure
GitHub: GH-102 This also improves freed closures assertions. https://github.com/ruby/fiddle/commit/0495624caf
This commit is contained in:
parent
dfca6a8799
commit
824c474c95
1 changed files with 15 additions and 10 deletions
|
@ -18,8 +18,11 @@ module Fiddle
|
|||
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,11 +85,12 @@ module Fiddle
|
|||
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])
|
||||
end
|
||||
closure_class.create(TYPE_INT, [TYPE_INT]) do |closure|
|
||||
func = Function.new(closure, [TYPE_INT], TYPE_INT)
|
||||
|
||||
assert_raise(ArgumentError) do
|
||||
|
@ -96,6 +100,7 @@ module Fiddle
|
|||
func.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_last_error
|
||||
func = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
|
||||
|
|
Loading…
Reference in a new issue