Skip to content

Conversation

ligurio
Copy link
Owner

@ligurio ligurio commented Aug 6, 2025

No description provided.

@ligurio ligurio force-pushed the ligurio/gh-xxxx-fix-lapi-tests-2 branch from 9c77028 to 68047ba Compare August 7, 2025 08:18
@ligurio ligurio requested a review from Buristan August 7, 2025 10:01
@ligurio ligurio assigned ligurio and Buristan and unassigned ligurio Aug 7, 2025
@ligurio ligurio force-pushed the ligurio/gh-xxxx-fix-lapi-tests-2 branch from 5ac345f to 42fa96a Compare August 8, 2025 13:06
Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Sergey!
Thanks for the patchset!
I'll proceed with the review per-patch below.


[PATCH 1/7] tests/lapi: fix table_remove_test

LGTM, with a minor comment below.

Fix out-of-bound indices passed to table.remove().

Please specify the Lua version since which the behaviour has changed. For 5.1 just no value returned.

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PATCH 2/7] tests/lapi: fix string_byte_test

Thanks for the patch!
Please consider my comments below.

  • string.char() returns the internal numeric codes of the

Typo: s/char/byte/

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PATCH 3/7] tests/lapi: fix string_rep_test

LGTM.

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PATCH 4/7] tests/lapi: fix formatting
LGTM.

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PATCH 5/7] tests/lapi: cache locales in random_locale()

LGTM.

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PATCH 6/7] tests/lapi: add table.clear test

Please consider my coments below.

The patcha adds a test for table.clear() function that is

Typo: s/patcha/patch/

local fdp = luzer.FuzzedDataProvider(buf)
local count = fdp:consume_integer(0, test_lib.MAX_INT64)
local tbl = fdp:consume_strings(test_lib.MAX_STR_LEN, count)
table_clear(tbl)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to check that there are no keys in this table after clearing.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated:

--- a/tests/lapi/table_clear_test.lua                                                                                                   
+++ b/tests/lapi/table_clear_test.lua                                                                                                   
@@ -32,6 +32,12 @@ local function TestOneInput(buf)                                                                                     
     local count = fdp:consume_integer(0, test_lib.MAX_INT64)                                                                           
     local tbl = fdp:consume_strings(test_lib.MAX_STR_LEN, count)                                                                       
     table_clear(tbl)                                                                                                                   
+    -- Make sure the table is empty.                                                                                                   
+    local n_items = 0                                                                                                                  
+    for _, _ in pairs(tbl) do                                                                                                          
+        n_items = n_items + 1                                                                                                          
+    end                                                                                                                                
+    assert(n_items == 0)                                                                                                               
 end                                                                                                                                    
                                                                                                                                        
 local args = {   

Copy link
Collaborator

@Buristan Buristan Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: s/_, _/_/

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PATCH 7/7] tests/lapi: update assertions in os tests

IINM, these values are not LuaJIT-specific, so there is no need to conditionally exclude them. The Lua may be built with the LUA_USE_POSIX as well to obtain the same behaviour. Looks like this patch is unnecessary.

@Buristan Buristan assigned ligurio and unassigned Buristan Aug 22, 2025
@ligurio
Copy link
Owner Author

ligurio commented Aug 27, 2025

Added missed comments to tests:

--- a/tests/lapi/os_date_test.lua
+++ b/tests/lapi/os_date_test.lua
@@ -33,6 +33,7 @@ local function TestOneInput(buf)
     local ok, res = xpcall(os.date, err_handler, format, time)
     if not ok then return end
     local type_check = type(res) == "string" or type(res) == "table"
+    -- Undocumented.
     if test_lib.lua_version() == "LuaJIT" then
         assert(type_check or type(res) == "number" or res == nil)
     else
diff --git a/tests/lapi/os_time_test.lua b/tests/lapi/os_time_test.lua
index f8feebd..72a1483 100644
--- a/tests/lapi/os_time_test.lua
+++ b/tests/lapi/os_time_test.lua
@@ -33,6 +33,7 @@ local function TestOneInput(buf)
     local ok, res = xpcall(os.time, err_handler, time)
     if not ok then return end
     local type_check = type(res) == "number" or type(res) == "table"
+    -- Undocumented.
     if test_lib.lua_version() == "LuaJIT" then
         assert(type_check or res == nil)
     else

@ligurio
Copy link
Owner Author

ligurio commented Aug 27, 2025

Fix out-of-bound indices passed to table.remove().

Please specify the Lua version since which the behaviour has changed. For 5.1 just no value returned.

Since Lua 5.1 for non-empty tables:

