[Tarantool-patches] [PATCH v2 luajit 16/45] test: enable <misc/hook_active.lua> LuaJIT test
Sergey Bronnikov
sergeyb at tarantool.org
Fri Aug 23 17:35:03 MSK 2024
Sergey,
On 21.08.2024 11:58, Sergey Kaplun wrote:
> This patch moves the aforementioned test from the <misc> to the <lang/>
> directory, includes it in <index>, names the subtests, and slightly
> reformates the code style to make it closer to ours.
>
> Part of tarantool/tarantool#9398
> ---
thanks for the patch! LGTM
> test/LuaJIT-tests/lang/hook_active.lua | 102 +++++++++++++++++++++++++
> test/LuaJIT-tests/lang/index | 1 +
> test/LuaJIT-tests/misc/hook_active.lua | 95 -----------------------
> 3 files changed, 103 insertions(+), 95 deletions(-)
> create mode 100644 test/LuaJIT-tests/lang/hook_active.lua
> delete mode 100644 test/LuaJIT-tests/misc/hook_active.lua
>
> diff --git a/test/LuaJIT-tests/lang/hook_active.lua b/test/LuaJIT-tests/lang/hook_active.lua
> new file mode 100644
> index 00000000..a5f38055
> --- /dev/null
> +++ b/test/LuaJIT-tests/lang/hook_active.lua
> @@ -0,0 +1,102 @@
> +local ctest = require("libctest")
> +
> +local called = 0
> +local function clearhook() debug.sethook(nil, "", 0) end
> +
> +do --- Return from pcall with active hook must prepend true. FF pcall.
> + called = 0
> + debug.sethook(function() called = called + 1; assert(pcall(function() end) == true); clearhook() end, "", 1)
> + do local x = 1 end
> + assert(called == 1)
> +end
> +
> +do --- Hook with special caught error must not unblock hooks. FF pcall.
> + called = 0
> + debug.sethook(function() called = called + 1; pcall(nil); clearhook() end, "", 1)
> + do local x = 1 end
> + assert(called == 1)
> +end
> +
> +do --- Hook with caught error must not unblock hooks. FF pcall.
> + called = 0
> + local function p2() error("") end
> + debug.sethook(function() called = called + 1; pcall(p2); clearhook() end, "", 1)
> + do local x = 1 end
> + assert(called == 1)
> +end
> +
> +do --- Hook with special caught error must not unblock hooks. C pcall.
> + called = 0
> + debug.sethook(function() called = called + 1; ctest.pcall(nil); clearhook() end, "", 1)
> + do local x = 1 end
> + assert(called == 1)
> +end
> +
> +do --- Hook with caught error must not unblock hooks. C pcall.
> + called = 0
> + local function p2() error("") end
> + debug.sethook(function() called = called + 1; ctest.pcall(p2); clearhook() end, "", 1)
> + do local x = 1 end
> + assert(called == 1)
> +end
> +
> +do --- Regular pcall must not block hooks.
> + debug.sethook(function() called = called + 1 end, "", 1)
> + pcall(function() end)
> + called = 0
> + do local x = 1 end
> + assert(called > 0)
> + pcall(function() error("") end)
> + called = 0
> + do local x = 1 end
> + assert(called > 0)
> + ctest.pcall(function() end)
> + called = 0
> + do local x = 1 end
> + assert(called > 0)
> + ctest.pcall(function() error("") end)
> + called = 0
> + do local x = 1 end
> + assert(called > 0)
> + clearhook()
> +end
> +
> +do --- Hook with uncaught error must unblock hooks. FF pcall.
> + called = 0
> + pcall(function()
> + debug.sethook(function()
> + local old = called
> + called = 1
> + if old == 0 then error("") end
> + end, "", 1)
> + do local x = 1 end
> + end)
> + assert(called == 1)
> + called = 2
> + do local x = 1 end
> + assert(called == 1, "hook not unblocked after uncaught error")
> + clearhook()
> + called = 2
> + do local x = 1 end
> + assert(called == 2)
> +end
> +
> +do --- Hook with uncaught error must unblock hooks. C pcall.
> + called = 0
> + ctest.pcall(function()
> + debug.sethook(function()
> + local old = called
> + called = 1
> + if old == 0 then error("") end
> + end, "", 1)
> + do local x = 1 end
> + end)
> + assert(called == 1)
> + called = 2
> + do local x = 1 end
> + assert(called == 1, "hook not unblocked after uncaught error")
> + clearhook()
> + called = 2
> + do local x = 1 end
> + assert(called == 2)
> +end
> diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index
> index 274425bf..8cecfa08 100644
> --- a/test/LuaJIT-tests/lang/index
> +++ b/test/LuaJIT-tests/lang/index
> @@ -8,6 +8,7 @@ compare_nan.lua
> constant
> dualnum.lua
> for.lua
> +hook_active.lua
> length.lua
> lightud.lua
> modulo.lua
> diff --git a/test/LuaJIT-tests/misc/hook_active.lua b/test/LuaJIT-tests/misc/hook_active.lua
> deleted file mode 100644
> index 37dfc379..00000000
> --- a/test/LuaJIT-tests/misc/hook_active.lua
> +++ /dev/null
> @@ -1,95 +0,0 @@
> -local ctest = require("ctest")
> -
> -local called = 0
> -local function clearhook() debug.sethook(nil, "", 0) end
> -
> --- Return from pcall with active hook must prepend true. FF pcall.
> -called = 0
> -debug.sethook(function() called=called+1; assert(pcall(function() end) == true); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with special caught error must not unblock hooks. FF pcall.
> -called = 0
> -debug.sethook(function() called=called+1; pcall(nil); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with caught error must not unblock hooks. FF pcall.
> -called = 0
> -local function p2() error("") end
> -debug.sethook(function() called=called+1; pcall(p2); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with special caught error must not unblock hooks. C pcall.
> -called = 0
> -debug.sethook(function() called=called+1; ctest.pcall(nil); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Hook with caught error must not unblock hooks. C pcall
> -called = 0
> -local function p2() error("") end
> -debug.sethook(function() called=called+1; ctest.pcall(p2); clearhook() end, "", 1)
> -do local x = 1 end
> -assert(called == 1)
> -
> --- Regular pcall must not block hooks.
> -debug.sethook(function() called=called+1 end, "", 1)
> -pcall(function() end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -pcall(function() error("") end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -ctest.pcall(function() end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -ctest.pcall(function() error("") end)
> -called = 0
> -do local x = 1 end
> -assert(called > 0)
> -clearhook()
> -
> --- Hook with uncaught error must unblock hooks. FF pcall
> -called = 0
> -pcall(function()
> - debug.sethook(function()
> - local old = called
> - called = 1
> - if old == 0 then error("") end
> - end, "", 1)
> - do local x = 1 end
> -end)
> -assert(called == 1)
> -called = 2
> -do local x = 1 end
> -assert(called == 1, "hook not unblocked after uncaught error")
> -clearhook()
> -called = 2
> -do local x = 1 end
> -assert(called == 2)
> -
> --- Hook with uncaught error must unblock hooks. C pcall
> -called = 0
> -ctest.pcall(function()
> - debug.sethook(function()
> - local old = called
> - called = 1
> - if old == 0 then error("") end
> - end, "", 1)
> - do local x = 1 end
> -end)
> -assert(called == 1)
> -called = 2
> -do local x = 1 end
> -assert(called == 1, "hook not unblocked after uncaught error")
> -clearhook()
> -called = 2
> -do local x = 1 end
> -assert(called == 2)
> -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20240823/d5ec1f4b/attachment.htm>
More information about the Tarantool-patches
mailing list