-
Notifications
You must be signed in to change notification settings - Fork 3
Fix Lua API tests #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix Lua API tests #153
Conversation
9c77028
to
68047ba
Compare
5ac345f
to
42fa96a
Compare
There was a problem hiding this 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.
There was a problem hiding this 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/
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: s/_, _
/_
/
There was a problem hiding this 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.
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 |
Since Lua 5.1 for non-empty tables:
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()`.
The flag is enabled: lua-c-api-tests/cmake/BuildLua.cmake Lines 67 to 69 in 42ef050
|
42fa96a
to
2e2509b
Compare
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 |
2e2509b
to
699b395
Compare
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 updates assertions for values returned by `os.date()` and `os.time()`. Follows up #141
699b395
to
23b7403
Compare
There was a problem hiding this 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.
No description provided.