[Tarantool-patches] [PATCH v2 luajit 16/26] test: enable <ffi_metatype.lua> in LuaJIT-tests
Sergey Kaplun
skaplun at tarantool.org
Mon Jan 29 13:45:16 MSK 2024
This patch changes `dofile()` (which uses an unreliable relative file
path and mutates `_G` with global functions to be defined) to the
corresponding `require()` of the helper function. It adds test names and
includes the test in <index>.
Part of tarantool/tarantool#9398
---
test/LuaJIT-tests/lib/ffi/ffi_metatype.lua | 16 ++++++++--------
test/LuaJIT-tests/lib/ffi/index | 1 +
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua b/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua
index 2db717f4..b0054b1a 100644
--- a/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua
+++ b/test/LuaJIT-tests/lib/ffi/ffi_metatype.lua
@@ -1,6 +1,6 @@
local ffi = require("ffi")
-dofile("../common/ffi_util.inc")
+local fails = require("common.fails")
ffi.cdef[[
typedef struct { int x; } idx1_t;
@@ -14,7 +14,7 @@ local function ptreq(a, b)
return ffi.cast("void *", a) == ffi.cast("void *", b)
end
-do
+do --- metatype index newindex
local nidx = {}
local tp = ffi.metatype("idx1_t", {
__index = { foo = 99, method = function(c, v) return v end },
@@ -45,7 +45,7 @@ do
fails(function(cp) cp.bar = 42 end, cp)
end
-do
+do --- metatype index newindex with upvalues
local uc, uk, uv
local tp = ffi.metatype("idx2_t", {
__index = function(c, k, x, y)
@@ -78,7 +78,7 @@ do
fails(function(p) p[0] = 11 end, p)
end
-do
+do --- metatype index newindex with upvalues via setmetatable
local uc, uk, uv
local ti, tn = {}, {}
local tp = ffi.metatype("idx3_t", {
@@ -103,7 +103,7 @@ do
uc, uk, uv = nil, nil, nil
end
-do
+do --- metatype arith
local tp
tp = ffi.metatype("arith_t", {
__add = function(a, b) return tp(a.x+b.x, a.y+b.y) end,
@@ -174,7 +174,7 @@ do
assert(x == 3000)
end
-do
+do --- metatype GC
local count = 0
local tp = ffi.metatype("gc_t", {
__gc = function(x) count = count + 1 end,
@@ -206,7 +206,7 @@ do
assert(count == 103)
end
-do
+do --- metatype new, type change
local tp = ffi.metatype([[
struct {
static const int Z42 = 42;
@@ -236,7 +236,7 @@ struct {
assert(o.x == 5)
end
-do
+do --- metatype is other cdata
local fb = ffi.new("struct { int x; }", 99)
local xt = ffi.metatype("struct { }", { __index = fb })
local o = xt()
diff --git a/test/LuaJIT-tests/lib/ffi/index b/test/LuaJIT-tests/lib/ffi/index
index 833c31e3..338a6930 100644
--- a/test/LuaJIT-tests/lib/ffi/index
+++ b/test/LuaJIT-tests/lib/ffi/index
@@ -14,6 +14,7 @@ ffi_jit_arith.lua
ffi_jit_call.lua
ffi_jit_conv.lua
ffi_lex_number.lua
+ffi_metatype.lua
istype.lua
jit_array.lua
jit_complex.lua
--
2.43.0
More information about the Tarantool-patches
mailing list