Sergey, On 21.08.2024 11:58, Sergey Kaplun wrote: > This patch moves the aforementioned test from the to the > directory, includes it in , names the subtests, and adjusts the > line numbers in the assertions and filters to match LuaJIT behaviour and > the new code layout. Also, it slightly refactors the code to make it > closer to our code style. > > Part of tarantool/tarantool#9398 > --- thanks for the patch! LGTM with a minor comment. > test/LuaJIT-tests/lang/hook_line.lua | 45 ++++++++++++++++++++++++++++ > test/LuaJIT-tests/lang/index | 1 + > test/LuaJIT-tests/misc/hook_line.lua | 41 ------------------------- > 3 files changed, 46 insertions(+), 41 deletions(-) > create mode 100644 test/LuaJIT-tests/lang/hook_line.lua > delete mode 100644 test/LuaJIT-tests/misc/hook_line.lua > > diff --git a/test/LuaJIT-tests/lang/hook_line.lua b/test/LuaJIT-tests/lang/hook_line.lua > new file mode 100644 > index 00000000..733e5513 > --- /dev/null > +++ b/test/LuaJIT-tests/lang/hook_line.lua > @@ -0,0 +1,45 @@ > +-- The test depends on the number of lines in the file. > +local lines = {} > +local function hook() > + lines[#lines + 1] = debug.getinfo(2).currentline > +end > + > +local function dummy() > +end -- <-- line 8 > + > +do --- Base test: cycles, function calls. > + debug.sethook(hook, "l", 0) > + -- <-- line 12 > + local x > + dummy() > + local y = 1 > + dummy() dummy() I would place a second call to a separate line. Feel free to ignore. > + local z = 2; local r = true > + while y < 4 do y = y + 1 end > + while z < 4 do > + z = z + 1 > + end > + -- <-- line 22 > + local v > + debug.sethook(nil, "", 0) > + > + assert(#lines > 0) > + while lines[1] < 12 do table.remove(lines, 1) end > + while lines[#lines] > 22 do table.remove(lines) end > + > + local s = table.concat(lines, " ") > + assert(s == "13 14 8 15 16 8 8 17 18 18 18 18 19 20 19 20 19" or > + s == "13 14 8 15 16 8 16 8 17 18 18 18 18 19 20 19 20 19") > +end > + > +do --- Not visited the end of the function definition. > + lines = {} > + local function f() > + if true then return end > + local function x() end > + end -- <-- line 40 > + debug.sethook(hook, "l", 0) > + f() > + debug.sethook(nil, "", 0) > + for i = 1, #lines do assert(lines[i] ~= 40) end > +end > diff --git a/test/LuaJIT-tests/lang/index b/test/LuaJIT-tests/lang/index > index 8cecfa08..ae59bc56 100644 > --- a/test/LuaJIT-tests/lang/index > +++ b/test/LuaJIT-tests/lang/index > @@ -9,6 +9,7 @@ constant > dualnum.lua > for.lua > hook_active.lua > +hook_line.lua > length.lua > lightud.lua > modulo.lua > diff --git a/test/LuaJIT-tests/misc/hook_line.lua b/test/LuaJIT-tests/misc/hook_line.lua > deleted file mode 100644 > index 36f71080..00000000 > --- a/test/LuaJIT-tests/misc/hook_line.lua > +++ /dev/null > @@ -1,41 +0,0 @@ > -local lines = {} > -local function hook() > - lines[#lines+1] = debug.getinfo(2).currentline > -end > - > -local function dummy() > -end -- <-- line 7 > - > -debug.sethook(hook, "l", 0) > --- <-- line 10 > -local x > -dummy() > -local y = 1 > -dummy() dummy() > -local z = 2; local r = true > -while y < 4 do y = y + 1 end > -while z < 4 do > - z = z + 1 > -end > --- <-- line 20 > -local v > -debug.sethook(nil, "", 0) > - > -assert(#lines > 0) > -while lines[1] < 10 do table.remove(lines, 1) end > -while lines[#lines] > 20 do table.remove(lines) end > - > -local s = table.concat(lines, " ") > -assert(s == "11 12 7 13 14 7 7 15 16 16 16 16 17 18 17 18 17" or > - s == "11 12 7 13 14 7 14 7 15 16 16 16 16 17 18 17 18 17") > - > -lines = {} > -local function f() > - if true then return end > - local function x() end > -end -- <-- line 36 > -debug.sethook(hook, "l", 0) > -f() > -debug.sethook(nil, "", 0) > -for i=1,#lines do assert(lines[i] ~= 36) end > -