[Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/
Igor Munkin
imun at tarantool.org
Thu Apr 16 16:43:42 MSK 2020
Sergey,
Thanks for the patch! I left several comments and changes reducing
amount of warnings, please consider them.
On 14.04.20, Sergey Bronnikov wrote:
> Closes #4681
>
> Reviewed-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
> ---
>
> test/app-tap/console.test.lua | 4 ---
> test/app-tap/csv.test.lua | 28 +++++++++----------
> test/app-tap/logger.test.lua | 2 +-
> test/box-py/box.lua | 2 +-
> test/box-tap/gc.test.lua | 4 +--
> test/box/box.lua | 2 +-
> test/box/hash_multipart.result | 2 +-
> test/box/hash_multipart.test.lua | 2 +-
> test/box/lua/cfg_bad_vinyl_dir.lua | 2 +-
> test/box/lua/cfg_rtree.lua | 2 +-
> test/box/lua/cfg_test1.lua | 2 +-
> test/box/lua/cfg_test2.lua | 2 +-
> test/box/lua/cfg_test3.lua | 2 +-
> test/box/lua/cfg_test4.lua | 2 +-
> test/box/lua/cfg_test5.lua | 4 +--
> test/box/lua/cfg_test6.lua | 2 +-
> test/box/lua/utils.lua | 3 +-
> test/box/on_schema_init.lua | 2 +-
> test/box/proxy.lua | 2 +-
> test/box/tiny.lua | 2 +-
> test/box/tree_pk.result | 4 +--
> test/box/tree_pk.test.lua | 4 +--
> test/engine/tree_min_max_count.result | 2 +-
> test/engine/tree_min_max_count.test.lua | 2 +-
> test/replication-py/master.lua | 2 +-
> test/replication-py/panic.lua | 2 +-
> test/replication/master.lua | 2 +-
> test/replication/replicaset_ro_mostly.result | 2 +-
> .../replication/replicaset_ro_mostly.test.lua | 2 +-
> test/sql-tap/analyze3.test.lua | 6 ++--
> test/sql-tap/analyze9.test.lua | 16 +++++------
> .../gh-4077-iproto-execute-no-bind.test.lua | 7 +++--
> test/sql-tap/index1.test.lua | 1 -
> test/sql-tap/join3.test.lua | 2 +-
> test/sql-tap/select9.test.lua | 10 ++-----
> test/sql-tap/tkt-fa7bf5ec.test.lua | 6 ++--
> test/sql-tap/where2.test.lua | 2 +-
> test/sql/lua/sql_tokenizer.lua | 2 +-
> test/sql/savepoints.result | 6 ++--
> test/sql/savepoints.test.lua | 6 ++--
> test/sql/triggers.result | 2 +-
> test/sql/triggers.test.lua | 2 +-
> test/vinyl/large.lua | 3 +-
> test/vinyl/txn_proxy.lua | 6 ++--
> test/vinyl/vinyl.lua | 2 +-
> test/wal_off/rtree_benchmark.result | 2 +-
> test/wal_off/rtree_benchmark.test.lua | 2 +-
> test/xlog-py/box.lua | 2 +-
> test/xlog/panic.lua | 2 +-
> test/xlog/reader.result | 2 +-
> test/xlog/reader.test.lua | 2 +-
> test/xlog/snap_io_rate.test.lua | 2 +-
> test/xlog/transaction.result | 2 +-
> test/xlog/transaction.test.lua | 2 +-
> test/xlog/xlog.lua | 2 +-
> 55 files changed, 92 insertions(+), 102 deletions(-)
>
Fixed a single warning left in test/app-tap/cfg.test.lua:
================================================================================
diff --git a/test/app-tap/cfg.test.lua b/test/app-tap/cfg.test.lua
index ba6b735ab..14e040f9f 100755
--- a/test/app-tap/cfg.test.lua
+++ b/test/app-tap/cfg.test.lua
@@ -12,7 +12,7 @@ test:plan(11)
local nil_uuid = '00000000-0000-0000-0000-000000000000'
local ok = pcall(box.cfg, {instance_uuid = nil_uuid})
test:ok(not ok, 'nil instance UUID is not allowed')
-ok, err = pcall(box.cfg, {replicaset_uuid = nil_uuid})
+ok = pcall(box.cfg, {replicaset_uuid = nil_uuid})
test:ok(not ok, 'nil replicaset UUID is not allowed')
test:is(type(box.ctl), "table", "box.ctl is available before box.cfg")
================================================================================
Fixed all warnings in test/app-tap/clock.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/clock.test.lua b/test/app-tap/clock.test.lua
index fd1c4f272..d1ea4f0a8 100755
--- a/test/app-tap/clock.test.lua
+++ b/test/app-tap/clock.test.lua
@@ -1,7 +1,7 @@
#!/usr/bin/env tarantool
-clock = require("clock")
-test = require("tap").test("csv")
+local clock = require("clock")
+local test = require("tap").test("csv")
test:plan(10)
test:ok(clock.realtime() > 0, "realtime")
test:ok(clock.thread() > 0, "thread")
================================================================================
Fixed a simple warning in test/app-tap/console_lua.test.lua:
================================================================================
diff --git a/test/app-tap/console_lua.test.lua b/test/app-tap/console_lua.test.lua
index 3ed6aad97..24f9744bb 100755
--- a/test/app-tap/console_lua.test.lua
+++ b/test/app-tap/console_lua.test.lua
@@ -83,7 +83,7 @@ local function execute_and_verify(test, client, input, exp_output, name)
test:ok(res ~= nil, ('-> [[%s]]'):format(input))
local exp = exp_output .. EOL
- local res = client:read(EOL)
+ res = client:read(EOL)
test:is(res, exp, ('<- [[%s]]'):format(exp:gsub('\n', '\\n')))
end)
end
================================================================================
> diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua
> index 4feadfa5e..1f61ba837 100755
> --- a/test/app-tap/console.test.lua
> +++ b/test/app-tap/console.test.lua
In addition to your changes the fix below solves 98/99 remaining
warnings in this file:
================================================================================
diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua
index 1f61ba837..65cf40485 100755
--- a/test/app-tap/console.test.lua
+++ b/test/app-tap/console.test.lua
@@ -18,7 +18,8 @@ os.remove(IPROTO_SOCKET)
--
local EOL = "\n...\n"
-test = tap.test("console")
+local test = tap.test("console")
+local _
test:plan(80)
@@ -58,7 +59,8 @@ test:is(client:read(";"), 'true;', "pushed message")
client:write('\\set output lua\n')
client:read(";")
-long_func_f = nil
+local long_func_f
+-- luacheck: globals long_func (is called via client socket)
function long_func()
long_func_f = fiber.self()
box.session.push('push')
@@ -229,13 +231,13 @@ box.cfg{listen = ''}
os.remove(IPROTO_SOCKET)
local s = console.listen('127.0.0.1:0')
-addr = s:name()
+local addr = s:name()
test:is(addr.family, 'AF_INET', 'console.listen uri support')
test:is(addr.host, '127.0.0.1', 'console.listen uri support')
test:isnt(addr.port, 0, 'console.listen uri support')
s:close()
-local s = console.listen('console://unix/:'..CONSOLE_SOCKET)
+s = console.listen('console://unix/:'..CONSOLE_SOCKET)
addr = s:name()
test:is(addr.family, 'AF_UNIX', 'console.listen uri support')
test:is(addr.host, 'unix/', 'console.listen uri support')
================================================================================
<snipped>
> diff --git a/test/app-tap/csv.test.lua b/test/app-tap/csv.test.lua
> index a7f17b1ea..689db7997 100755
> --- a/test/app-tap/csv.test.lua
> +++ b/test/app-tap/csv.test.lua
In addition to your changes the fix below solves all remaining warnings
in this file:
================================================================================
diff --git a/test/app-tap/csv.test.lua b/test/app-tap/csv.test.lua
index 689db7997..b17c48664 100755
--- a/test/app-tap/csv.test.lua
+++ b/test/app-tap/csv.test.lua
@@ -35,10 +35,10 @@ local test6_ans = "|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n|none|" ..
"|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio.c.f" ..
"lag[ flag ])|\t\n||\t||\t||\t\n"
-test = tap.test("csv")
+local test = tap.test("csv")
test:plan(12)
-readable = {}
+local readable = {}
readable.read = myread
readable.v = "a,b\n1,\"ha\n\"\"ha\"\"\nha\"\n3,4\n"
readable.i = 0
@@ -52,11 +52,11 @@ readable.v = ", \r\nkp\"\"v"
readable.i = 0
test:is(table2str(csv.load(readable, {chunk_size = 3})), test3_ans, "obj test3")
-tmpdir = fio.tempdir()
-file1 = fio.pathjoin(tmpdir, 'file.1')
-file2 = fio.pathjoin(tmpdir, 'file.2')
-file3 = fio.pathjoin(tmpdir, 'file.3')
-file4 = fio.pathjoin(tmpdir, 'file.4')
+local tmpdir = fio.tempdir()
+local file1 = fio.pathjoin(tmpdir, 'file.1')
+local file2 = fio.pathjoin(tmpdir, 'file.2')
+local file3 = fio.pathjoin(tmpdir, 'file.3')
+local file4 = fio.pathjoin(tmpdir, 'file.4')
local f = fio.open(file1, { 'O_WRONLY', 'O_TRUNC', 'O_CREAT' }, tonumber('0777', 8))
f:write("123 , 5 , 92 , 0, 0\n" ..
@@ -83,12 +83,12 @@ test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2")
f:close()
f = fio.open(file2, {'O_RDONLY'})
-opts = {chunk_size = 7, skip_head_lines = 1}
+local opts = {chunk_size = 7, skip_head_lines = 1}
--7 symbols per chunk
test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3")
f:close()
-t = {
+local t = {
{'quote" d', ',and, comma', 'both " of " t,h,e,m'},
{'"""', ',","'},
{'mul\nti\nli\r\nne\n\n', 'field'},
@@ -101,7 +101,7 @@ f = require("fio").open(file3, { "O_WRONLY", "O_TRUNC" , "O_CREAT"}, 0x1FF)
csv.dump(t, {}, f)
f:close()
f = fio.open(file3, {'O_RDONLY'})
-t2 = csv.load(f, {chunk_size = 5})
+local t2 = csv.load(f, {chunk_size = 5})
f:close()
test:is(table2str(t), table2str(t2), "test roundtrip")
================================================================================
<snipped>
Fixed a couple warnings in test/app-tap/cfg.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/debug.test.lua b/test/app-tap/debug.test.lua
index 0d199e55b..184bcc904 100755
--- a/test/app-tap/debug.test.lua
+++ b/test/app-tap/debug.test.lua
@@ -44,7 +44,7 @@ print(('debug.sourcefile() => %s; %s'):format(tostring(result), tostring(err)))
assert(result == box.NULL, 'debug.sourcefile() returns box.NULL')
assert(err == nil, 'debug.sourcefile() returns no error')
-local result, err = conn:call('debug.sourcedir')
+result, err = conn:call('debug.sourcedir')
print(('debug.sourcedir() => %s; %s'):format(tostring(result), tostring(err)))
assert(result == '.', 'debug.sourcedir() returns "."')
assert(err == nil, 'debug.sourcedir() returns no error')
@@ -74,7 +74,7 @@ if not dirstat then
end
assert(dirstat:is_dir(), dirname..' must be a directory')
-local cmd = TNTBIN..' '..filename
+cmd = TNTBIN..' '..filename
print('======================================')
print('When running lua code from script file')
print('======================================')
================================================================================
Fixed all warnings in test/app-tap/fail_main.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/fail_main.test.lua b/test/app-tap/fail_main.test.lua
index f8c45bf6f..3fe0971eb 100755
--- a/test/app-tap/fail_main.test.lua
+++ b/test/app-tap/fail_main.test.lua
@@ -7,7 +7,7 @@ local tarantool_bin = arg[-1]
test:plan(1)
-function run_script(code)
+local function run_script(code)
local dir = fio.tempdir()
local script_path = fio.pathjoin(dir, 'script.lua')
local script = fio.open(script_path, {'O_CREAT', 'O_WRONLY', 'O_APPEND'},
@@ -30,7 +30,7 @@ end
-- gh-4382: an error in main script should be handled gracefully,
-- with proper logging.
--
-local code, output = run_script("error('Error in the main script')")
+local _, output = run_script("error('Error in the main script')")
test:ok(output:match("fatal error, exiting the event loop"),
"main script error is handled gracefully")
================================================================================
Fixed all warnings in test/app-tap/gh-4761-json-per-call-options.test.lua
with the diff below:
================================================================================
diff --git a/test/app-tap/gh-4761-json-per-call-options.test.lua b/test/app-tap/gh-4761-json-per-call-options.test.lua
index 1fb24744e..6dfce51fd 100755
--- a/test/app-tap/gh-4761-json-per-call-options.test.lua
+++ b/test/app-tap/gh-4761-json-per-call-options.test.lua
@@ -12,24 +12,23 @@ local tap = require('tap')
local res = tap.test('gh-4761-json-per-call-options', function(test)
test:plan(2)
+ local ok, res, exp_res
-- Preparation code: call :decode() with a custom option.
- local ok, err = pcall(json.decode, '{"foo": {"bar": 1}}',
- {decode_max_depth = 1})
+ ok = pcall(json.decode, '{"foo": {"bar": 1}}', {decode_max_depth = 1})
assert(not ok, 'expect "too many nested data structures" error')
-- Verify that the instance option remains unchanged.
- local exp_res = {foo = {bar = 1}}
- local ok, res = pcall(json.decode, '{"foo": {"bar": 1}}')
+ exp_res = {foo = {bar = 1}}
+ ok, res = pcall(json.decode, '{"foo": {"bar": 1}}')
test:is_deeply({ok, res}, {true, exp_res},
'json instance settings remain unchanged after :decode()')
-- Same check for json.encode.
local nan = 1/0
- local ok, err = pcall(json.encode, {a = nan},
- {encode_invalid_numbers = false})
+ ok = pcall(json.encode, {a = nan}, {encode_invalid_numbers = false})
assert(not ok, 'expected "number must not be NaN or Inf" error')
- local exp_res = '{"a":inf}'
- local ok, res = pcall(json.encode, {a = nan})
+ exp_res = '{"a":inf}'
+ ok, res = pcall(json.encode, {a = nan})
test:is_deeply({ok, res}, {true, exp_res},
'json instance settings remain unchanged after :encode()')
end)
================================================================================
Fixed several warnings in test/app-tap/http_client.test.lua with the
diff below:
================================================================================
diff --git a/test/app-tap/http_client.test.lua b/test/app-tap/http_client.test.lua
index b85b605cf..f5bfe9b2a 100755
--- a/test/app-tap/http_client.test.lua
+++ b/test/app-tap/http_client.test.lua
@@ -42,7 +42,7 @@ local function start_server(test, sock_family, sock_addr)
test:is(server:read("*l"), "heartbeat", "server started")
test:diag("trying to connect to %s", url)
local r
- for i=1,10 do
+ for _ = 1, 10 do
r = client.get(url, merge(opts, {timeout = 0.01}))
if r.status == 200 then
break
@@ -82,7 +82,7 @@ local function test_http_client(test, url, opts)
"content-length > 0")
test:is(client.get("http://localhost:1/").status, 595, 'cannot connect')
- local r = client.request('GET', url, nil, opts)
+ r = client.request('GET', url, nil, opts)
test:is(r.status, 200, 'request')
-- XXX: enable after resolving of gh-4180: httpc: redirects
@@ -120,7 +120,7 @@ end
--
local function test_http_client_headers_redefine(test, url, opts)
test:plan(9)
- local opts = table.deepcopy(opts)
+ opts = table.deepcopy(opts)
-- Test defaults
opts.headers = {['Connection'] = nil, ['Accept'] = nil}
local r = client.post(url, nil, opts)
@@ -132,7 +132,7 @@ local function test_http_client_headers_redefine(test, url, opts)
opts.headers={['Connection'] = 'close'}
opts.keepalive_idle = 2
opts.keepalive_interval = 1
- local r = client.get(url, opts)
+ r = client.get(url, opts)
test:is(r.status, 200, 'simple 200')
test:is(r.headers['connection'], 'close', 'Redefined Connection header')
test:is(r.headers['keep_alive'], 'timeout=2',
@@ -140,7 +140,7 @@ local function test_http_client_headers_redefine(test, url, opts)
-- Test that user-defined Connection and Acept headers
-- are used
opts.headers={['Connection'] = 'Keep-Alive', ['Accept'] = 'text/html'}
- local r = client.get(url, opts)
+ r = client.get(url, opts)
test:is(r.status, 200, 'simple 200')
test:is(r.headers['accept'], 'text/html', 'Redefined Accept header')
test:is(r.headers['connection'], 'Keep-Alive', 'Redefined Connection header')
@@ -164,7 +164,7 @@ local function test_cancel_and_errinj(test, url, opts)
local errinj = box.error.injection
errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', true)
local topts = merge(opts, {timeout = 1200})
- f = fiber.create(func, topts)
+ fiber.create(func, topts)
r = ch:get()
test:is(r.status, 200, "No hangs in errinj")
errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', false)
@@ -180,7 +180,6 @@ local function test_post_and_get(test, url, opts)
local my_body = { key = "value" }
local json_body = json.encode(my_body)
local responses = {}
- local data = {a = 'b'}
headers['Content-Type'] = 'application/json'
local fibers = 7
local ch = fiber.channel(fibers)
@@ -213,7 +212,7 @@ local function test_post_and_get(test, url, opts)
responses.absent_get = http:get(url .. 'absent', opts)
ch:put(1)
end)
- for i=1,fibers do
+ for _ = 1, fibers do
ch:get()
end
local r = responses.good_get
@@ -270,7 +269,6 @@ local function test_errors(test)
test:ok(not status and string.find(json.encode(err),
"Unsupported protocol"),
"POST: exception on bad protocol")
- local r = http:get("http://do_not_exist_8ffad33e0cb01e6a01a03d00089e71e5b2b7e9930dfcba.ru")
end
-- gh-3679 Check that opts.headers values can be strings only.
@@ -395,7 +393,7 @@ local function test_headers(test, url, opts)
test:isnil(r.headers["very_very_very_long_headers_name1"], "no long header name")
test:is(r.headers["very_very_very_long_headers_name"], "true", "truncated name")
opts["max_header_name_length"] = 64
- local r = http:get(url .. 'headers', opts)
+ r = http:get(url .. 'headers', opts)
test:is(r.headers["very_very_very_long_headers_name1"], "true", "truncated max_header_name_length")
opts["max_header_name_length"] = nil
@@ -406,13 +404,13 @@ local function test_headers(test, url, opts)
-- "${hname}: ${hvalue}" is 8192 bytes length
local hvalue = string.rep('x', MAX_HEADER_NAME - hname:len() - 2)
local headers = {[hname] = hvalue}
- local r = http:post(url, nil, merge(opts, {headers = headers}))
+ r = http:post(url, nil, merge(opts, {headers = headers}))
test:is(r.headers[hname], hvalue, '8192 bytes header: success')
-- "${hname}: ${hvalue}" is 8193 bytes length
local exp_err = 'header is too large'
- local hvalue = string.rep('x', MAX_HEADER_NAME - hname:len() - 1)
- local headers = {[hname] = hvalue}
+ hvalue = string.rep('x', MAX_HEADER_NAME - hname:len() - 1)
+ headers = {[hname] = hvalue}
local ok, err = pcall(http.post, http, url, nil,
merge(opts, {headers = headers}))
test:is_deeply({ok, tostring(err)}, {false, exp_err},
@@ -425,7 +423,6 @@ local function test_special_methods(test, url, opts)
local responses = {}
local fibers = 7
local ch = fiber.channel(fibers)
- local _
fiber.create(function()
responses.patch_data = http:patch(url, "{\"key\":\"val\"}", opts)
ch:put(1)
@@ -454,7 +451,7 @@ local function test_special_methods(test, url, opts)
responses.custom_data = http:request("CUSTOM", url, nil, opts)
ch:put(1)
end)
- for i = 1, fibers do
+ for _ = 1, fibers do
ch:get()
end
@@ -483,10 +480,6 @@ end
local function test_concurrent(test, url, opts)
test:plan(3)
- local http = client.new()
- local headers = { my_header = "1", my_header2 = "2" }
- local my_body = { key = "value" }
- local json_body = json.encode(my_body)
local num_test = 10
local num_load = 10
local curls = { }
@@ -497,7 +490,7 @@ local function test_concurrent(test, url, opts)
headers["My-header" .. i] = "my-value"
end
- for i = 1, num_test do
+ for _ = 1, num_test do
table.insert(curls, {
url = url,
http = client.new(),
@@ -515,7 +508,7 @@ local function test_concurrent(test, url, opts)
-- Creating concurrent clients
for i=1,num_test do
local obj = curls[i]
- for j=1,num_load do
+ for _ = 1, num_load do
fiber.create(function()
local r = obj.http:post(obj.url, obj.body, merge(opts, {
headers = obj.headers,
@@ -540,13 +533,11 @@ local function test_concurrent(test, url, opts)
end
local ok_sockets_added = true
local ok_active = true
- local ok_timeout = true
local ok_req = true
-- Join test
local rest = num_test
while true do
- local ticks = 0
for i = 1, num_load do
local obj = curls[i]
-- checking that stats in concurrent are ok
@@ -582,7 +573,7 @@ local function test_concurrent(test, url, opts)
test:ok(ok_active, "no active requests")
end
-function run_tests(test, sock_family, sock_addr)
+local function run_tests(test, sock_family, sock_addr)
test:plan(11)
local server, url, opts = start_server(test, sock_family, sock_addr)
test:test("http.client", test_http_client, url, opts)
================================================================================
Fixed all warnings in test/app-tap/iconv.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/iconv.test.lua b/test/app-tap/iconv.test.lua
index 6f6a04b14..b4e8e7339 100755
--- a/test/app-tap/iconv.test.lua
+++ b/test/app-tap/iconv.test.lua
@@ -3,7 +3,7 @@
local tap = require('tap')
local iconv = require('iconv')
-test = tap.test("iconv")
+local test = tap.test("iconv")
test:plan(11)
local simple_str = 'ascii string'
@@ -34,7 +34,7 @@ test:is(c8_1251(c1251_16(c16_16be(c16be_8(cyrillic_str)))), cyrillic_str,
'complex multi-format conversion')
-- test huge string
-huge_str = string.rep(cyrillic_str, 50)
+local huge_str = string.rep(cyrillic_str, 50)
test:is(c16be_8(c8_16be(huge_str)), huge_str, "huge string")
@@ -42,7 +42,7 @@ local stat, err = pcall(iconv.new, 'NOT EXISTS', 'UTF-8')
test:is(stat, false, 'error was thrown on bad encoding')
test:ok(err:match('Invalid') ~= nil, 'correct error')
-local stat, err = pcall(c_ascii_8, cyrillic_str)
+stat, err = pcall(c_ascii_8, cyrillic_str)
test:is(stat, false, 'error was thrown on sequence')
test:ok(err:match('Incomplete multibyte sequence') ~= nil, 'correct error')
================================================================================
Fixed all warnings in test/app-tap/init_script.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/init_script.test.lua b/test/app-tap/init_script.test.lua
index 155f149a7..5831ffa77 100755
--- a/test/app-tap/init_script.test.lua
+++ b/test/app-tap/init_script.test.lua
@@ -9,14 +9,14 @@ box.cfg{
log="tarantool.log"
}
-yaml = require('yaml')
-fiber = require('fiber')
+local yaml = require('yaml')
+local fiber = require('fiber')
if box.space.tweedledum ~= nil then
box.space.space1:drop()
end
-space = box.schema.space.create('tweedledum')
+local space = box.schema.space.create('tweedledum')
space:create_index('primary', { type = 'hash' })
print[[
@@ -24,7 +24,7 @@ print[[
-- Access to box.cfg from init script
--
]]
-t = {}
+local t = {}
for k,v in pairs(box.cfg) do
if k == 'listen' then
@@ -44,7 +44,7 @@ local function do_insert()
space:insert{1, 2, 4, 8}
end
-fiber1 = fiber.create(do_insert)
+fiber.create(do_insert)
print[[
--
@@ -71,12 +71,12 @@ print[[
-- Check that require function(math.floor) reachable in the init script
--
]]
-floor = require("math").floor
+local floor = require("math").floor
print(floor(0.5))
print(floor(0.9))
print(floor(1.1))
-mod = require('require_mod')
+local mod = require('require_mod')
print(mod.test(10, 15))
--
-- A test case for https://github.com/tarantool/tarantool/issues/53
================================================================================
Fixed all warnings in test/app-tap/inspector.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/inspector.test.lua b/test/app-tap/inspector.test.lua
index ed10020a2..cda3eda2c 100755
--- a/test/app-tap/inspector.test.lua
+++ b/test/app-tap/inspector.test.lua
@@ -1,9 +1,6 @@
#!/usr/bin/env tarantool
-local socket = require('socket')
-
-test_run = require('test_run')
-inspector = test_run.new()
+local inspector = require('test_run').new()
print('create instance')
print(inspector:cmd("create server replica with rpl_master=default, script='box/box.lua'\n"))
================================================================================
Fixed a single warning in test/app-tap/json.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/json.test.lua b/test/app-tap/json.test.lua
index fadfc74ec..186d6ad46 100755
--- a/test/app-tap/json.test.lua
+++ b/test/app-tap/json.test.lua
@@ -2,7 +2,6 @@
package.path = "lua/?.lua;"..package.path
-local ffi = require('ffi')
local tap = require('tap')
local common = require('serializer_test')
================================================================================
> diff --git a/test/app-tap/logger.test.lua b/test/app-tap/logger.test.lua
> index 492d5ea0b..6ec85d0e0 100755
> --- a/test/app-tap/logger.test.lua
> +++ b/test/app-tap/logger.test.lua
<snipped>
In addition to your changes the fix below solves several remaining
warnings in this file:
================================================================================
diff --git a/test/app-tap/logger.test.lua b/test/app-tap/logger.test.lua
index 6ec85d0e0..8f43b1fb3 100755
--- a/test/app-tap/logger.test.lua
+++ b/test/app-tap/logger.test.lua
@@ -26,7 +26,7 @@ end
log.info(message)
local line = file:read()
test:is(line:sub(-message:len()), message, "message")
-s, err = pcall(json.decode, line)
+local s = pcall(json.decode, line)
test:ok(not s, "plain")
--
-- gh-700: Crash on calling log.info() with formatting characters
@@ -45,7 +45,7 @@ test:is(file:read():match('I>%s+(.*)'), '{"key":"value"}', "table is handled as
log.info({message="value"})
test:is(file:read():match('I>%s+(.*)'), '{"message":"value"}', "table is handled as json")
-function help() log.info("gh-2340: %s %s", 'help') end
+local function help() log.info("gh-2340: %s %s", 'help') end
xpcall(help, function(err)
test:ok(err:match("bad argument #3"), "found error string")
@@ -56,14 +56,14 @@ file:close()
test:ok(log.pid() >= 0, "pid()")
--- logger uses 'debug', try to set it to nil
+-- luacheck: ignore (logger uses 'debug', try to set it to nil)
local debug = nil
log.info("debug is nil")
debug = require('debug')
test:ok(log.info(true) == nil, 'check tarantool crash (gh-2516)')
-s, err = pcall(box.cfg, {log_format='json', log="syslog:identity:tarantool"})
+s = pcall(box.cfg, {log_format='json', log="syslog:identity:tarantool"})
test:ok(not s, "check json not in syslog")
box.cfg{log=filename,
================================================================================
Fixed all warnings in test/app-tap/minimal.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/minimal.test.lua b/test/app-tap/minimal.test.lua
index e44a0f6a7..8b261a03e 100755
--- a/test/app-tap/minimal.test.lua
+++ b/test/app-tap/minimal.test.lua
@@ -24,13 +24,13 @@ os.execute("tarantool ./script-args.lua 1 2 3")
--
-- LUA_PATH and LUA_CPATH argument handling
--
-local script = io.open('script-path.lua', 'w')
+script = io.open('script-path.lua', 'w')
script:write([[
print(package.path)
os.exit(0)
]])
script:close()
-local script = io.open('script-cpath.lua', 'w')
+script = io.open('script-cpath.lua', 'w')
script:write([[
print(package.cpath)
os.exit(0)
================================================================================
Fixed all warnings in test/app-tap/module_api.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index a6658cc61..d7be56a9b 100755
--- a/test/app-tap/module_api.test.lua
+++ b/test/app-tap/module_api.test.lua
@@ -5,7 +5,7 @@ local fio = require('fio')
box.cfg{log = "tarantool.log"}
-- Use BUILDDIR passed from test-run or cwd when run w/o
-- test-run to find test/app-tap/module_api.{so,dylib}.
-build_path = os.getenv("BUILDDIR") or '.'
+local build_path = os.getenv("BUILDDIR") or '.'
package.cpath = fio.pathjoin(build_path, 'test/app-tap/?.so' ) .. ';' ..
fio.pathjoin(build_path, 'test/app-tap/?.dylib') .. ';' ..
package.cpath
@@ -17,10 +17,10 @@ local function test_pushcdata(test, module)
local gc_counter = 0;
local ct = ffi.typeof('struct module_api_test')
ffi.metatype(ct, {
- __tostring = function(obj)
+ __tostring = function()
return 'ok'
end;
- __gc = function(obj)
+ __gc = function()
gc_counter = gc_counter + 1;
end
})
@@ -33,7 +33,7 @@ local function test_pushcdata(test, module)
test:is(ctid, ctid2, 'checkcdata type')
test:is(ptr, ptr2, 'checkcdata value')
test:is(gc_counter, 0, 'pushcdata gc')
- obj = nil
+ obj = nil -- luacheck: ignore
collectgarbage('collect')
test:is(gc_counter, 1, 'pushcdata gc')
end
@@ -116,7 +116,7 @@ local function test_iscallable(test, module)
end
end
-local test = require('tap').test("module_api", function(test)
+require('tap').test("module_api", function(test)
test:plan(24)
local status, module = pcall(require, 'module_api')
test:is(status, true, "module")
@@ -138,7 +138,7 @@ local test = require('tap').test("module_api", function(test)
end
end
- local status, msg = pcall(module.check_error)
+ local _, msg = pcall(module.check_error)
test:like(msg, 'luaT_error', 'luaT_error')
test:test("pushcdata", test_pushcdata, module)
================================================================================
Fixed all warnings in test/app-tap/msgpackffi.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/msgpackffi.test.lua b/test/app-tap/msgpackffi.test.lua
index 0ee5f5edc..058b74f3d 100755
--- a/test/app-tap/msgpackffi.test.lua
+++ b/test/app-tap/msgpackffi.test.lua
@@ -4,7 +4,6 @@ package.path = "lua/?.lua;"..package.path
local tap = require('tap')
local common = require('serializer_test')
-local ffi = require('ffi')
local function is_map(s)
local b = string.byte(string.sub(s, 1, 1))
@@ -76,7 +75,7 @@ local function test_other(test, s)
--
local function check_depth(depth_to_try)
local t = nil
- for i = 1, depth_to_try do t = {t} end
+ for _ = 1, depth_to_try do t = {t} end
t = s.decode_unchecked(s.encode(t))
local level = 0
while t ~= nil do level = level + 1 t = t[1] end
================================================================================
Fixed all warnings in test/app-tap/pcall.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/pcall.test.lua b/test/app-tap/pcall.test.lua
index 30163a41a..3ae16c8aa 100755
--- a/test/app-tap/pcall.test.lua
+++ b/test/app-tap/pcall.test.lua
@@ -12,7 +12,7 @@ box.cfg{
log="tarantool.log",
memtx_memory=107374182,
}
-function pcalltest()
+local function pcalltest()
local ERRMSG = "module 'some_invalid_module' not found"
local status, msg = pcall(require, 'some_invalid_module')
if status == false and msg ~= nil and msg:match(ERRMSG) ~= nil then
@@ -27,10 +27,10 @@ local status, msg = xpcall(pcalltest, function(msg)
end)
print('pcall inside xpcall:', status, msg)
-local status, msg = pcall(function() error('some message') end)
+status, msg = pcall(function() error('some message') end)
print('pcall with Lua error():', status, msg:match('some message'))
-local status, msg = pcall(function()
+status, msg = pcall(function()
box.error(box.error.ILLEGAL_PARAMS, 'some message')
end)
print('pcall with box.error():', status, msg)
================================================================================
Fixed all warnings in test/app-tap/snapshot.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/snapshot.test.lua b/test/app-tap/snapshot.test.lua
index 587f8279b..6cae662c6 100755
--- a/test/app-tap/snapshot.test.lua
+++ b/test/app-tap/snapshot.test.lua
@@ -3,7 +3,6 @@
local math = require('math')
local fiber = require('fiber')
local tap = require('tap')
-local ffi = require('ffi')
local fio = require('fio')
box.cfg{ log="tarantool.log", memtx_memory=107374182}
@@ -75,18 +74,18 @@ snap_chan:get()
test:ok(true, 'gh-695: avoid overwriting tuple data necessary for smfree()')
-------------------------------------------------------------------------------
--- gh-1185: Crash in matras_touch in snapshot_daemon.test
+-- gh-1185: Crash in matras_touch in snapshot_daemon.test
-------------------------------------------------------------------------------
local s1 = box.schema.create_space('test1', { engine = 'memtx'})
-local i1 = s1:create_index('test', { type = 'tree', parts = {1, 'unsigned'} })
+s1:create_index('test', { type = 'tree', parts = {1, 'unsigned'} })
local s2 = box.schema.create_space('test2', { engine = 'memtx'})
-local i2 = s2:create_index('test', { type = 'tree', parts = {1, 'unsigned'} })
+s2:create_index('test', { type = 'tree', parts = {1, 'unsigned'} })
for i = 1,1000 do s1:insert{i, i, i} end
-local snap_chan = fiber.channel()
+snap_chan = fiber.channel()
fiber.create(function () box.snapshot() snap_chan:put(true) end)
fiber.sleep(0)
@@ -126,11 +125,11 @@ local function gh1094()
break
end
end
- local sf, mf = pcall(box.snapshot)
- for i, f in pairs(files) do
+ local sf = pcall(box.snapshot)
+ for _, f in pairs(files) do
f:close()
end
- local ss, ms = pcall(box.snapshot)
+ local ss = pcall(box.snapshot)
test:ok(not sf and ss, msg)
end
gh1094()
@@ -141,7 +140,7 @@ box.snapshot()
box.snapshot()
box.snapshot()
test:ok(true, 'No crash for second snapshot w/o any changes')
-files = fio.glob(box.cfg.memtx_dir .. '/*.snap')
+local files = fio.glob(box.cfg.memtx_dir .. '/*.snap')
table.sort(files)
fio.unlink(files[#files])
box.snapshot()
================================================================================
Fixed several warnings in test/app-tap/string.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/string.test.lua b/test/app-tap/string.test.lua
index 02a1a84d7..431e96899 100755
--- a/test/app-tap/string.test.lua
+++ b/test/app-tap/string.test.lua
@@ -127,9 +127,9 @@ test:test("fromhex", function(test)
local _, err = pcall(string.fromhex, "aaa")
test:ok(err and err:match("(even amount of chars expected," ..
" got odd amount)"))
- local _, err = pcall(string.fromhex, "qq")
+ _, err = pcall(string.fromhex, "qq")
test:ok(err and err:match("(hex string expected, got non hex chars)"))
- local _, err = pcall(string.fromhex, 795)
+ _, err = pcall(string.fromhex, 795)
test:ok(err and err:match("(string expected, got number)"))
end)
@@ -216,10 +216,9 @@ test:test("unicode", function(test)
test:is(s, lower_res, 'default locale lower')
test:is(utf8.upper(''), '', 'empty string upper')
test:is(utf8.lower(''), '', 'empty string lower')
- local err
- s, err = pcall(utf8.upper, true)
+ local _, err = pcall(utf8.upper, true)
test:isnt(err:find('Usage'), nil, 'upper usage is checked')
- s, err = pcall(utf8.lower, true)
+ _, err = pcall(utf8.lower, true)
test:isnt(err:find('Usage'), nil, 'lower usage is checked')
test:is(utf8.isupper('a'), false, 'isupper("a")')
@@ -247,9 +246,9 @@ test:test("unicode", function(test)
test:isnil(c, 'middle of symbol offset is error')
test:is(err, 4, 'error on 4 byte')
test:is(utf8.len(s, 5), 4, 'start 5')
- c, err = utf8.len(s, 6)
+ _, err = utf8.len(s, 6)
test:is(err, 6, 'error on 6 byte')
- c, err = utf8.len(s, 0)
+ _, err = utf8.len(s, 0)
test:is(err, 'position is out of string', 'range is out of string')
test:is(utf8.len(s, #s), 1, 'start from the end')
test:is(utf8.len(s, #s + 1), 0, 'position is out of string')
@@ -262,14 +261,14 @@ test:test("unicode", function(test)
test:is(utf8.len(s, 1, -7), 4, 'end -7')
test:is(utf8.len(s, 2, -7), 3, '[2, -7]')
test:is(utf8.len(s, 3, -7), 2, '[3, -7]')
- c, err = utf8.len(s, 4, -7)
+ _, err = utf8.len(s, 4, -7)
test:is(err, 4, '[4, -7] is error - start from the middle of symbol')
test:is(utf8.len(s, 10, -100), 0, 'it is ok to be out of str by end pos')
test:is(utf8.len(s, 10, -10), 0, 'it is ok to swap end and start pos')
test:is(utf8.len(''), 0, 'empty len')
test:is(utf8.len(s, -6, -1), 3, 'pass both negative offsets')
test:is(utf8.len(s, 3, 3), 1, "end in the middle on the same symbol as start")
- c, err = utf8.len('a\xF4')
+ _, err = utf8.len('a\xF4')
test:is(err, 2, "invalid unicode in the middle of the string")
local chars = {}
@@ -279,11 +278,11 @@ test:test("unicode", function(test)
table.insert(codes, code)
end
test:is(table.concat(chars), s, "next and char works")
- c, err = pcall(utf8.char, 'kek')
+ _, err = pcall(utf8.char, 'kek')
test:isnt(err:find('bad argument'), nil, 'char usage is checked')
- c, err = pcall(utf8.next, true)
+ _, err = pcall(utf8.next, true)
test:isnt(err:find('Usage'), nil, 'next usage is checked')
- c, err = pcall(utf8.next, '1234', true)
+ _, err = pcall(utf8.next, '1234', true)
test:isnt(err:find('bad argument'), nil, 'next usage is checked')
local offset
offset, c = utf8.next('')
@@ -338,15 +337,15 @@ test:test("unicode", function(test)
test:is(utf8.sub(s, -2, 2), '', 'sub [-2:2]')
test:is(utf8.sub(s, -1, 8), '8', 'sub [-1:8]')
- c, err = pcall(utf8.sub)
+ _, err = pcall(utf8.sub)
test:isnt(err:find('Usage'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, true)
+ _, err = pcall(utf8.sub, true)
test:isnt(err:find('Usage'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, '123')
+ _, err = pcall(utf8.sub, '123')
test:isnt(err:find('Usage'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, '123', true)
+ _, err = pcall(utf8.sub, '123', true)
test:isnt(err:find('bad argument'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, '123', 1, true)
+ _, err = pcall(utf8.sub, '123', 1, true)
test:isnt(err:find('bad argument'), nil, 'usage is checked')
local s1 = '☢'
================================================================================
Fixed several warnings in test/app-tap/table.test.lua with the diff
below:
================================================================================
diff --git a/test/app-tap/table.test.lua b/test/app-tap/table.test.lua
index 60c095fdf..7279b07ed 100755
--- a/test/app-tap/table.test.lua
+++ b/test/app-tap/table.test.lua
@@ -145,7 +145,7 @@ end
do -- check usage of __copy metamethod
local copy_mt = nil; copy_mt = {
- __copy = function(self)
+ __copy = function()
local new_self = { a = 1}
return setmetatable(new_self, copy_mt)
end
@@ -164,7 +164,7 @@ end
do -- check usage of __copy metamethod + shallow
local copy_mt = nil; copy_mt = {
- __copy = function(self)
+ __copy = function()
local new_self = { a = 1}
return setmetatable(new_self, copy_mt)
end
@@ -191,7 +191,7 @@ end
do -- check usage of not __copy metamethod on second level + shallow
local copy_mt = nil; copy_mt = {
- __copy = function(self)
+ __copy = function()
local new_self = { a = 1 }
return setmetatable(new_self, copy_mt)
end
================================================================================
Fixed 53/57 warnings in test/app-tap/tap.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/tap.test.lua b/test/app-tap/tap.test.lua
index e2a78f630..0e184782a 100755
--- a/test/app-tap/tap.test.lua
+++ b/test/app-tap/tap.test.lua
@@ -11,7 +11,7 @@ local tap = require "tap"
--
-- Create a root test
--
-test = tap.test("root test")
+local test = tap.test("root test")
-- Disable stack traces for this test because Tarantool test system also
-- checks test output.
test.trace = false
@@ -88,7 +88,7 @@ end)
--
-- Subtest without callbacks.
--
-sub2 = test:test("subtest 2")
+local sub2 = test:test("subtest 2")
sub2:plan(1)
sub2:ok(true, 'true in subtest')
sub2:diag('hello from subtest')
================================================================================
Fixed 23/35 warnings (including one suppressed semantic error!) in
test/app-tap/tarantoolctl.test.lua with the diff below (there are more
fixed with the Vlad's patch in his reply):
================================================================================
diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua
index 4d7059559..f5638d330 100755
--- a/test/app-tap/tarantoolctl.test.lua
+++ b/test/app-tap/tarantoolctl.test.lua
@@ -4,7 +4,6 @@ local ffi = require('ffi')
local fio = require('fio')
local tap = require('tap')
local uuid = require('uuid')
-local yaml = require('yaml')
local errno = require('errno')
local fiber = require('fiber')
local ok, test_run = pcall(require, 'test_run')
@@ -33,7 +32,7 @@ local function recursive_rmdir(path)
end
end
if fio.rmdir(path) == false then
- print(string.format('!!! failed to rmdir path "%s"', file))
+ print(string.format('!!! failed to rmdir path "%s"', path))
print(string.format('!!! [errno %s]: %s', errno(), errno.strerror()))
end
end
@@ -51,7 +50,7 @@ int execvp(const char *file, char *const argv[]);
]]
-- background checks
-tctlcfg_code = [[default_cfg = {
+local tctlcfg_code = [[default_cfg = {
pid_file = '.', wal_dir = '.', memtx_dir = '.' ,
vinyl_dir = '.', log = '.', background = true,
}
@@ -124,8 +123,7 @@ local function tctl_wait_stop(dir, name)
end
end
-local function tctl_command(dir, cmd, args, name)
- local pid = nil
+local function tctl_command(dir, cmd, args)
if not fio.stat(fio.pathjoin(dir, '.tarantoolctl')) then
create_script(dir, '.tarantoolctl', tctlcfg_code)
end
@@ -224,7 +222,7 @@ do
-- bad code
local code = [[ box.cfg{ ]]
create_script(dir, 'bad_script.lua', code)
- local code = [[ box.cfg{memtx_memory = 104857600} ]]
+ code = [[ box.cfg{memtx_memory = 104857600} ]]
create_script(dir, 'good_script.lua', code)
local status, err = pcall(function()
@@ -258,9 +256,9 @@ do
-- bad code
local code = [[ error('help'); return 1]]
create_script(dir, 'bad_script.lua', code)
- local code = [[ return 1]]
+ code = [[ return 1]]
create_script(dir, 'ok_script.lua', code)
- local code = [[ box.cfg{memtx_memory = 104857600} box.once('help', function() end)]]
+ code = [[ box.cfg{memtx_memory = 104857600} box.once('help', function() end)]]
create_script(dir, 'good_script.lua', code)
local status, err = pcall(function()
@@ -330,7 +328,7 @@ do
local function test_help(test, dir, cmd, e_stderr)
local desc = dir and 'with config' or 'without config'
dir = dir or './'
- local res, stdout, stderr = run_command(dir, cmd)
+ local _, _, stderr = run_command(dir, cmd)
if e_stderr ~= nil then
if not test:ok(stderr:find(e_stderr), ("check stderr of '%s' %s"):format(cmd, desc)) then
print(("Expected to find '%s' in '%s'"):format(e_stderr, stderr))
@@ -385,7 +383,7 @@ do
local command_base = 'tarantoolctl cat filler/00000000000000000000.xlog'
local desc = args and "cat + " .. args or "cat"
args = args and " " .. args or ""
- local res, stdout, stderr = run_command(dir, command_base .. args)
+ local res, stdout = run_command(dir, command_base .. args)
test:is(res, 0, desc .. " result")
test:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count")
end
@@ -394,7 +392,7 @@ do
local command_base = 'tarantoolctl cat filler/00000000000000000000.snap'
local desc = args and "cat + " .. args or "cat"
args = args and " " .. args or ""
- local res, stdout, stderr = run_command(dir, command_base .. args)
+ local res, stdout = run_command(dir, command_base .. args)
test:is(res, 0, desc .. " result")
test:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count")
end
@@ -413,6 +411,7 @@ do
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system", "\n", 3)
check_ctlcat_xlog(test_i, dir, "--from=6 --to=3 --format=json --show-system", "\n", 0)
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1", "\n", 3)
+ -- luacheck: ignore (it's more convenient to not breaking the line).
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1 --replica 2", "\n", 3)
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 2", "\n", 0)
check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 25)
@@ -478,10 +477,10 @@ else
check_ok(test_i, dir, 'start', 'filler', 0)
local lsn_before = test_run:get_lsn("remote", 1)
test_i:is(lsn_before, 4, "check lsn before")
- local res, stdout, stderr = run_command(dir, command_base)
+ local res = run_command(dir, command_base)
test_i:is(res, 0, "execution result")
test_i:is(test_run:get_lsn("remote", 1), 10, "check lsn after")
- local res, stdout, stderr = run_command(dir, command_base)
+ res = run_command(dir, command_base)
test_i:is(res, 0, "execution result")
test_i:is(test_run:get_lsn("remote", 1), 16, "check lsn after")
end)
@@ -621,7 +620,7 @@ test:test('filter_xlog', function(test)
local tarantoolctl = dofile(TARANTOOLCTL_PATH)
-- Like xlog.pairs().
- local function gen(param, lsn)
+ local function gen(param)
local row = param.data[param.idx]
if row == nil then
return
================================================================================
Fixed 6/8 warnings in test/app-tap/trigger.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/trigger.test.lua b/test/app-tap/trigger.test.lua
index a31d45e5f..6cf3fbe53 100755
--- a/test/app-tap/trigger.test.lua
+++ b/test/app-tap/trigger.test.lua
@@ -45,7 +45,7 @@ test:test("simple trigger test", function(test)
-- Check that we've failed to delete trigger
- local stat, err = pcall(getmetatable(trigger_list).__call, trigger_list,
+ local _, err = pcall(getmetatable(trigger_list).__call, trigger_list,
nil, trigger_cnt)
test:ok(string.find(err, "is not found"), "check error")
end)
@@ -69,18 +69,18 @@ test:test("errored trigger test", function(test)
test:is(cnt, 1, "check simple trigger")
-- Append errored trigger
trigger_list(trigger_errored)
- local status = pcall(function() trigger_list:run() end)
+ pcall(function() trigger_list:run() end)
test:is(cnt, 2, "check simple+error trigger")
-- Flush triggers
table_clear(trigger_list)
test:is(#trigger_list(), 0, "successfull flush")
-- Append first trigger
trigger_list(trigger_errored)
- local status = pcall(function() trigger_list:run() end)
+ pcall(function() trigger_list:run() end)
test:is(cnt, 2, "check error trigger")
-- Append errored trigger
trigger_list(trigger_cnt)
- local status = pcall(function() trigger_list:run() end)
+ pcall(function() trigger_list:run() end)
test:is(cnt, 2, "check error+simple trigger")
end)
================================================================================
Fixed all warnings in test/app-tap/yaml.test.lua with the diff below:
================================================================================
diff --git a/test/app-tap/yaml.test.lua b/test/app-tap/yaml.test.lua
index 4669b6102..82fcb90c0 100755
--- a/test/app-tap/yaml.test.lua
+++ b/test/app-tap/yaml.test.lua
@@ -37,8 +37,6 @@ local function test_compact(test, s)
"---\n- {'k': 'v'}\n...\n", "flow map")
test:is(getmetatable(ss.decode(ss.encode({k = 'v'}))).__serialize, "map",
"decoded __serialize is map")
-
- ss = nil
end
local function test_output(test, s)
@@ -83,11 +81,11 @@ local function test_tagged(test, s)
-- Test encoding tags.
--
local prefix = 'tag:tarantool.io/push,2018'
- local ok, err = pcall(s.encode, 200, {tag_handle = true, tag_prefix = 100})
+ local _, err = pcall(s.encode, 200, {tag_handle = true, tag_prefix = 100})
test:isnt(err:find('Usage'), nil, "encode usage")
- ok, err = pcall(s.encode, 100, {tag_handle = 'handle'})
+ _, err = pcall(s.encode, 100, {tag_handle = 'handle'})
test:isnt(err:find('Usage'), nil, "encode usage, no prefix")
- ok, err = pcall(s.encode, 100, {tag_prefix = 'prefix'})
+ _, err = pcall(s.encode, 100, {tag_prefix = 'prefix'})
test:isnt(err:find('Usage'), nil, "encode usage, no handle")
local ret
ret, err = s.encode(300, {tag_handle = '!push', tag_prefix = prefix})
@@ -100,11 +98,12 @@ local function test_tagged(test, s)
--
-- Test decoding tags.
--
- ok, err = pcall(s.decode)
+ _, err = pcall(s.decode)
test:isnt(err:find('Usage'), nil, "decode usage")
- ok, err = pcall(s.decode, false)
+ _, err = pcall(s.decode, false)
test:isnt(err:find('Usage'), nil, "decode usage")
- local handle, prefix = s.decode(ret, {tag_only = true})
+ local handle
+ handle, prefix = s.decode(ret, {tag_only = true})
test:is(handle, "!print!", "handle is decoded ok")
test:is(prefix, "tag:tarantool.io/push,2018", "prefix is decoded ok")
local several_tags =
@@ -114,6 +113,7 @@ local function test_tagged(test, s)
- 100
...
]]
+ local ok
ok, err = s.decode(several_tags, {tag_only = true})
test:is(ok, nil, "can not decode multiple tags")
test:is(err, "can not decode multiple tags", "same")
================================================================================
OK, here are some stats before and after my changes applied on this
patch:
| State | Before | After* |
|-------|------------|------------|
| Codes | 50 (W111) | |
| | 10 (W112) | |
| | 472 (W113) | 103 (W113) |
| | 70 (W143) | 70 (W143) |
| | 37 (W211) | 1 (W211) |
| | 7 (W212) | |
| | 7 (W213) | |
| | 1 (W231) | |
| | 22 (W311) | |
| | 47 (W411) | 1 (W411) |
| | 3 (W412) | 1 (W412) |
| | 2 (W421) | 2 (W421) |
| | 1 (W422) | 1 (W422) |
| | 32 (W431) | 32 (W431) |
| | 6 (W432) | 6 (W432) |
| | 1 (W511) | |
| | 1 (W614) | |
| | 1 (W631) | |
|-------|------------|------------|
| Total | 770 / 0 | 217 / 0 |
*In addition to the changes I set <box>, <utf>, <jit> as globals.
I can agree with the fact that *not all* changes need to be applied, but
there are definitely useful and trivial ones above and I see no reasons
to omit and suppress the corresponding warnings.
Considering the results it looks like we can fix other sources with this
approach to reduce the amout of warnings to be suppressed by
.luacheckrc.
>
<snipped>
> diff --git a/test/box/tree_pk.result b/test/box/tree_pk.result
> index df3c78bed..f2a4f5352 100644
> --- a/test/box/tree_pk.result
> +++ b/test/box/tree_pk.result
> @@ -153,8 +153,8 @@ test_run:cmd("setopt delimiter ';'")
> ...
> function crossjoin(space0, space1, limit)
> local result = {}
> - for state, v0 in space0:pairs() do
> - for state, v1 in space1:pairs() do
> + for _, v0 in space0:pairs() do
> + for _, v1 in space1:pairs() do
> if limit <= 0 then
> return result
> end
> diff --git a/test/box/tree_pk.test.lua b/test/box/tree_pk.test.lua
> index 1190ab424..86041a642 100644
> --- a/test/box/tree_pk.test.lua
> +++ b/test/box/tree_pk.test.lua
> @@ -58,8 +58,8 @@ test_run = env.new()
> test_run:cmd("setopt delimiter ';'")
> function crossjoin(space0, space1, limit)
> local result = {}
> - for state, v0 in space0:pairs() do
> - for state, v1 in space1:pairs() do
> + for _, v0 in space0:pairs() do
> + for _, v1 in space1:pairs() do
> if limit <= 0 then
> return result
> end
OK, we already discussed it in brief, but let's point it one more time:
diff based tests (and especially the corresponding results) *are not Lua
sources* but console input and output. Thereby these chunks *don't need
to be checked* via luacheckrc. It might be useful to write a separate
checker, but I see no benefits to it (since AFAIR we're going to reduce
the amount of diff-based patches, but I might be wrong).
<snipped>
> --
> 2.23.0
>
>
> --
> sergeyb@
--
Best regards,
IM
More information about the Tarantool-patches
mailing list