[Tarantool-patches] [PATCH luajit 16/36] test: enable <misc/hook_top.lua> LuaJIT test

Sergey Kaplun skaplun at tarantool.org
Wed Aug 14 16:55:58 MSK 2024


This patch moves the aforementioned test from the <misc> to the <lang/>
directory, includes it in <index>, and names the subtests.

Part of tarantool/tarantool#9398
---
 test/LuaJIT-tests/lang/hook_top.lua | 59 +++++++++++++++++++++++++++++
 test/LuaJIT-tests/lang/index        |  1 +
 test/LuaJIT-tests/misc/hook_top.lua | 55 ---------------------------
 3 files changed, 60 insertions(+), 55 deletions(-)
 create mode 100644 test/LuaJIT-tests/lang/hook_top.lua
 delete mode 100644 test/LuaJIT-tests/misc/hook_top.lua

diff --git a/test/LuaJIT-tests/lang/hook_top.lua b/test/LuaJIT-tests/lang/hook_top.lua
new file mode 100644
index 00000000..4cab2559
--- /dev/null
+++ b/test/LuaJIT-tests/lang/hook_top.lua
@@ -0,0 +1,59 @@
+local t = {}
+for i = 1, 26 do t[i] = string.char(96 + i) end
+
+local function tcheck(t1, t2)
+  assert(#t1 == #t2)
+  for i = 1, #t1 do assert(t1[i] == t2[i]) end
+end
+
+local function foo1(...) -- VARG RETM
+  return ...
+end
+
+local function foo2(...) -- VARG UCLO RETM
+  local function dummy() end
+  return ...
+end
+
+local function foo3(...) -- VARG UCLO -> RETM
+  do return ... end
+  local function dummy() end
+end
+
+local function foo4() -- UCLO UCLO RET
+  do
+    local x
+    local function dummy() return x end
+  end
+end
+
+local function foo5(a)
+  assert(a == "bar")
+end
+
+do --- Run hook on each bytecode instruction.
+  local called = false
+  debug.sethook(function() local x = "wrong"; called = true end, "", 1)
+  tcheck(t, {foo1(unpack(t))}) -- CALLM TSETM
+  assert(called)
+  called = false
+  tcheck(t, {foo2(unpack(t))})
+  assert(called)
+  called = false
+  tcheck(t, {foo3(unpack(t))})
+  assert(called)
+  called = false
+  foo4()
+  assert(called)
+  debug.sethook(nil)
+end
+
+do --- Set local variable given to a function inside the hook.
+  debug.sethook(function()
+    local name, val = debug.getlocal(2, 1)
+    assert(name == "a" and val == nil)
+    debug.setlocal(2, 1, "bar")
+    debug.sethook(nil)
+  end, "c")
+  foo5()
+end
diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
index ae59bc56..327b40fe 100644
--- a/test/LuaJIT-tests/lang/index
+++ b/test/LuaJIT-tests/lang/index
@@ -10,6 +10,7 @@ dualnum.lua
 for.lua
 hook_active.lua
 hook_line.lua
+hook_top.lua
 length.lua
 lightud.lua
 modulo.lua
diff --git a/test/LuaJIT-tests/misc/hook_top.lua b/test/LuaJIT-tests/misc/hook_top.lua
deleted file mode 100644
index f809fcea..00000000
--- a/test/LuaJIT-tests/misc/hook_top.lua
+++ /dev/null
@@ -1,55 +0,0 @@
-
-local t = {}
-for i=1,26 do t[i] = string.char(96+i) end
-
-local function tcheck(t1, t2)
-  assert(#t1 == #t2)
-  for i=1,#t1 do assert(t1[i] == t2[i]) end
-end
-
-local function foo1(...) -- VARG RETM
-  return ...
-end
-
-local function foo2(...) -- VARG UCLO RETM
-  local function dummy() end
-  return ...
-end
-
-local function foo3(...) -- VARG UCLO -> RETM
-  do return ... end
-  local function dummy() end
-end
-
-local function foo4() -- UCLO UCLO RET
-  do
-    local x
-    local function dummy() return x end
-  end
-end
-
-called = false
-debug.sethook(function() local x = "wrong"; called = true end, "", 1)
-tcheck(t, {foo1(unpack(t))}) -- CALLM TSETM
-assert(called)
-called = false
-tcheck(t, {foo2(unpack(t))})
-assert(called)
-called = false
-tcheck(t, {foo2(unpack(t))})
-assert(called)
-called = false
-foo4()
-assert(called)
-
-debug.sethook(function()
-  local name, val = debug.getlocal(2, 1)
-  assert(name == "a" and val == nil)
-  debug.setlocal(2, 1, "bar")
-  debug.sethook(nil)
-end, "c")
-local function foo5(a)
-  assert(a == "bar")
-end
-foo5()
-
-- 
2.45.2



More information about the Tarantool-patches mailing list