From 15dbf758473f006a222af09a6a5d87188bc76114 Mon Sep 17 00:00:00 2001 From: Oleg Chaplashkin Date: Thu, 21 Mar 2024 14:18:01 +0400 Subject: [PATCH] Improve luatest.log function if a nil value is passed Use `select()` to avoid `bad argument to '?' (no value)` error in following example: luatest.log('%s and %s', cdata: NULL, nil) Closes #360 --- CHANGELOG.md | 1 + luatest/log.lua | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8df5a7..e9b2252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add logging to unified file (gh-324). - Add memory leak detection during server process execution (gh-349). +- Improve `luatest.log` function if a `nil` value is passed (gh-360). ## 1.0.1 diff --git a/luatest/log.lua b/luatest/log.lua index 5411ebf..f6183d2 100644 --- a/luatest/log.lua +++ b/luatest/log.lua @@ -11,9 +11,10 @@ local function _log(level, msg, ...) if not utils.version_current_ge_than(2, 5, 1) then return end - local args = {...} - for k, v in pairs(args) do - args[k] = pp.tostringlog(v) + local args = {} + for i = 1, select('#', ...) do + local v = select(i, ...) + table.insert(args, pp.tostringlog(v)) end return tarantool_log[level](msg, unpack(args)) end