]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Fix cffi-lua compatibility issues
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 5 Dec 2025 17:27:55 +0000 (17:27 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 5 Dec 2025 17:27:55 +0000 (17:27 +0000)
- base32: Use tostring() for size_t values in format strings
- expressions: Use %s instead of %d for float values (Lua 5.4 strict)
- fpconv: Skip variadic function tests on cffi-lua (not supported)

test/lua/unit/base32.lua
test/lua/unit/expressions.lua
test/lua/unit/fpconv.lua

index 0996f4efd03a5444a1cd2139d2c9486f7ce7476e..e6eaf7f686017c34dbfbf260f81d772efbee0279 100644 (file)
@@ -47,8 +47,9 @@ context("Base32 encodning", function()
         local nl = ffi.new("size_t [1]")
         local nb = ffi.C.rspamd_decode_base32(bs, #bs, nl, how)
 
-        assert_equal(tonumber(nl[0]), l,
-            string.format("invalid size reported: %d reported vs %d expected", tonumber(nl[0]), l))
+        local reported_len = tonumber(nl[0]) or 0
+        assert_equal(reported_len, l,
+            string.format("invalid size reported: %s reported vs %s expected", tostring(reported_len), tostring(l)))
         local cmp = ffi.C.memcmp(b, nb, l)
         ffi.C.g_free(ben)
         ffi.C.g_free(nb)
index 3d05685b076aafb231f6488956ec58939a32b7c3..3ea26275931cb858b3335c51f4c699f2676ceec0 100644 (file)
@@ -104,8 +104,8 @@ context("Rspamd expressions", function()
 
       assert_not_nil(expr, "Cannot parse " .. c[1] .. '; error: ' .. (err or 'wut??'))
       res = expr:process(atoms)
-      assert_equal(res, c[2], string.format("Processed expr '%s'{%s} returned '%d', expected: '%d'",
-          expr:to_string(), c[1], res, c[2]))
+      assert_equal(res, c[2], string.format("Processed expr '%s'{%s} returned '%s', expected: '%s'",
+          expr:to_string(), c[1], tostring(res), tostring(c[2])))
     end)
   end
 end)
index 6858b192a809af0086f1904a6277f065443a814f..ee008708e329c320b88c5e1410760d357b88ad5d 100644 (file)
@@ -2,9 +2,18 @@
 
 context("Fpconv printf functions", function()
   local ok, ffi = pcall(require, "ffi")
+  local is_luajit_ffi = ok
   if not ok then
     ffi = require("cffi")
   end
+
+  -- cffi-lua doesn't support variadic functions properly, skip these tests
+  if not is_luajit_ffi then
+    test("Skipped: cffi-lua does not support variadic functions", function()
+      -- This test suite requires LuaJIT FFI for variadic function support
+    end)
+    return
+  end
   local niter_fuzz = 100000
   local function small_double()
     return math.random()