$ lua5.2 -e "print(table.remove({1}, 0))"
lua5.2: (command line):1: bad argument #1 to 'remove' (position out of bounds)
stack traceback:
        [C]: in function 'remove'
        (command line):1: in main chunk
        [C]: in ?
$ lua5.3 -e "print(table.remove({1}, 0))"
lua5.3: (command line):1: bad argument #1 to 'remove' (position out of bounds)
stack traceback:
        [C]: in function 'table.remove'
        (command line):1: in main chunk
        [C]: in ?
$ lua5.4 -e "print(table.remove({1}, 0))"
lua5.4: (command line):1: bad argument #2 to 'remove' (position out of bounds)
stack traceback:
        [C]: in function 'table.remove'
        (command line):1: in main chunk
        [C]: in ?
$ lua5.4 -e "print(table.remove({}, 0))"
nil

Updated the test:

--- a/tests/lapi/table_remove_test.lua
+++ b/tests/lapi/table_remove_test.lua
@@ -20,7 +20,13 @@ local function TestOneInput(buf, _size)
     local tbl = fdp:consume_strings(test_lib.MAX_STR_LEN, count)
 
     local indices_count = fdp:consume_integer(0, #tbl)
-    local indices = fdp:consume_integers(1, count, indices_count)
+    local min_index = 0
+    -- PUC Rio Lua 5.2+ raises an error "position out of bounds"
+    -- when `pos` is equal to 0 and table is not empty.
+    if test_lib.lua_current_version_ge_than(5, 2) then
+        min_index = 1
+    end
+    local indices = fdp:consume_integers(min_index, count, indices_count)
     for _, idx in ipairs(indices) do
         local old_v = tbl[idx]
         assert(table.remove(tbl, idx) == old_v)

Fix out-of-bound indices passed to `table.remove()`.
@ligurio
Copy link
Owner Author

ligurio commented Aug 27, 2025

[PATCH 7/7] tests/lapi: update assertions in os tests

IINM, these values are not LuaJIT-specific, so there is no need to conditionally exclude them. The Lua may be built with the LUA_USE_POSIX as well to obtain the same behaviour. Looks like this patch is unnecessary.

The flag is enabled:

# `io.popen()` is not supported by default, it is enabled
# by `LUA_USE_POSIX` flag. Required by a function `random_locale()`.
set(CFLAGS "${CFLAGS} -DLUA_USE_POSIX")

@ligurio ligurio force-pushed the ligurio/gh-xxxx-fix-lapi-tests-2 branch from 42fa96a to 2e2509b Compare August 27, 2025 13:56
@Buristan
Copy link
Collaborator

IINM, these values are not LuaJIT-specific, so there is no need to conditionally exclude them. The Lua may be built with the LUA_USE_POSIX as well to obtain the same behaviour. Looks like this patch is unnecessary.

The flag is enabled:

Yes, but it makes a difference only since 5.2 IINM. For 5.4-5.3 the same time input should raise an error, for example. For 5.1-5.2 nil should be pushed as well for the non-representable input as for the LuaJIT.

@ligurio ligurio force-pushed the ligurio/gh-xxxx-fix-lapi-tests-2 branch from 2e2509b to 699b395 Compare August 27, 2025 14:20
The patch fixes the following issues:

- `string.byte()` returns the internal numeric codes of the
  characters, not a single number.
- `string.char()` returns `nil` when values `i` or `j` are
   outside the acceptable range (less than zero and greater than
   the length of the string). It is not documented.

Follows up #124
The patch fixes description (synopsis is at the end of the
description) and fixes lower boundary for `n`, with `n` equal
to zero assertion calculates negative number in right part of
expression.

Follows up #124
The patch changes function `random_locale()`, so it builds a table
with locales only once on the first execution and then returns
a cached table.
The patch adds a test for `table.clear()` function that is
present in LuaJIT. Follows up the commit ee032e7
("tests/lapi: add table tests").

Follows up #142
The patch updates assertions for values returned by `os.date()`
and `os.time()`.

Follows up #141
@ligurio ligurio force-pushed the ligurio/gh-xxxx-fix-lapi-tests-2 branch from 699b395 to 23b7403 Compare August 28, 2025 15:06
@ligurio ligurio requested a review from Buristan August 28, 2025 15:15
@ligurio ligurio assigned Buristan and unassigned ligurio Aug 28, 2025
Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sergey,
Thanks for the fixes!
LGTM, after fixing a minor comment above.

Also, don't forget to fix the last (TMP) commit.

@Buristan Buristan assigned ligurio and unassigned Buristan Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants