diff options
author | Benoit Daloze <[email protected]> | 2025-02-03 00:40:07 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-02-03 10:22:16 +0900 |
commit | 15e6f13ff7c80c42490c3004977d72d95b35bb21 (patch) | |
tree | 408b00eb967bed123fcda98ba25e11ed11314f68 /test | |
parent | b5b509766309f693f3bf0ea1e5214a1d727662ce (diff) |
[ruby/fiddle] Fix Fiddle.last_error on FFI backend and improve test
to work for all
(https://github.com/ruby/fiddle/pull/173)
https://github.com/ruby/fiddle/commit/ef2382a7ef
Diffstat (limited to 'test')
-rw-r--r-- | test/fiddle/test_function.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb index b408a14ccd..ee5fdf30fb 100644 --- a/test/fiddle/test_function.rb +++ b/test/fiddle/test_function.rb @@ -8,7 +8,7 @@ module Fiddle class TestFunction < Fiddle::TestCase def setup super - Fiddle.last_error = nil + Fiddle.last_error = 0 if WINDOWS Fiddle.win32_last_error = nil Fiddle.win32_last_socket_error = nil @@ -126,14 +126,20 @@ module Fiddle end def test_last_error - if ffi_backend? - omit("Fiddle.last_error doesn't work with FFI backend") + if RUBY_ENGINE == 'jruby' && WINDOWS + omit("Fiddle.last_error doesn't work well on JRuby on Windows") end - func = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP) + require 'rbconfig/sizeof' - assert_nil Fiddle.last_error - func.call(+"000", "123") + strtol = Function.new(@libc['strtol'], [TYPE_VOIDP, TYPE_VOIDP, TYPE_INT], TYPE_LONG) + + assert_equal 0, Fiddle.last_error + + assert_equal RbConfig::LIMITS["LONG_MAX"], strtol.call((2**128).to_s, nil, 10) # overflow + assert_equal Errno::ERANGE::Errno, Fiddle.last_error + + assert_equal 123, strtol.call("123", nil, 10) refute_nil Fiddle.last_error end |