[Tarantool-patches] [PATCH 01/19] Fix luacheck warnings in test/app-tap
sergeyb at tarantool.org
sergeyb at tarantool.org
Thu Jul 16 17:11:20 MSK 2020
From: Sergey Bronnikov <sergeyb at tarantool.org>
Part of #4681
Reviewed-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Reviewed-by: Igor Munkin <imun at tarantool.org>
Co-authored-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Co-authored-by: Igor Munkin <imun at tarantool.org>
---
.luacheckrc | 26 +-
test/app-tap/cfg.test.lua | 2 +-
test/app-tap/clock.test.lua | 4 +-
test/app-tap/console.test.lua | 14 +-
test/app-tap/console_lua.test.lua | 18 +-
test/app-tap/csv.test.lua | 56 +-
test/app-tap/debug.test.lua | 10 +-
test/app-tap/errno.test.lua | 24 +-
test/app-tap/fail_main.test.lua | 6 +-
.../gh-4761-json-per-call-options.test.lua | 11 +-
test/app-tap/http_client.test.lua | 297 +++++------
test/app-tap/iconv.test.lua | 6 +-
test/app-tap/init_script.test.lua | 16 +-
test/app-tap/inspector.test.lua | 5 +-
test/app-tap/json.test.lua | 1 -
test/app-tap/logger.test.lua | 23 +-
test/app-tap/lua/serializer_test.lua | 46 +-
test/app-tap/minimal.test.lua | 4 +-
test/app-tap/module_api.test.lua | 12 +-
test/app-tap/msgpackffi.test.lua | 3 +-
test/app-tap/pcall.test.lua | 6 +-
test/app-tap/popen.test.lua | 35 +-
test/app-tap/snapshot.test.lua | 17 +-
test/app-tap/string.test.lua | 502 +++++++++---------
test/app-tap/tap.test.lua | 26 +-
test/app-tap/tarantoolctl.test.lua | 82 ++-
test/app-tap/trigger.test.lua | 48 +-
test/app-tap/yaml.test.lua | 16 +-
28 files changed, 653 insertions(+), 663 deletions(-)
diff --git a/.luacheckrc b/.luacheckrc
index 994d29956..4055b0994 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -3,6 +3,8 @@ globals = {"box", "_TARANTOOL", "tonumber64"}
ignore = {
-- Accessing an undefined field of a global variable <debug>.
"143/debug",
+ -- Accessing an undefined field of a global variable <os>.
+ "143/os",
-- Accessing an undefined field of a global variable <string>.
"143/string",
-- Accessing an undefined field of a global variable <table>.
@@ -31,7 +33,23 @@ exclude_files = {
-- Third-party source code.
"src/box/lua/serpent.lua",
"test-run/**/*.lua",
- "test/**/*.lua",
+ "test/app/**/*.lua",
+ "test/box/**/*.lua",
+ "test/box-py/**/*.lua",
+ "test/box-tap/**/*.lua",
+ "test/engine/**/*.lua",
+ "test/engine_long/*.lua",
+ "test/long_run-py/**/*.lua",
+ "test/replication/**/*.lua",
+ "test/replication-py/**/*.lua",
+ "test/sql-tap/**/*.lua",
+ "test/sql/**/*.lua",
+ "test/swim/**/*.lua",
+ "test/var/**/*.lua",
+ "test/vinyl/**/*.lua",
+ "test/wal_off/*.lua",
+ "test/xlog/**/*.lua",
+ "test/xlog-py/**/*.lua",
"third_party/**/*.lua",
".rocks/**/*.lua",
".git/**/*.lua",
@@ -57,3 +75,9 @@ files["src/box/lua/console.lua"] = {
"212",
}
}
+files["test/app-tap/lua/require_mod.lua"] = {
+ globals = {"exports"}
+}
+files["test/app-tap/string.test.lua"] = {
+ globals = {"utf8"}
+}
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")
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")
diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua
index d5452aa17..0d8cc917a 100755
--- a/test/app-tap/console.test.lua
+++ b/test/app-tap/console.test.lua
@@ -5,7 +5,6 @@ local console = require('console')
local socket = require('socket')
local yaml = require('yaml')
local fiber = require('fiber')
-local ffi = require('ffi')
local log = require('log')
local fio = require('fio')
@@ -19,7 +18,8 @@ os.remove(IPROTO_SOCKET)
--
local EOL = "\n...\n"
-test = tap.test("console")
+local test = tap.test("console")
+local _
test:plan(78)
@@ -59,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 = nil
+-- luacheck: globals long_func (is called via client socket)
function long_func()
long_func_f = fiber.self()
box.session.push('push')
@@ -87,12 +88,9 @@ test:is(#client:read(EOL) > 0, true, "_G")
client:write("require('fiber').id()\n")
local fid1 = yaml.decode(client:read(EOL))[1]
local state = fiber.find(fid1).storage.console
-local server_info = state.client:peer()
local client_info = state.client:name()
test:is(client_info.host, client_info.host, "state.socker:peer().host")
test:is(client_info.port, client_info.port, "state.socker:peer().port")
-server_info = nil
-client_info = nil
-- Check console.delimiter()
client:write("require('console').delimiter(';')\n")
@@ -225,14 +223,14 @@ 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)
-addr = s:name()
+local addr = s:name()
test:is(addr.family, 'AF_UNIX', 'console.listen uri support')
test:is(addr.host, 'unix/', 'console.listen uri support')
test:is(addr.port, CONSOLE_SOCKET, 'console.listen uri support')
diff --git a/test/app-tap/console_lua.test.lua b/test/app-tap/console_lua.test.lua
index dbfc3da11..b18cb7724 100755
--- a/test/app-tap/console_lua.test.lua
+++ b/test/app-tap/console_lua.test.lua
@@ -57,8 +57,8 @@ end
--
-- Execute a list of statements, show requests and responses.
-local function execute_statements(test, client, statements, name)
- test:test(name, function(test)
+local function execute_statements(testcase, client, statements, name)
+ testcase:test(name, function(test)
test:plan(2 * #statements)
for _, stmt in ipairs(statements) do
@@ -75,8 +75,8 @@ end
--
-- Execute a statement and verify its response.
-local function execute_and_verify(test, client, input, exp_output, name)
- test:test(name, function(test)
+local function execute_and_verify(testcase, client, input, exp_output, name)
+ testcase:test(name, function(test)
test:plan(2)
local res = client:write(input .. '\n')
@@ -149,15 +149,15 @@ test:plan(#cases)
local server, client = start_console()
for _, case in ipairs(cases) do
- test:test(case.name, function(test)
- test:plan(3)
+ test:test(case.name, function(testcase)
+ testcase:plan(3)
- execute_statements(test, client, totable(case.prepare), 'prepare')
+ execute_statements(testcase, client, totable(case.prepare), 'prepare')
set_lua_output(client, case.opts)
- execute_and_verify(test, client, case.input, case.expected, 'run')
+ execute_and_verify(testcase, client, case.input, case.expected, 'run')
- execute_statements(test, client, totable(case.cleanup), 'cleanup')
+ execute_statements(testcase, client, totable(case.cleanup), 'cleanup')
end)
end
diff --git a/test/app-tap/csv.test.lua b/test/app-tap/csv.test.lua
index a7f17b1ea..eb180f95d 100755
--- a/test/app-tap/csv.test.lua
+++ b/test/app-tap/csv.test.lua
@@ -2,9 +2,9 @@
local function table2str(t)
local res = ""
- for k, line in pairs(t) do
+ for _, line in pairs(t) do
local s = ""
- for k2, field in pairs(line) do
+ for _, field in pairs(line) do
s = s .. '|' .. field .. '|\t'
end
res = res .. s .. '\n'
@@ -12,9 +12,9 @@ local function table2str(t)
return res
end
-local function myread(self, bytes)
+local function myread(self, bytes)
self.i = self.i + bytes
- return self.v:sub(self.i - bytes + 1, self.i)
+ return self.v:sub(self.i - bytes + 1, self.i)
end
local csv = require('csv')
local fio = require('fio')
@@ -27,18 +27,18 @@ local test4_ans = '|123|\t|5|\t|92|\t|0|\t|0|\t\n|1|\t|12 34|\t|56|\t' ..
local test5_ans = "|1|\t\n|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n" ..
"|none|\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f" ..
"3|\t|0|\t\n|local res = internal.pwrite(self.fh|\t|dat" ..
- "a|\t|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio." ..
+ "a|\t|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio." ..
"c.flag[ flag ])|\t\n||\t||\t||\t\n"
local test6_ans = "|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n|none|" ..
- "\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f3|\t|" ..
+ "\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f3|\t|" ..
"0|\t\n|local res = internal.pwrite(self.fh|\t|data|\t" ..
"|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,17 +52,17 @@ 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" ..
"1, 12 34, 56, \"quote , \", 66\nok")
f:close()
-f = fio.open(file1, {'O_RDONLY'})
+f = fio.open(file1, {'O_RDONLY'})
test:is(table2str(csv.load(f, {chunk_size = 10})), test4_ans, "fio test1")
f:close()
@@ -77,31 +77,31 @@ f:write("1\n23,456,abcac,\'multiword field 4\'\n" ..
",,"
)
f:close()
-f = fio.open(file2, {'O_RDONLY'})
+f = fio.open(file2, {'O_RDONLY'})
--symbol by symbol reading
-test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2")
+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}
+f = fio.open(file2, {'O_RDONLY'})
+local opts = {chunk_size = 7, skip_head_lines = 1}
--7 symbols per chunk
-test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3")
+test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3")
f:close()
-t = {
- {'quote" d', ',and, comma', 'both " of " t,h,e,m'},
- {'"""', ',","'},
- {'mul\nti\nli\r\nne\n\n', 'field'},
- {""},
- {'"'},
- {"\n"}
+local t = {
+ {'quote" d', ',and, comma', 'both " of " t,h,e,m'},
+ {'"""', ',","'},
+ {'mul\nti\nli\r\nne\n\n', 'field'},
+ {""},
+ {'"'},
+ {"\n"}
}
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})
+f = fio.open(file3, {'O_RDONLY'})
+local t2 = csv.load(f, {chunk_size = 5})
f:close()
test:is(table2str(t), table2str(t2), "test roundtrip")
diff --git a/test/app-tap/debug.test.lua b/test/app-tap/debug.test.lua
index 0d199e55b..0f9b881f0 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')
@@ -58,10 +58,10 @@ print('When running lua code from console')
print('==================================')
-- debug.sourcefile() returns cwd when running within console
for _, test in ipairs(tests) do
- local cmd = string.format('%s -e "%s; os.exit(0)"', TNTBIN, test)
- print('Exec: '..cmd)
+ local cmdline = string.format('%s -e "%s; os.exit(0)"', TNTBIN, test)
+ print('Exec: '..cmdline)
io.flush()
- assert(os.execute(cmd) == 0, string.format('cmd: "%s" must execute successfully', cmd))
+ assert(os.execute(cmdline) == 0, string.format('cmd: "%s" must execute successfully', cmdline))
end
local fio = require('fio')
@@ -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('======================================')
diff --git a/test/app-tap/errno.test.lua b/test/app-tap/errno.test.lua
index 5fd8eaca4..41f8c7d15 100755
--- a/test/app-tap/errno.test.lua
+++ b/test/app-tap/errno.test.lua
@@ -6,16 +6,16 @@ local errno = require('errno')
local test = tap.test("errno")
test:plan(1)
-test:test("primary", function(test)
- test:plan(10)
- test:is(type(errno), "table", "type of table")
- test:ok(errno.EINVAL ~= nil, "errno.EINVAL is available")
- test:ok(errno.EBADF ~= nil , "errno.EBADF is available" )
- test:ok(errno(0) ~= nil, "errno set to 0")
- test:is(errno(errno.EBADF), 0, "setting errno.EBADF")
- test:is(errno(), errno.EBADF, "checking errno.EBADF")
- test:is(errno(errno.EINVAL), errno.EBADF, "setting errno.EINVAL")
- test:is(errno(), errno.EINVAL, "checking errno.EINVAL")
- test:is(errno.strerror(), "Invalid argument", "checking strerror without argument")
- test:is(errno.strerror(errno.EBADF), "Bad file descriptor", "checking strerror with argument")
+test:test("primary", function(testcase)
+ testcase:plan(10)
+ testcase:is(type(errno), "table", "type of table")
+ testcase:ok(errno.EINVAL ~= nil, "errno.EINVAL is available")
+ testcase:ok(errno.EBADF ~= nil , "errno.EBADF is available" )
+ testcase:ok(errno(0) ~= nil, "errno set to 0")
+ testcase:is(errno(errno.EBADF), 0, "setting errno.EBADF")
+ testcase:is(errno(), errno.EBADF, "checking errno.EBADF")
+ testcase:is(errno(errno.EINVAL), errno.EBADF, "setting errno.EINVAL")
+ testcase:is(errno(), errno.EINVAL, "checking errno.EINVAL")
+ testcase:is(errno.strerror(), "Invalid argument", "checking strerror without argument")
+ testcase:is(errno.strerror(errno.EBADF), "Bad file descriptor", "checking strerror with argument")
end)
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'},
@@ -16,7 +16,7 @@ function run_script(code)
script:close()
local output_file = fio.pathjoin(fio.cwd(), 'out.txt')
local cmd = [[/bin/sh -c 'cd "%s" && "%s" ./script.lua 0> %s 2> %s']]
- local code = os.execute(
+ code = os.execute(
string.format(cmd, dir, tarantool_bin, output_file, output_file)
)
fio.rmtree(dir)
@@ -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")
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..bd710b76f 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
@@ -13,23 +13,24 @@ local res = tap.test('gh-4761-json-per-call-options', function(test)
test:plan(2)
-- Preparation code: call :decode() with a custom option.
- local ok, err = pcall(json.decode, '{"foo": {"bar": 1}}',
+ local 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}}')
+ local res
+ 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},
+ 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)
diff --git a/test/app-tap/http_client.test.lua b/test/app-tap/http_client.test.lua
index b85b605cf..b44876b39 100755
--- a/test/app-tap/http_client.test.lua
+++ b/test/app-tap/http_client.test.lua
@@ -22,8 +22,8 @@ local function merge(...)
return res
end
-local function start_server(test, sock_family, sock_addr)
- test:diag("starting HTTP server on %s...", sock_addr)
+local function start_server(testcase, sock_family, sock_addr)
+ testcase:diag("starting HTTP server on %s...", sock_addr)
local arg, url, opts
if sock_family == 'AF_INET' then
arg = string.format("--inet %s", sock_addr)
@@ -39,51 +39,51 @@ local function start_server(test, sock_family, sock_addr)
local cmd = string.format("%s/test/app-tap/httpd.py %s",
TARANTOOL_SRC_DIR, arg)
local server = io.popen(cmd)
- test:is(server:read("*l"), "heartbeat", "server started")
- test:diag("trying to connect to %s", url)
+ testcase:is(server:read("*l"), "heartbeat", "server started")
+ testcase: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
end
fiber.sleep(0.01)
end
- test:is(r.status, 200, "connection is ok")
+ testcase:is(r.status, 200, "connection is ok")
if r.status ~= 200 then
os.exit(1)
end
return server, url, opts
end
-local function stop_server(test, server)
- test:diag("stopping HTTP server")
+local function stop_server(testcase, server)
+ testcase:diag("stopping HTTP server")
server:close()
end
-local function test_http_client(test, url, opts)
- test:plan(11)
+local function test_http_client(testcase, url, opts)
+ testcase:plan(11)
-- gh-4136: confusing httpc usage error message
local ok, err = pcall(client.request, client)
local usage_err = "request(method, url[, body, [options]])"
- test:is_deeply({ok, err:split(': ')[2]}, {false, usage_err},
+ testcase:is_deeply({ok, err:split(': ')[2]}, {false, usage_err},
"test httpc usage error")
- test:isnil(rawget(_G, 'http'), "global namespace is not polluted");
- test:isnil(rawget(_G, 'http.client'), "global namespace is not polluted");
+ testcase:isnil(rawget(_G, 'http'), "global namespace is not polluted");
+ testcase:isnil(rawget(_G, 'http.client'), "global namespace is not polluted");
local r = client.get(url, opts)
- test:is(r.status, 200, 'simple 200')
- test:is(r.reason, 'Ok', '200 - Ok')
- test:is(r.proto[1], 1, 'proto major http 1.1')
- test:is(r.proto[2], 1, 'proto major http 1.1')
- test:ok(r.body:match("hello") ~= nil, "body")
- test:ok(tonumber(r.headers["content-length"]) > 0,
+ testcase:is(r.status, 200, 'simple 200')
+ testcase:is(r.reason, 'Ok', '200 - Ok')
+ testcase:is(r.proto[1], 1, 'proto major http 1.1')
+ testcase:is(r.proto[2], 1, 'proto major http 1.1')
+ testcase:ok(r.body:match("hello") ~= nil, "body")
+ testcase:ok(tonumber(r.headers["content-length"]) > 0,
"content-length > 0")
- test:is(client.get("http://localhost:1/").status, 595, 'cannot connect')
+ testcase:is(client.get("http://localhost:1/").status, 595, 'cannot connect')
- local r = client.request('GET', url, nil, opts)
- test:is(r.status, 200, 'request')
+ r = client.request('GET', url, nil, opts)
+ testcase:is(r.status, 200, 'request')
-- XXX: enable after resolving of gh-4180: httpc: redirects
-- are broken with libcurl-7.30 and older
@@ -118,36 +118,36 @@ end
-- gh-3955: Check that httpc module doesn't redefine http headers
-- set explicitly by the caller.
--
-local function test_http_client_headers_redefine(test, url, opts)
- test:plan(9)
- local opts = table.deepcopy(opts)
+local function test_http_client_headers_redefine(testcase, url, opts)
+ testcase:plan(9)
+ opts = table.deepcopy(opts)
-- Test defaults
opts.headers = {['Connection'] = nil, ['Accept'] = nil}
local r = client.post(url, nil, opts)
- test:is(r.status, 200, 'simple 200')
- test:is(r.headers['connection'], 'close', 'Default Connection header')
- test:is(r.headers['accept'], '*/*', 'Default Accept header for POST request')
+ testcase:is(r.status, 200, 'simple 200')
+ testcase:is(r.headers['connection'], 'close', 'Default Connection header')
+ testcase:is(r.headers['accept'], '*/*', 'Default Accept header for POST request')
-- Test that in case of conflicting headers, user variant is
-- prefered
opts.headers={['Connection'] = 'close'}
opts.keepalive_idle = 2
opts.keepalive_interval = 1
- local 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',
+ r = client.get(url, opts)
+ testcase:is(r.status, 200, 'simple 200')
+ testcase:is(r.headers['connection'], 'close', 'Redefined Connection header')
+ testcase:is(r.headers['keep_alive'], 'timeout=2',
'Automatically set Keep-Alive header')
-- Test that user-defined Connection and Acept headers
-- are used
opts.headers={['Connection'] = 'Keep-Alive', ['Accept'] = 'text/html'}
- local 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')
+ r = client.get(url, opts)
+ testcase:is(r.status, 200, 'simple 200')
+ testcase:is(r.headers['accept'], 'text/html', 'Redefined Accept header')
+ testcase:is(r.headers['connection'], 'Keep-Alive', 'Redefined Connection header')
end
-local function test_cancel_and_errinj(test, url, opts)
- test:plan(3)
+local function test_cancel_and_errinj(testcase, url, opts)
+ testcase:plan(3)
local ch = fiber.channel(1)
local http = client:new()
local func = function(fopts)
@@ -156,31 +156,30 @@ local function test_cancel_and_errinj(test, url, opts)
local f = fiber.create(func, opts)
f:cancel()
local r = ch:get()
- test:ok(r.status == 408 and string.find(r.reason, "Timeout"),
+ testcase:ok(r.status == 408 and string.find(r.reason, "Timeout"),
"After cancel fiber timeout is returned")
r = http:get(url, merge(opts, {timeout = 0.0001}))
- test:ok(r.status == 408 and string.find(r.reason, "Timeout"),
+ testcase:ok(r.status == 408 and string.find(r.reason, "Timeout"),
"Timeout check")
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")
+ testcase:is(r.status, 200, "No hangs in errinj")
errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', false)
end
-local function test_post_and_get(test, url, opts)
- test:plan(21)
+local function test_post_and_get(testcase, url, opts)
+ testcase:plan(21)
local http = client.new()
- test:ok(http ~= nil, "client is created")
+ testcase:ok(http ~= nil, "client is created")
local headers = { header1 = "1", header2 = "2" }
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,70 +212,69 @@ 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
- test:is(r.status, 200, "GET: default http code page exists")
- test:is(r.body, "hello world", "GET: default right body")
+ testcase:is(r.status, 200, "GET: default http code page exists")
+ testcase:is(r.body, "hello world", "GET: default right body")
r = responses.get2
- test:is(r.status, 200, "GET: http code page exists")
- test:is(r.body, "abc", "GET: right body")
+ testcase:is(r.status, 200, "GET: http code page exists")
+ testcase:is(r.body, "abc", "GET: right body")
r = responses.absent_get
- test:is(r.status, 500, "GET: absent method http code page exists")
- test:is(r.reason, 'Unknown', '500 - Unknown')
- test:is(r.body, "No such method", "GET: absent method right body")
+ testcase:is(r.status, 500, "GET: absent method http code page exists")
+ testcase:is(r.reason, 'Unknown', '500 - Unknown')
+ testcase:is(r.body, "No such method", "GET: absent method right body")
r = responses.empty_post
- test:is(r.status, 200, "POST: good status")
- test:ok(r.headers['header1'] == headers.header1 and
+ testcase:is(r.status, 200, "POST: good status")
+ testcase:ok(r.headers['header1'] == headers.header1 and
r.headers['header2'] == headers.header2, "POST: good headers")
- test:isnil(r.body, "POST: empty body")
+ testcase:isnil(r.body, "POST: empty body")
r = responses.good_post
- test:is(r.status, 200, "POST: good status")
- test:ok(r.headers['header1'] == headers.header1 and
+ testcase:is(r.status, 200, "POST: good status")
+ testcase:ok(r.headers['header1'] == headers.header1 and
r.headers['header2'] == headers.header2, "POST: good headers")
- test:is(r.body, json_body, "POST: body")
+ testcase:is(r.body, json_body, "POST: body")
r = responses.good_put
- test:is(r.status, 200, "PUT: good status")
- test:ok(r.headers['header'] == headers.header and
+ testcase:is(r.status, 200, "PUT: good status")
+ testcase:ok(r.headers['header'] == headers.header and
r.headers['header2'] == headers.header2, "PUT: good headers")
r = responses.bad_get
- test:is(r.status, 404, "GET: http page not exists")
- test:is(r.reason, 'Unknown', '404 - Unknown')
- test:isnt(r.body:len(), 0, "GET: not empty body page not exists")
- test:ok(string.find(r.body, "Not Found"),
+ testcase:is(r.status, 404, "GET: http page not exists")
+ testcase:is(r.reason, 'Unknown', '404 - Unknown')
+ testcase:isnt(r.body:len(), 0, "GET: not empty body page not exists")
+ testcase:ok(string.find(r.body, "Not Found"),
"GET: right body page not exists")
local st = http:stat()
- test:ok(st.sockets_added == st.sockets_deleted and
+ testcase:ok(st.sockets_added == st.sockets_deleted and
st.active_requests == 0,
"stats checking")
end
-local function test_errors(test)
- test:plan(2)
+local function test_errors(testcase)
+ testcase:plan(2)
local http = client:new()
local status, err = pcall(http.get, http, "htp://mail.ru")
- test:ok(not status and string.find(json.encode(err),
+ testcase:ok(not status and string.find(json.encode(err),
"Unsupported protocol"),
"GET: exception on bad protocol")
status, err = pcall(http.post, http, "htp://mail.ru", "")
- test:ok(not status and string.find(json.encode(err),
+ testcase: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.
-- gh-4281 Check that opts.headers can be a table and opts.headers
-- keys can be strings only.
-local function test_request_headers(test, url, opts)
+local function test_request_headers(testcase, url, opts)
local exp_err_bad_opts_headers = 'opts.headers should be a table'
local exp_err_bad_key = 'opts.headers keys should be strings'
local exp_err_bad_value = 'opts.headers values should be strings'
@@ -350,53 +348,53 @@ local function test_request_headers(test, url, opts)
exp_err = exp_err_bad_value,
},
}
- test:plan(#cases)
+ testcase:plan(#cases)
local http = client:new()
for _, case in ipairs(cases) do
- local opts = merge(table.copy(opts), case.opts)
+ opts = merge(table.copy(opts), case.opts)
local ok, err = pcall(http.get, http, url, opts)
if case.postrequest_check ~= nil then
case.postrequest_check(opts)
end
if case.exp_err == nil then
-- expect success
- test:ok(ok, case[1])
+ testcase:ok(ok, case[1])
else
-- expect fail
assert(type(err) == 'string')
err = err:gsub('^builtin/[a-z._]+.lua:[0-9]+: ', '')
- test:is_deeply({ok, err}, {false, case.exp_err}, case[1])
+ testcase:is_deeply({ok, err}, {false, case.exp_err}, case[1])
end
end
end
-local function test_headers(test, url, opts)
- test:plan(21)
+local function test_headers(testcase, url, opts)
+ testcase:plan(21)
local http = client:new()
local r = http:get(url .. 'headers', opts)
- test:is(type(r.headers["set-cookie"]), 'string', "set-cookie check")
- test:ok(r.headers["set-cookie"]:match("likes=cheese"), "set-cookie check")
- test:ok(r.headers["set-cookie"]:match("age = 17"), "set-cookie check")
- test:is(r.headers["content-type"], "application/json", "content-type check")
- test:is(r.headers["my_header"], "value1,value2", "other header check")
- test:isnil(r.headers["11200ok"], "http status line not included in headers")
- test:is(r.cookies["likes"][1], "cheese", "cookie value check")
- test:ok(r.cookies["likes"][2][1]:match("Expires"), "cookie option check")
- test:ok(r.cookies["likes"][2][3]:match("HttpOnly"), "cookie option check")
- test:is(r.cookies["age"][1], "17", "cookie value check")
- test:is(#r.cookies["age"][2], 1, "cookie option check")
- test:is(r.cookies["age"][2][1], "Secure", "cookie option check")
- test:ok(r.cookies["good_name"] ~= nil , "cookie name check")
- test:ok(r.cookies["bad at name"] == nil , "cookie name check")
- test:ok(r.cookies["badname"] == nil , "cookie name check")
- test:ok(r.cookies["badcookie"] == nil , "cookie name check")
- 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")
+ testcase:is(type(r.headers["set-cookie"]), 'string', "set-cookie check")
+ testcase:ok(r.headers["set-cookie"]:match("likes=cheese"), "set-cookie check")
+ testcase:ok(r.headers["set-cookie"]:match("age = 17"), "set-cookie check")
+ testcase:is(r.headers["content-type"], "application/json", "content-type check")
+ testcase:is(r.headers["my_header"], "value1,value2", "other header check")
+ testcase:isnil(r.headers["11200ok"], "http status line not included in headers")
+ testcase:is(r.cookies["likes"][1], "cheese", "cookie value check")
+ testcase:ok(r.cookies["likes"][2][1]:match("Expires"), "cookie option check")
+ testcase:ok(r.cookies["likes"][2][3]:match("HttpOnly"), "cookie option check")
+ testcase:is(r.cookies["age"][1], "17", "cookie value check")
+ testcase:is(#r.cookies["age"][2], 1, "cookie option check")
+ testcase:is(r.cookies["age"][2][1], "Secure", "cookie option check")
+ testcase:ok(r.cookies["good_name"] ~= nil , "cookie name check")
+ testcase:ok(r.cookies["bad at name"] == nil , "cookie name check")
+ testcase:ok(r.cookies["badname"] == nil , "cookie name check")
+ testcase:ok(r.cookies["badcookie"] == nil , "cookie name check")
+ testcase:isnil(r.headers["very_very_very_long_headers_name1"], "no long header name")
+ testcase: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)
- test:is(r.headers["very_very_very_long_headers_name1"], "true", "truncated max_header_name_length")
+ r = http:get(url .. 'headers', opts)
+ testcase:is(r.headers["very_very_very_long_headers_name1"], "true", "truncated max_header_name_length")
opts["max_header_name_length"] = nil
-- Send large headers.
@@ -406,26 +404,25 @@ 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}))
- test:is(r.headers[hname], hvalue, '8192 bytes header: success')
+ r = http:post(url, nil, merge(opts, {headers = headers}))
+ testcase: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},
+ testcase:is_deeply({ok, tostring(err)}, {false, exp_err},
'8193 KiB header: error')
end
-local function test_special_methods(test, url, opts)
- test:plan(14)
+local function test_special_methods(testcase, url, opts)
+ testcase:plan(14)
local http = client.new()
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,39 +451,35 @@ 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
- test:is(responses.patch_data.status, 200, "HTTP:PATCH request")
- test:ok(json.decode(responses.patch_data.body).key == "val",
+ testcase:is(responses.patch_data.status, 200, "HTTP:PATCH request")
+ testcase:ok(json.decode(responses.patch_data.body).key == "val",
"HTTP:PATCH request content")
- test:is(responses.delete_data.status, 200, "HTTP:DELETE request")
- test:ok(responses.delete_data.headers.method == "DELETE",
+ testcase:is(responses.delete_data.status, 200, "HTTP:DELETE request")
+ testcase:ok(responses.delete_data.headers.method == "DELETE",
"HTTP:DELETE request content")
- test:is(responses.options_data.status, 200, "HTTP:OPTIONS request")
- test:ok(responses.options_data.headers.method == "OPTIONS",
+ testcase:is(responses.options_data.status, 200, "HTTP:OPTIONS request")
+ testcase:ok(responses.options_data.headers.method == "OPTIONS",
"HTTP:OPTIONS request content")
- test:is(responses.head_data.status, 200, "HTTP:HEAD request code")
- test:ok(responses.head_data.headers.method == "HEAD",
+ testcase:is(responses.head_data.status, 200, "HTTP:HEAD request code")
+ testcase:ok(responses.head_data.headers.method == "HEAD",
"HTTP:HEAD request content")
- test:is(responses.connect_data.status, 200, "HTTP:CONNECT request")
- test:ok(responses.connect_data.headers.method == "CONNECT",
+ testcase:is(responses.connect_data.status, 200, "HTTP:CONNECT request")
+ testcase:ok(responses.connect_data.headers.method == "CONNECT",
"HTTP:OPTIONS request content")
- test:is(responses.trace_data.status, 200, "HTTP:TRACE request")
- test:ok(responses.trace_data.headers.method == "TRACE",
+ testcase:is(responses.trace_data.status, 200, "HTTP:TRACE request")
+ testcase:ok(responses.trace_data.headers.method == "TRACE",
"HTTP:TRACE request content")
- test:is(responses.custom_data.status, 400, "HTTP:CUSTOM request")
- test:ok(responses.custom_data.headers.method == "CUSTOM",
+ testcase:is(responses.custom_data.status, 400, "HTTP:CUSTOM request")
+ testcase:ok(responses.custom_data.headers.method == "CUSTOM",
"HTTP:CUSTOM request content")
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 function test_concurrent(testcase, url, opts)
+ testcase:plan(3)
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
@@ -577,23 +568,23 @@ local function test_concurrent(test, url, opts)
break
end
end
- test:is(ok_req, true, "All requests are ok")
- test:ok(ok_sockets_added, "free sockets")
- test:ok(ok_active, "no active requests")
+ testcase:is(ok_req, true, "All requests are ok")
+ testcase:ok(ok_sockets_added, "free sockets")
+ testcase:ok(ok_active, "no active requests")
end
-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)
- test:test("http.client headers redefine", test_http_client_headers_redefine,
+local function run_tests(testcase, sock_family, sock_addr)
+ testcase:plan(11)
+ local server, url, opts = start_server(testcase, sock_family, sock_addr)
+ testcase:test("http.client", test_http_client, url, opts)
+ testcase:test("http.client headers redefine", test_http_client_headers_redefine,
url, opts)
- test:test("cancel and errinj", test_cancel_and_errinj, url .. 'long_query', opts)
- test:test("basic http post/get", test_post_and_get, url, opts)
- test:test("errors", test_errors)
- test:test("request_headers", test_request_headers, url, opts)
- test:test("headers", test_headers, url, opts)
- test:test("special methods", test_special_methods, url, opts)
+ testcase:test("cancel and errinj", test_cancel_and_errinj, url .. 'long_query', opts)
+ testcase:test("basic http post/get", test_post_and_get, url, opts)
+ testcase:test("errors", test_errors)
+ testcase:test("request_headers", test_request_headers, url, opts)
+ testcase:test("headers", test_headers, url, opts)
+ testcase:test("special methods", test_special_methods, url, opts)
if sock_family == 'AF_UNIX' and jit.os ~= "Linux" then
--
-- BSD-based operating systems (including OS X) will fail
@@ -604,25 +595,25 @@ function run_tests(test, sock_family, sock_addr)
-- however, is fine - instead of returning ECONNEREFUSED
-- it will suspend connect() until backlog is processed.
--
- test:skip("concurrent")
+ testcase:skip("concurrent")
else
- test:test("concurrent", test_concurrent, url, opts)
+ testcase:test("concurrent", test_concurrent, url, opts)
end
- stop_server(test, server)
+ stop_server(testcase, server)
end
test:plan(2)
-test:test("http over AF_INET", function(test)
+test:test("http over AF_INET", function(testcase)
local s = socketlib('AF_INET', 'SOCK_STREAM', 0)
s:bind('127.0.0.1', 0)
local host = s:name().host
local port = s:name().port
s:close()
- run_tests(test, 'AF_INET', string.format("%s:%d", host, port))
+ run_tests(testcase, 'AF_INET', string.format("%s:%d", host, port))
end)
-test:test("http over AF_UNIX", function(test)
+test:test("http over AF_UNIX", function(testcase)
local path = os.tmpname()
os.remove(path)
local status = pcall(client.get, 'http://localhost/', {unix_socket = path})
@@ -630,7 +621,7 @@ test:test("http over AF_UNIX", function(test)
-- Unix domain sockets are not supported, skip the test.
return
end
- run_tests(test, 'AF_UNIX', path)
+ run_tests(testcase, 'AF_UNIX', path)
os.remove(path)
end)
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')
diff --git a/test/app-tap/init_script.test.lua b/test/app-tap/init_script.test.lua
index e6f298f93..56de6d44e 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
@@ -36,7 +36,7 @@ for k,v in pairs(box.cfg) do
end
table.sort(t)
print('box.cfg')
-for k,v in pairs(t) do print(v) end
+for _,v in pairs(t) do print(v) end
--
-- Insert tests
--
@@ -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
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"))
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 a448ba87a..dd33ea63b 100755
--- a/test/app-tap/logger.test.lua
+++ b/test/app-tap/logger.test.lua
@@ -7,7 +7,7 @@ test:plan(64)
-- gh-5121: Allow to use 'json' output before box.cfg()
--
local log = require('log')
-_, err = pcall(log.log_format, 'json')
+local _, err = pcall(log.log_format, 'json')
test:ok(err == nil)
-- We're not allowed to use json with syslog though.
@@ -141,7 +141,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
@@ -160,7 +160,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")
@@ -171,34 +171,34 @@ 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)
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,
memtx_memory=107374182,
log_format = "json"}
-local file = io.open(filename)
+file = io.open(filename)
while file:read() do
end
log.error("error")
-local line = file:read()
+line = file:read()
message = json.decode(line)
test:is(type(message), 'table', "json valid in log.error")
test:is(message.level, "ERROR", "check type error")
test:is(message.message, "error", "check error message")
log.info({key="value", level=48})
-local line = file:read()
+line = file:read()
message = json.decode(line)
test:is(type(message), 'table', "json valid in log.info")
test:is(message.level, "INFO", "check type info")
@@ -206,7 +206,7 @@ test:is(message.message, nil, "check message is nil")
test:is(message.key, "value", "custom table encoded")
log.info('this is "')
-local line = file:read()
+line = file:read()
message = json.decode(line)
test:is(message.message, "this is \"", "check message with escaped character")
@@ -216,13 +216,14 @@ line = file:read()
test:ok(line:len() < 20000, "big line truncated")
log.info("json")
-local line = file:read()
+line = file:read()
message = json.decode(line)
test:is(message.message, "json", "check message with internal key word")
log.log_format("plain")
log.info("hello")
line = file:read()
test:ok(not line:match("{"), "log change format")
+local e
s, e = pcall(log.log_format, "non_format")
test:ok(not s, "bad format")
file:close()
@@ -235,7 +236,7 @@ file = fio.open(filename)
while file == nil do file = fio.open(filename) fiber.sleep(0.0001) end
line = file:read()
while line == nil or line == "" do line = file:read() fiber.sleep(0.0001) end
-index = line:find('\n')
+local index = line:find('\n')
line = line:sub(1, index)
message = json.decode(line)
test:is(message.message, "log file has been reopened", "check message after log.rotate()")
diff --git a/test/app-tap/lua/serializer_test.lua b/test/app-tap/lua/serializer_test.lua
index 2a668f898..dbc1ddcab 100644
--- a/test/app-tap/lua/serializer_test.lua
+++ b/test/app-tap/lua/serializer_test.lua
@@ -2,7 +2,7 @@ local ffi = require('ffi')
local function rt(test, s, x, t)
local buf1 = s.encode(x)
- local x1, offset1 = s.decode(buf1)
+ local x1 = s.decode(buf1)
local xstr
if type(x) == "table" then
xstr = "table"
@@ -189,8 +189,6 @@ local function test_double(test, s)
ss.cfg{decode_invalid_numbers = true}
rt(test, s, nan)
rt(test, s, inf)
-
- ss = nil
end
local function test_decimal(test, s)
@@ -258,14 +256,14 @@ local function test_table(test, s, is_array, is_map)
test:ok(is_map(s.encode({k1 = 'v1', k2 = 'v2', k3 = 'v3'})), "map is map")
-- utf-8 pairs
- rt(test, s, {Метапеременная = { 'Метазначение' }})
+ rt(test, s, {['Метапеременная'] = { 'Метазначение' }})
rt(test, s, {test = { 'Результат' }})
local arr = setmetatable({1, 2, 3, k1 = 'v1', k2 = 'v2', 4, 5},
{ __serialize = 'seq'})
local map = setmetatable({1, 2, 3, 4, 5}, { __serialize = 'map'})
local obj = setmetatable({}, {
- __serialize = function(x) return 'serialize' end
+ __serialize = function() return 'serialize' end
})
-- __serialize on encode
@@ -306,14 +304,12 @@ local function test_table(test, s, is_array, is_map)
-- string (from __serialize hook)
test:is(ss.decode(ss.encode(obj)), "serialize", "object load __serialize")
- ss = nil
-
--
-- decode_save_metatables
--
- local arr = {1, 2, 3}
- local map = {k1 = 'v1', k2 = 'v2', k3 = 'v3'}
+ arr = {1, 2, 3}
+ map = {k1 = 'v1', k2 = 'v2', k3 = 'v3'}
ss = s.new()
ss.cfg{decode_save_metatables = false}
@@ -325,14 +321,12 @@ local function test_table(test, s, is_array, is_map)
"array save __serialize")
test:is(getmetatable(ss.decode(ss.encode(map))).__serialize, "map",
"map save __serialize")
- ss = nil
-
--
-- encode_sparse_convert / encode_sparse_ratio / encode_sparse_safe
--
- local ss = s.new()
+ ss = s.new()
ss.cfg{encode_sparse_ratio = 2, encode_sparse_safe = 10}
@@ -359,8 +353,6 @@ local function test_table(test, s, is_array, is_map)
-- array
test:ok(is_array(ss.encode({1, 2, 3, 4, 5, [100] = 100})),
"sparse safe 2")
-
- ss = nil
end
local function test_ucdata(test, s)
@@ -374,9 +366,9 @@ local function test_ucdata(test, s)
local ctype = ffi.typeof('struct serializer_cdata_test')
ffi.metatype(ctype, {
__index = {
- __serialize = function(obj) return 'unpack' end,
+ __serialize = function() return 'unpack' end,
},
- __tostring = function(obj) return 'tostring' end
+ __tostring = function() return 'tostring' end
});
local cdata = ffi.new(ctype)
@@ -409,8 +401,6 @@ local function test_ucdata(test, s)
test:istable(ss.decode(ss.encode(udata)), 'udata hook priority')
-- gh-1226: luaL_convertfield should ignore __serialize hook for ctypes
test:like(ss.decode(ss.encode(ctype)), 'ctype<struct', 'ctype __serialize')
-
- ss = nil
end
local function test_depth(test, s)
@@ -433,12 +423,12 @@ local function test_depth(test, s)
s.cfg({encode_deep_as_nil = false})
local t = nil
- for i = 1, max_depth + 1 do t = {t} end
- local ok, err = pcall(s.encode, t)
+ for _ = 1, max_depth + 1 do t = {t} end
+ local ok = pcall(s.encode, t)
test:ok(not ok, "too deep encode depth")
s.cfg({encode_max_depth = max_depth + 1})
- ok, err = pcall(s.encode, t)
+ ok = pcall(s.encode, t)
test:ok(ok, "no throw in a corner case")
s.cfg({encode_deep_as_nil = deep_as_nil, encode_max_depth = max_depth})
@@ -483,21 +473,21 @@ local function test_decode_buffer(test, s)
test:plan(#cases)
for _, case in ipairs(cases) do
- test:test(case[1], function(test)
- test:plan(4)
+ test:test(case[1], function(testcase)
+ testcase:plan(4)
local args_len = table.maxn(case.args)
local res, res_buf = case.func(unpack(case.args, 1, args_len))
- test:is_deeply(res, case.exp_res, 'verify result')
+ testcase:is_deeply(res, case.exp_res, 'verify result')
local buf = case.args[1]
local rewind = res_buf - buf
- test:is(rewind, case.exp_rewind, 'verify resulting buffer')
- -- test:iscdata() is not sufficient here, because it
+ testcase:is(rewind, case.exp_rewind, 'verify resulting buffer')
+ -- testcase:iscdata() is not sufficient here, because it
-- ignores 'const' qualifier (because of using
-- ffi.istype()).
- test:is(type(res_buf), 'cdata', 'verify resulting buffer type')
+ testcase:is(type(res_buf), 'cdata', 'verify resulting buffer type')
local buf_ctype = tostring(ffi.typeof(buf))
local res_buf_ctype = tostring(ffi.typeof(res_buf))
- test:is(res_buf_ctype, buf_ctype, 'verify resulting buffer ctype')
+ testcase:is(res_buf_ctype, buf_ctype, 'verify resulting buffer ctype')
end)
end
end
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)
diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index a6658cc61..e161d2f29 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: no unused
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)
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
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)
diff --git a/test/app-tap/popen.test.lua b/test/app-tap/popen.test.lua
index 3b6d9469f..6615d6dae 100755
--- a/test/app-tap/popen.test.lua
+++ b/test/app-tap/popen.test.lua
@@ -90,12 +90,13 @@ local function test_trivial_echo_output(test)
test:ok(is_dead, 'the process is killed after close()')
-- Verify that :close() is idempotent.
- local res, err = ph:close()
+ res, err = ph:close()
test:is_deeply({res, err}, {true, nil}, 'close() is idempotent')
-- Sending a signal using a closed handle gives an error.
local exp_err = 'popen: attempt to operate on a closed handle'
- local ok, err = pcall(ph.signal, ph, popen.signal.SIGTERM)
+ local ok
+ ok, err = pcall(ph.signal, ph, popen.signal.SIGTERM)
test:is_deeply({ok, err.type, tostring(err)},
{false, 'IllegalParams', exp_err},
'signal() on closed handle gives an error')
@@ -195,28 +196,28 @@ local function test_read_write(test)
test:is_deeply({res, err}, {true, nil}, 'write() succeeds')
local ok = ph:shutdown({stdin = true})
test:ok(ok, 'shutdown() succeeds')
- local res, err = ph:read()
+ res, err = ph:read()
test:is_deeply({res, err}, {payload, nil}, 'read() from stdout succeeds')
ph:close()
-- The script copies data from stdin to stderr.
- local script = 'prompt=""; read -r prompt; printf "$prompt" 1>&2'
- local ph = popen.shell(script, 'Rw')
+ script = 'prompt=""; read -r prompt; printf "$prompt" 1>&2'
+ ph = popen.shell(script, 'Rw')
-- Write to stdin, read from stderr.
- local res, err = ph:write(payload .. '\n')
+ res, err = ph:write(payload .. '\n')
test:is_deeply({res, err}, {true, nil}, 'write() succeeds')
- local ok = ph:shutdown({stdin = true})
+ ok = ph:shutdown({stdin = true})
test:ok(ok, 'shutdown() succeeds')
- local res, err = ph:read({stderr = true})
+ res, err = ph:read({stderr = true})
test:is_deeply({res, err}, {payload, nil}, 'read() from stderr succeeds')
ph:close()
-- The same script: copy from stdin to stderr.
- local script = 'prompt=""; read -r prompt; printf "$prompt" 1>&2'
- local ph = popen.shell(script, 'Rw')
+ script = 'prompt=""; read -r prompt; printf "$prompt" 1>&2'
+ ph = popen.shell(script, 'Rw')
-- Ensure that read waits for data and does not return
-- prematurely.
@@ -226,7 +227,7 @@ local function test_read_write(test)
res_w, err_w = ph:write(payload .. '\n')
ph:shutdown({stdin = true})
end)
- local res, err = ph:read({stderr = true})
+ res, err = ph:read({stderr = true})
test:is_deeply({res_w, err_w}, {true, nil}, 'write() succeeds')
test:is_deeply({res, err}, {payload, nil}, 'read() from stderr succeeds')
@@ -251,10 +252,10 @@ local function test_read_timeout(test)
'timeout error')
-- Write and read after the timeout error.
- local res, err = ph:write(payload .. '\n')
+ res, err = ph:write(payload .. '\n')
test:is_deeply({res, err}, {true, nil}, 'write data')
ph:shutdown({stdin = true})
- local res, err = ph:read()
+ res, err = ph:read()
test:is_deeply({res, err}, {payload, nil}, 'read data')
ph:close()
@@ -316,13 +317,13 @@ local function test_shutdown(test)
test:plan(9)
-- Verify std* status.
- local function test_stream_status(test, ph, pstream, exp_pstream)
- test:plan(6)
+ local function test_stream_status(testcase, ph, pstream, exp_pstream)
+ testcase:plan(6)
local info = ph:info()
for _, s in ipairs({'stdin', 'stdout', 'stderr'}) do
local exp_status = s == pstream and exp_pstream or nil
- test:is(ph[s], exp_status, ('%s open'):format(s))
- test:is(info[s], exp_status, ('%s open'):format(s))
+ testcase:is(ph[s], exp_status, ('%s open'):format(s))
+ testcase:is(info[s], exp_status, ('%s open'):format(s))
end
end
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()
diff --git a/test/app-tap/string.test.lua b/test/app-tap/string.test.lua
index 02a1a84d7..bd4db6e43 100755
--- a/test/app-tap/string.test.lua
+++ b/test/app-tap/string.test.lua
@@ -5,40 +5,40 @@ local test = tap.test("string extensions")
test:plan(7)
-test:test("split", function(test)
- test:plan(10)
+test:test("split", function(testcase)
+ testcase:plan(10)
-- testing basic split (works over gsplit)
- test:ok(not pcall(string.split, "", ""), "empty separator")
- test:ok(not pcall(string.split, "a", ""), "empty separator")
- test:is_deeply((""):split("z"), {""}, "empty split")
- test:is_deeply(("a"):split("a"), {"", ""}, "split self")
- test:is_deeply(
+ testcase:ok(not pcall(string.split, "", ""), "empty separator")
+ testcase:ok(not pcall(string.split, "a", ""), "empty separator")
+ testcase:is_deeply((""):split("z"), {""}, "empty split")
+ testcase:is_deeply(("a"):split("a"), {"", ""}, "split self")
+ testcase:is_deeply(
(" 1 2 3 "):split(),
{"1", "2", "3"},
"complex split on empty separator"
)
- test:is_deeply(
+ testcase:is_deeply(
(" 1 2 3 "):split(" "),
{"", "1", "2", "", "3", "", ""},
"complex split on space separator"
)
- test:is_deeply(
+ testcase:is_deeply(
(" 1 2 \n\n\n\r\t\n3 "):split(),
{"1", "2", "3"},
"complex split on empty separator"
)
- test:is_deeply(
+ testcase:is_deeply(
("a*bb*c*ddd"):split("*"),
{"a", "bb", "c", "ddd"},
"another * separator"
)
- test:is_deeply(
+ testcase:is_deeply(
("dog:fred:bonzo:alice"):split(":", 2),
{"dog", "fred", "bonzo:alice"},
"testing max separator"
)
- test:is_deeply(
+ testcase:is_deeply(
("///"):split("/"),
{"", "", "", ""},
"testing splitting on one char"
@@ -46,231 +46,231 @@ test:test("split", function(test)
end)
-- gh-2214 - string.ljust()/string.rjust() Lua API
-test:test("ljust/rjust/center", function(test)
- test:plan(18)
+test:test("ljust/rjust/center", function(testcase)
+ testcase:plan(18)
- test:is(("help"):ljust(0), "help", "ljust, length 0, do nothing")
- test:is(("help"):rjust(0), "help", "rjust, length 0, do nothing")
- test:is(("help"):center(0), "help", "center, length 0, do nothing")
+ testcase:is(("help"):ljust(0), "help", "ljust, length 0, do nothing")
+ testcase:is(("help"):rjust(0), "help", "rjust, length 0, do nothing")
+ testcase:is(("help"):center(0), "help", "center, length 0, do nothing")
- test:is(("help"):ljust(3), "help", "ljust, length 3, do nothing")
- test:is(("help"):rjust(3), "help", "rjust, length 3, do nothing")
- test:is(("help"):center(3), "help", "center, length 3, do nothing")
+ testcase:is(("help"):ljust(3), "help", "ljust, length 3, do nothing")
+ testcase:is(("help"):rjust(3), "help", "rjust, length 3, do nothing")
+ testcase:is(("help"):center(3), "help", "center, length 3, do nothing")
- test:is(("help"):ljust(5), "help ", "ljust, length 5, one extra charachter")
- test:is(("help"):rjust(5), " help", "rjust, length 5, one extra charachter")
- test:is(("help"):center(5), "help ", "center, length 5, one extra charachter")
+ testcase:is(("help"):ljust(5), "help ", "ljust, length 5, one extra charachter")
+ testcase:is(("help"):rjust(5), " help", "rjust, length 5, one extra charachter")
+ testcase:is(("help"):center(5), "help ", "center, length 5, one extra charachter")
- test:is(("help"):ljust(6), "help ", "ljust, length 6, two extra charachters")
- test:is(("help"):rjust(6), " help", "rjust, length 6, two extra charachters")
- test:is(("help"):center(6), " help ", "center, length 6, two extra charachters")
+ testcase:is(("help"):ljust(6), "help ", "ljust, length 6, two extra charachters")
+ testcase:is(("help"):rjust(6), " help", "rjust, length 6, two extra charachters")
+ testcase:is(("help"):center(6), " help ", "center, length 6, two extra charachters")
- test:is(("help"):ljust(6, '.'), "help..", "ljust, length 6, two extra charachters, custom fill char")
- test:is(("help"):rjust(6, '.'), "..help", "rjust, length 6, two extra charachters, custom fill char")
- test:is(("help"):center(6, '.'), ".help.", "center, length 6, two extra charachters, custom fill char")
+ testcase:is(("help"):ljust(6, '.'), "help..", "ljust, length 6, two extra charachters, custom fill char")
+ testcase:is(("help"):rjust(6, '.'), "..help", "rjust, length 6, two extra charachters, custom fill char")
+ testcase:is(("help"):center(6, '.'), ".help.", "center, length 6, two extra charachters, custom fill char")
local errmsg = "%(char expected, got string%)"
local _, err = pcall(function() ("help"):ljust(6, "XX") end)
- test:ok(err and err:match(errmsg), "wrong params")
+ testcase:ok(err and err:match(errmsg), "wrong params")
_, err = pcall(function() ("help"):rjust(6, "XX") end)
- test:ok(err and err:match(errmsg), "wrong params")
+ testcase:ok(err and err:match(errmsg), "wrong params")
_, err = pcall(function() ("help"):center(6, "XX") end)
- test:ok(err and err:match(errmsg), "wrong params")
+ testcase:ok(err and err:match(errmsg), "wrong params")
end)
-- gh-2215 - string.startswith()/string.endswith() Lua API
-test:test("startswith/endswith", function(test)
- test:plan(21)
-
- test:ok((""):startswith(""), "empty+empty startswith")
- test:ok((""):endswith(""), "empty+empty endswith")
- test:ok(not (""):startswith("a"), "empty+non-empty startswith")
- test:ok(not (""):endswith("a"), "empty+non-empty endswith")
- test:ok(("a"):startswith(""), "non-empty+empty startswith")
- test:ok(("a"):endswith(""), "non-empty+empty endswith")
-
- test:ok(("12345"):startswith("123") , "simple startswith")
- test:ok(("12345"):startswith("123", 1, 5) , "startswith with good begin/end")
- test:ok(("12345"):startswith("123", 1, 3) , "startswith with good begin/end")
- test:ok(("12345"):startswith("123", -5, 3) , "startswith with good negative begin/end")
- test:ok(("12345"):startswith("123", -5, -3) , "startswith with good negative begin/end")
- test:ok(not ("12345"):startswith("123", 2, 5) , "bad startswith with good begin/end")
- test:ok(not ("12345"):startswith("123", 1, 2) , "bad startswith with good begin/end")
-
- test:ok(("12345"):endswith("345") , "simple endswith")
- test:ok(("12345"):endswith("345", 1, 5) , "endswith with good begin/end")
- test:ok(("12345"):endswith("345", 3, 5) , "endswith with good begin/end")
- test:ok(("12345"):endswith("345", -3, 5) , "endswith with good begin/end")
- test:ok(("12345"):endswith("345", -3, -1) , "endswith with good begin/end")
- test:ok(not ("12345"):endswith("345", 1, 4) , "bad endswith with good begin/end")
- test:ok(not ("12345"):endswith("345", 4, 5) , "bad endswith with good begin/end")
+test:test("startswith/endswith", function(testcase)
+ testcase:plan(21)
+
+ testcase:ok((""):startswith(""), "empty+empty startswith")
+ testcase:ok((""):endswith(""), "empty+empty endswith")
+ testcase:ok(not (""):startswith("a"), "empty+non-empty startswith")
+ testcase:ok(not (""):endswith("a"), "empty+non-empty endswith")
+ testcase:ok(("a"):startswith(""), "non-empty+empty startswith")
+ testcase:ok(("a"):endswith(""), "non-empty+empty endswith")
+
+ testcase:ok(("12345"):startswith("123") , "simple startswith")
+ testcase:ok(("12345"):startswith("123", 1, 5) , "startswith with good begin/end")
+ testcase:ok(("12345"):startswith("123", 1, 3) , "startswith with good begin/end")
+ testcase:ok(("12345"):startswith("123", -5, 3) , "startswith with good negative begin/end")
+ testcase:ok(("12345"):startswith("123", -5, -3) , "startswith with good negative begin/end")
+ testcase:ok(not ("12345"):startswith("123", 2, 5) , "bad startswith with good begin/end")
+ testcase:ok(not ("12345"):startswith("123", 1, 2) , "bad startswith with good begin/end")
+
+ testcase:ok(("12345"):endswith("345") , "simple endswith")
+ testcase:ok(("12345"):endswith("345", 1, 5) , "endswith with good begin/end")
+ testcase:ok(("12345"):endswith("345", 3, 5) , "endswith with good begin/end")
+ testcase:ok(("12345"):endswith("345", -3, 5) , "endswith with good begin/end")
+ testcase:ok(("12345"):endswith("345", -3, -1) , "endswith with good begin/end")
+ testcase:ok(not ("12345"):endswith("345", 1, 4) , "bad endswith with good begin/end")
+ testcase:ok(not ("12345"):endswith("345", 4, 5) , "bad endswith with good begin/end")
local _, err = pcall(function() ("help"):startswith({'n', 1}) end)
- test:ok(err and err:match("%(string expected, got table%)"), "wrong params")
+ testcase:ok(err and err:match("%(string expected, got table%)"), "wrong params")
end)
-test:test("hex", function(test)
- test:plan(2)
- test:is(string.hex("hello"), "68656c6c6f", "hex non-empty string")
- test:is(string.hex(""), "", "hex empty string")
+test:test("hex", function(testcase)
+ testcase:plan(2)
+ testcase:is(string.hex("hello"), "68656c6c6f", "hex non-empty string")
+ testcase:is(string.hex(""), "", "hex empty string")
end)
-test:test("fromhex", function(test)
- test:plan(11)
- test:is(string.fromhex("48656c6c6f"), "Hello", "from hex to bin")
- test:is(string.fromhex("4c696e7578"), "Linux", "from hex to bin")
- test:is(string.fromhex("6C6F72656D"), "lorem", "from hex to bin")
- test:is(string.fromhex("697073756D"), "ipsum", "from hex to bin")
- test:is(string.fromhex("6c6f72656d"), "lorem", "from hex to bin")
- test:is(string.fromhex("697073756d"), "ipsum", "from hex to bin")
- test:is(string.fromhex("6A6B6C6D6E6F"), "jklmno", "from hex to bin")
- test:is(string.fromhex("6a6b6c6d6e6f"), "jklmno", "from hex to bin")
+test:test("fromhex", function(testcase)
+ testcase:plan(11)
+ testcase:is(string.fromhex("48656c6c6f"), "Hello", "from hex to bin")
+ testcase:is(string.fromhex("4c696e7578"), "Linux", "from hex to bin")
+ testcase:is(string.fromhex("6C6F72656D"), "lorem", "from hex to bin")
+ testcase:is(string.fromhex("697073756D"), "ipsum", "from hex to bin")
+ testcase:is(string.fromhex("6c6f72656d"), "lorem", "from hex to bin")
+ testcase:is(string.fromhex("697073756d"), "ipsum", "from hex to bin")
+ testcase:is(string.fromhex("6A6B6C6D6E6F"), "jklmno", "from hex to bin")
+ testcase:is(string.fromhex("6a6b6c6d6e6f"), "jklmno", "from hex to bin")
local _, err = pcall(string.fromhex, "aaa")
- test:ok(err and err:match("(even amount of chars expected," ..
+ testcase:ok(err and err:match("(even amount of chars expected," ..
" got odd amount)"))
- local _, err = pcall(string.fromhex, "qq")
- test:ok(err and err:match("(hex string expected, got non hex chars)"))
- local _, err = pcall(string.fromhex, 795)
- test:ok(err and err:match("(string expected, got number)"))
+ _, err = pcall(string.fromhex, "qq")
+ testcase:ok(err and err:match("(hex string expected, got non hex chars)"))
+ _, err = pcall(string.fromhex, 795)
+ testcase:ok(err and err:match("(string expected, got number)"))
end)
-test:test("strip", function(test)
- test:plan(45)
+test:test("strip", function(testcase)
+ testcase:plan(45)
local str = " Hello world! "
- test:is(string.strip(str), "Hello world!", "strip (without chars)")
- test:is(string.lstrip(str), "Hello world! ", "lstrip (without chars)")
- test:is(string.rstrip(str), " Hello world!", "rstrip (without chars)")
+ testcase:is(string.strip(str), "Hello world!", "strip (without chars)")
+ testcase:is(string.lstrip(str), "Hello world! ", "lstrip (without chars)")
+ testcase:is(string.rstrip(str), " Hello world!", "rstrip (without chars)")
str = ""
- test:is(string.strip(str), str, "strip (0-len inp without chars)")
- test:is(string.lstrip(str), str, "lstrip (0-len inp without chars)")
- test:is(string.rstrip(str), str, "rstrip (0-len inp without chars)")
+ testcase:is(string.strip(str), str, "strip (0-len inp without chars)")
+ testcase:is(string.lstrip(str), str, "lstrip (0-len inp without chars)")
+ testcase:is(string.rstrip(str), str, "rstrip (0-len inp without chars)")
str = " "
- test:is(string.strip(str), "", "strip (1-len inp without chars)")
- test:is(string.lstrip(str), "", "lstrip (1-len inp without chars)")
- test:is(string.rstrip(str), "", "rstrip (1-len inp without chars)")
+ testcase:is(string.strip(str), "", "strip (1-len inp without chars)")
+ testcase:is(string.lstrip(str), "", "lstrip (1-len inp without chars)")
+ testcase:is(string.rstrip(str), "", "rstrip (1-len inp without chars)")
str = "\t\v"
- test:is(string.strip(str), "", "strip (strip everything without chars)")
- test:is(string.lstrip(str), "", "lstrip (strip everything without chars)")
- test:is(string.rstrip(str), "", "rstrip (strip everything without chars)")
+ testcase:is(string.strip(str), "", "strip (strip everything without chars)")
+ testcase:is(string.lstrip(str), "", "lstrip (strip everything without chars)")
+ testcase:is(string.rstrip(str), "", "rstrip (strip everything without chars)")
str = "hello"
- test:is(string.strip(str), str, "strip (strip nothing without chars)")
- test:is(string.lstrip(str), str, "lstrip (strip nothing without chars)")
- test:is(string.rstrip(str), str, "rstrip (strip nothing without chars)")
+ testcase:is(string.strip(str), str, "strip (strip nothing without chars)")
+ testcase:is(string.lstrip(str), str, "lstrip (strip nothing without chars)")
+ testcase:is(string.rstrip(str), str, "rstrip (strip nothing without chars)")
str = " \t\n\v\f\rTEST \t\n\v\f\r"
- test:is(string.strip(str), "TEST", "strip (all space characters without chars)")
- test:is(string.lstrip(str), "TEST \t\n\v\f\r", "lstrip (all space characters without chars)")
- test:is(string.rstrip(str), " \t\n\v\f\rTEST", "rstrip (all space characters without chars)")
+ testcase:is(string.strip(str), "TEST", "strip (all space characters without chars)")
+ testcase:is(string.lstrip(str), "TEST \t\n\v\f\r", "lstrip (all space characters without chars)")
+ testcase:is(string.rstrip(str), " \t\n\v\f\rTEST", "rstrip (all space characters without chars)")
local chars = "#\0"
str = "##Hello world!#"
- test:is(string.strip(str, chars), "Hello world!", "strip (with chars)")
- test:is(string.lstrip(str, chars), "Hello world!#", "lstrip (with chars)")
- test:is(string.rstrip(str, chars), "##Hello world!", "rstrip (with chars)")
+ testcase:is(string.strip(str, chars), "Hello world!", "strip (with chars)")
+ testcase:is(string.lstrip(str, chars), "Hello world!#", "lstrip (with chars)")
+ testcase:is(string.rstrip(str, chars), "##Hello world!", "rstrip (with chars)")
str = ""
- test:is(string.strip(str, chars), str, "strip (0-len inp with chars)")
- test:is(string.lstrip(str, chars), str, "lstrip (0-len inp with chars)")
- test:is(string.rstrip(str, chars), str, "rstrip (0-len inp with chars)")
+ testcase:is(string.strip(str, chars), str, "strip (0-len inp with chars)")
+ testcase:is(string.lstrip(str, chars), str, "lstrip (0-len inp with chars)")
+ testcase:is(string.rstrip(str, chars), str, "rstrip (0-len inp with chars)")
str = "#"
- test:is(string.strip(str, chars), "", "strip (1-len inp with chars)")
- test:is(string.lstrip(str, chars), "", "lstrip (1-len inp with chars)")
- test:is(string.rstrip(str, chars), "", "rstrip (1-len inp with chars)")
+ testcase:is(string.strip(str, chars), "", "strip (1-len inp with chars)")
+ testcase:is(string.lstrip(str, chars), "", "lstrip (1-len inp with chars)")
+ testcase:is(string.rstrip(str, chars), "", "rstrip (1-len inp with chars)")
str = "##"
- test:is(string.strip(str, chars), "", "strip (strip everything with chars)")
- test:is(string.lstrip(str, chars), "", "lstrip (strip everything with chars)")
- test:is(string.rstrip(str, chars), "", "rstrip (strip everything with chars)")
+ testcase:is(string.strip(str, chars), "", "strip (strip everything with chars)")
+ testcase:is(string.lstrip(str, chars), "", "lstrip (strip everything with chars)")
+ testcase:is(string.rstrip(str, chars), "", "rstrip (strip everything with chars)")
str = "hello"
- test:is(string.strip(str, chars), str, "strip (strip nothing with chars)")
- test:is(string.lstrip(str, chars), str, "lstrip (strip nothing with chars)")
- test:is(string.rstrip(str, chars), str, "rstrip (strip nothing with chars)")
+ testcase:is(string.strip(str, chars), str, "strip (strip nothing with chars)")
+ testcase:is(string.lstrip(str, chars), str, "lstrip (strip nothing with chars)")
+ testcase:is(string.rstrip(str, chars), str, "rstrip (strip nothing with chars)")
str = "\0\0\0TEST\0"
- test:is(string.strip(str, chars), "TEST", "strip (embedded 0s with chars)")
- test:is(string.lstrip(str, chars), "TEST\0", "lstrip (embedded 0s with chars)")
- test:is(string.rstrip(str, chars), "\0\0\0TEST", "rstrip (embedded 0s with chars)")
+ testcase:is(string.strip(str, chars), "TEST", "strip (embedded 0s with chars)")
+ testcase:is(string.lstrip(str, chars), "TEST\0", "lstrip (embedded 0s with chars)")
+ testcase:is(string.rstrip(str, chars), "\0\0\0TEST", "rstrip (embedded 0s with chars)")
chars = ""
- test:is(string.strip(str, chars), str, "strip (0-len chars)")
- test:is(string.lstrip(str, chars), str, "lstrip (0-len chars)")
- test:is(string.rstrip(str, chars), str, "rstrip (0-len chars)")
+ testcase:is(string.strip(str, chars), str, "strip (0-len chars)")
+ testcase:is(string.lstrip(str, chars), str, "lstrip (0-len chars)")
+ testcase:is(string.rstrip(str, chars), str, "rstrip (0-len chars)")
local _, err = pcall(string.strip, 12)
- test:ok(err and err:match("#1 to '.-%.strip' %(string expected, got number%)"), "strip err 1")
+ testcase:ok(err and err:match("#1 to '.-%.strip' %(string expected, got number%)"), "strip err 1")
_, err = pcall(string.lstrip, 12)
- test:ok(err and err:match("#1 to '.-%.lstrip' %(string expected, got number%)"), "lstrip err 1")
+ testcase:ok(err and err:match("#1 to '.-%.lstrip' %(string expected, got number%)"), "lstrip err 1")
_, err = pcall(string.rstrip, 12)
- test:ok(err and err:match("#1 to '.-%.rstrip' %(string expected, got number%)"), "rstrip err 1")
+ testcase:ok(err and err:match("#1 to '.-%.rstrip' %(string expected, got number%)"), "rstrip err 1")
_, err = pcall(string.strip, "foo", 12)
- test:ok(err and err:match("#2 to '.-%.strip' %(string expected, got number%)"), "strip err 2")
+ testcase:ok(err and err:match("#2 to '.-%.strip' %(string expected, got number%)"), "strip err 2")
_, err = pcall(string.lstrip, "foo", 12)
- test:ok(err and err:match("#2 to '.-%.lstrip' %(string expected, got number%)"), "lstrip err 2")
+ testcase:ok(err and err:match("#2 to '.-%.lstrip' %(string expected, got number%)"), "lstrip err 2")
_, err = pcall(string.rstrip, "foo", 12)
- test:ok(err and err:match("#2 to '.-%.rstrip' %(string expected, got number%)"), "rstrip err 2")
+ testcase:ok(err and err:match("#2 to '.-%.rstrip' %(string expected, got number%)"), "rstrip err 2")
end)
-test:test("unicode", function(test)
- test:plan(104)
+test:test("unicode", function(testcase)
+ testcase:plan(104)
local str = 'хеЛлоу вОрЛд ё Ё я Я э Э ъ Ъ hElLo WorLd 1234 i I İ 勺#☢༺'
local upper_res = 'ХЕЛЛОУ ВОРЛД Ё Ё Я Я Э Э Ъ Ъ HELLO WORLD 1234 I I İ 勺#☢༺'
local lower_res = 'хеллоу ворлд ё ё я я э э ъ ъ hello world 1234 i i i̇ 勺#☢༺'
local s = utf8.upper(str)
- test:is(s, upper_res, 'default locale upper')
+ testcase:is(s, upper_res, 'default locale upper')
s = utf8.lower(str)
- 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)
- test:isnt(err:find('Usage'), nil, 'upper usage is checked')
- s, err = pcall(utf8.lower, true)
- test:isnt(err:find('Usage'), nil, 'lower usage is checked')
-
- test:is(utf8.isupper('a'), false, 'isupper("a")')
- test:is(utf8.isupper('A'), true, 'isupper("A")')
- test:is(utf8.islower('a'), true, 'islower("a")')
- test:is(utf8.islower('A'), false, 'islower("A")')
- test:is(utf8.isalpha('a'), true, 'isalpha("a")')
- test:is(utf8.isalpha('A'), true, 'isalpha("A")')
- test:is(utf8.isalpha('aa'), false, 'isalpha("aa")')
- test:is(utf8.isalpha('勺'), true, 'isalpha("勺")')
- test:is(utf8.isupper('Ё'), true, 'isupper("Ё")')
- test:is(utf8.islower('ё'), true, 'islower("ё")')
- test:is(utf8.isdigit('a'), false, 'isdigit("a")')
- test:is(utf8.isdigit('1'), true, 'isdigit("1")')
- test:is(utf8.isdigit('9'), true, 'isdigit("9")')
-
- test:is(utf8.len(str), 56, 'len works on complex string')
+ testcase:is(s, lower_res, 'default locale lower')
+ testcase:is(utf8.upper(''), '', 'empty string upper')
+ testcase:is(utf8.lower(''), '', 'empty string lower')
+ local err, _
+ _, err = pcall(utf8.upper, true)
+ testcase:isnt(err:find('Usage'), nil, 'upper usage is checked')
+ _, err = pcall(utf8.lower, true)
+ testcase:isnt(err:find('Usage'), nil, 'lower usage is checked')
+
+ testcase:is(utf8.isupper('a'), false, 'isupper("a")')
+ testcase:is(utf8.isupper('A'), true, 'isupper("A")')
+ testcase:is(utf8.islower('a'), true, 'islower("a")')
+ testcase:is(utf8.islower('A'), false, 'islower("A")')
+ testcase:is(utf8.isalpha('a'), true, 'isalpha("a")')
+ testcase:is(utf8.isalpha('A'), true, 'isalpha("A")')
+ testcase:is(utf8.isalpha('aa'), false, 'isalpha("aa")')
+ testcase:is(utf8.isalpha('勺'), true, 'isalpha("勺")')
+ testcase:is(utf8.isupper('Ё'), true, 'isupper("Ё")')
+ testcase:is(utf8.islower('ё'), true, 'islower("ё")')
+ testcase:is(utf8.isdigit('a'), false, 'isdigit("a")')
+ testcase:is(utf8.isdigit('1'), true, 'isdigit("1")')
+ testcase:is(utf8.isdigit('9'), true, 'isdigit("9")')
+
+ testcase:is(utf8.len(str), 56, 'len works on complex string')
s = '12İ☢勺34'
- test:is(utf8.len(s), 7, 'len works no options')
- test:is(utf8.len(s, 1), 7, 'default start is 1')
- test:is(utf8.len(s, 2), 6, 'start 2')
- test:is(utf8.len(s, 3), 5, 'start 3')
+ testcase:is(utf8.len(s), 7, 'len works no options')
+ testcase:is(utf8.len(s, 1), 7, 'default start is 1')
+ testcase:is(utf8.len(s, 2), 6, 'start 2')
+ testcase:is(utf8.len(s, 3), 5, 'start 3')
local c
c, err = utf8.len(s, 4)
- 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)
- test:is(err, 6, 'error on 6 byte')
- c, 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')
- test:is(utf8.len(s, 1, -1), 7, 'default end is -1')
- test:is(utf8.len(s, 1, -2), 6, 'end -2')
- test:is(utf8.len(s, 1, -3), 5, 'end -3')
- test:is(utf8.len(s, 1, -4), 5, 'end in the middle of symbol')
- test:is(utf8.len(s, 1, -5), 5, 'end in the middle of symbol')
- test:is(utf8.len(s, 1, -6), 5, 'end in the middle of symbol')
- 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)
- 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')
- test:is(err, 2, "invalid unicode in the middle of the string")
+ testcase:isnil(c, 'middle of symbol offset is error')
+ testcase:is(err, 4, 'error on 4 byte')
+ testcase:is(utf8.len(s, 5), 4, 'start 5')
+ _, err = utf8.len(s, 6)
+ testcase:is(err, 6, 'error on 6 byte')
+ _, err = utf8.len(s, 0)
+ testcase:is(err, 'position is out of string', 'range is out of string')
+ testcase:is(utf8.len(s, #s), 1, 'start from the end')
+ testcase:is(utf8.len(s, #s + 1), 0, 'position is out of string')
+ testcase:is(utf8.len(s, 1, -1), 7, 'default end is -1')
+ testcase:is(utf8.len(s, 1, -2), 6, 'end -2')
+ testcase:is(utf8.len(s, 1, -3), 5, 'end -3')
+ testcase:is(utf8.len(s, 1, -4), 5, 'end in the middle of symbol')
+ testcase:is(utf8.len(s, 1, -5), 5, 'end in the middle of symbol')
+ testcase:is(utf8.len(s, 1, -6), 5, 'end in the middle of symbol')
+ testcase:is(utf8.len(s, 1, -7), 4, 'end -7')
+ testcase:is(utf8.len(s, 2, -7), 3, '[2, -7]')
+ testcase:is(utf8.len(s, 3, -7), 2, '[3, -7]')
+ _, err = utf8.len(s, 4, -7)
+ testcase:is(err, 4, '[4, -7] is error - start from the middle of symbol')
+ testcase:is(utf8.len(s, 10, -100), 0, 'it is ok to be out of str by end pos')
+ testcase:is(utf8.len(s, 10, -10), 0, 'it is ok to swap end and start pos')
+ testcase:is(utf8.len(''), 0, 'empty len')
+ testcase:is(utf8.len(s, -6, -1), 3, 'pass both negative offsets')
+ testcase:is(utf8.len(s, 3, 3), 1, "end in the middle on the same symbol as start")
+ _, err = utf8.len('a\xF4')
+ testcase:is(err, 2, "invalid unicode in the middle of the string")
local chars = {}
local codes = {}
@@ -278,21 +278,21 @@ test:test("unicode", function(test)
table.insert(chars, utf8.char(code))
table.insert(codes, code)
end
- test:is(table.concat(chars), s, "next and char works")
- c, err = pcall(utf8.char, 'kek')
- test:isnt(err:find('bad argument'), nil, 'char usage is checked')
- c, err = pcall(utf8.next, true)
- test:isnt(err:find('Usage'), nil, 'next usage is checked')
- c, err = pcall(utf8.next, '1234', true)
- test:isnt(err:find('bad argument'), nil, 'next usage is checked')
+ testcase:is(table.concat(chars), s, "next and char works")
+ _, err = pcall(utf8.char, 'kek')
+ testcase:isnt(err:find('bad argument'), nil, 'char usage is checked')
+ _, err = pcall(utf8.next, true)
+ testcase:isnt(err:find('Usage'), nil, 'next usage is checked')
+ _, err = pcall(utf8.next, '1234', true)
+ testcase:isnt(err:find('bad argument'), nil, 'next usage is checked')
local offset
offset, c = utf8.next('')
- test:isnil(offset, 'next on empty - nil offset')
- test:isnil(c, 'next on empty - nil code')
+ testcase:isnil(offset, 'next on empty - nil offset')
+ testcase:isnil(c, 'next on empty - nil code')
offset, c = utf8.next('123', 100)
- test:isnil(offset, 'out of string - nil offset')
- test:isnil(c, 'out of string - nil code')
- test:is(utf8.char(unpack(codes)), s, 'char with multiple values')
+ testcase:isnil(offset, 'out of string - nil offset')
+ testcase:isnil(c, 'out of string - nil code')
+ testcase:is(utf8.char(unpack(codes)), s, 'char with multiple values')
local uppers = 0
local lowers = 0
@@ -304,70 +304,70 @@ test:test("unicode", function(test)
if utf8.isalpha(code) then letters = letters + 1 end
if utf8.isdigit(code) then digits = digits + 1 end
end
- test:is(uppers, 13, 'uppers by code')
- test:is(lowers, 19, 'lowers by code')
- test:is(letters, 33, 'letters by code')
- test:is(digits, 4, 'digits by code')
+ testcase:is(uppers, 13, 'uppers by code')
+ testcase:is(lowers, 19, 'lowers by code')
+ testcase:is(letters, 33, 'letters by code')
+ testcase:is(digits, 4, 'digits by code')
s = '12345678'
- test:is(utf8.sub(s, 1, 1), '1', 'sub [1]')
- test:is(utf8.sub(s, 1, 2), '12', 'sub [1:2]')
- test:is(utf8.sub(s, 2, 2), '2', 'sub [2:2]')
- test:is(utf8.sub(s, 0, 2), '12', 'sub [0:2]')
- test:is(utf8.sub(s, 3, 7), '34567', 'sub [3:7]')
- test:is(utf8.sub(s, 7, 3), '', 'sub [7:3]')
- test:is(utf8.sub(s, 3, 100), '345678', 'sub [3:100]')
- test:is(utf8.sub(s, 100, 3), '', 'sub [100:3]')
-
- test:is(utf8.sub(s, 5), '5678', 'sub [5:]')
- test:is(utf8.sub(s, 1, -1), s, 'sub [1:-1]')
- test:is(utf8.sub(s, 1, -2), '1234567', 'sub [1:-2]')
- test:is(utf8.sub(s, 2, -2), '234567', 'sub [2:-2]')
- test:is(utf8.sub(s, 3, -3), '3456', 'sub [3:-3]')
- test:is(utf8.sub(s, 5, -4), '5', 'sub [5:-4]')
- test:is(utf8.sub(s, 7, -7), '', 'sub[7:-7]')
-
- test:is(utf8.sub(s, -2, -1), '78', 'sub [-2:-1]')
- test:is(utf8.sub(s, -1, -1), '8', 'sub [-1:-1]')
- test:is(utf8.sub(s, -4, -2), '567', 'sub [-4:-2]')
- test:is(utf8.sub(s, -400, -2), '1234567', 'sub [-400:-2]')
- test:is(utf8.sub(s, -3, -5), '', 'sub [-3:-5]')
-
- test:is(utf8.sub(s, -6, 5), '345', 'sub [-6:5]')
- test:is(utf8.sub(s, -5, 4), '4', 'sub [-5:4]')
- 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)
- test:isnt(err:find('Usage'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, true)
- test:isnt(err:find('Usage'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, '123')
- test:isnt(err:find('Usage'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, '123', true)
- test:isnt(err:find('bad argument'), nil, 'usage is checked')
- c, err = pcall(utf8.sub, '123', 1, true)
- test:isnt(err:find('bad argument'), nil, 'usage is checked')
+ testcase:is(utf8.sub(s, 1, 1), '1', 'sub [1]')
+ testcase:is(utf8.sub(s, 1, 2), '12', 'sub [1:2]')
+ testcase:is(utf8.sub(s, 2, 2), '2', 'sub [2:2]')
+ testcase:is(utf8.sub(s, 0, 2), '12', 'sub [0:2]')
+ testcase:is(utf8.sub(s, 3, 7), '34567', 'sub [3:7]')
+ testcase:is(utf8.sub(s, 7, 3), '', 'sub [7:3]')
+ testcase:is(utf8.sub(s, 3, 100), '345678', 'sub [3:100]')
+ testcase:is(utf8.sub(s, 100, 3), '', 'sub [100:3]')
+
+ testcase:is(utf8.sub(s, 5), '5678', 'sub [5:]')
+ testcase:is(utf8.sub(s, 1, -1), s, 'sub [1:-1]')
+ testcase:is(utf8.sub(s, 1, -2), '1234567', 'sub [1:-2]')
+ testcase:is(utf8.sub(s, 2, -2), '234567', 'sub [2:-2]')
+ testcase:is(utf8.sub(s, 3, -3), '3456', 'sub [3:-3]')
+ testcase:is(utf8.sub(s, 5, -4), '5', 'sub [5:-4]')
+ testcase:is(utf8.sub(s, 7, -7), '', 'sub[7:-7]')
+
+ testcase:is(utf8.sub(s, -2, -1), '78', 'sub [-2:-1]')
+ testcase:is(utf8.sub(s, -1, -1), '8', 'sub [-1:-1]')
+ testcase:is(utf8.sub(s, -4, -2), '567', 'sub [-4:-2]')
+ testcase:is(utf8.sub(s, -400, -2), '1234567', 'sub [-400:-2]')
+ testcase:is(utf8.sub(s, -3, -5), '', 'sub [-3:-5]')
+
+ testcase:is(utf8.sub(s, -6, 5), '345', 'sub [-6:5]')
+ testcase:is(utf8.sub(s, -5, 4), '4', 'sub [-5:4]')
+ testcase:is(utf8.sub(s, -2, 2), '', 'sub [-2:2]')
+ testcase:is(utf8.sub(s, -1, 8), '8', 'sub [-1:8]')
+
+ _, err = pcall(utf8.sub)
+ testcase:isnt(err:find('Usage'), nil, 'usage is checked')
+ _, err = pcall(utf8.sub, true)
+ testcase:isnt(err:find('Usage'), nil, 'usage is checked')
+ _, err = pcall(utf8.sub, '123')
+ testcase:isnt(err:find('Usage'), nil, 'usage is checked')
+ _, err = pcall(utf8.sub, '123', true)
+ testcase:isnt(err:find('bad argument'), nil, 'usage is checked')
+ _, err = pcall(utf8.sub, '123', 1, true)
+ testcase:isnt(err:find('bad argument'), nil, 'usage is checked')
local s1 = '☢'
local s2 = 'İ'
- test:is(s1 < s2, false, 'test binary cmp')
- test:is(utf8.cmp(s1, s2) < 0, true, 'test unicode <')
- test:is(utf8.cmp(s1, s1) == 0, true, 'test unicode eq')
- test:is(utf8.cmp(s2, s1) > 0, true, 'test unicode >')
- test:is(utf8.casecmp('a', 'A') == 0, true, 'test icase ==')
- test:is(utf8.casecmp('b', 'A') > 0, true, 'test icase >, first')
- test:is(utf8.casecmp('B', 'a') > 0, true, 'test icase >, second >')
- test:is(utf8.cmp('', '') == 0, true, 'test empty compare')
- test:is(utf8.cmp('', 'a') < 0, true, 'test left empty compare')
- test:is(utf8.cmp('a', '') > 0, true, 'test right empty compare')
- test:is(utf8.casecmp('', '') == 0, true, 'test empty icompare')
- test:is(utf8.casecmp('', 'a') < 0, true, 'test left empty icompare')
- test:is(utf8.casecmp('a', '') > 0, true, 'test right empty icompare')
+ testcase:is(s1 < s2, false, 'test binary cmp')
+ testcase:is(utf8.cmp(s1, s2) < 0, true, 'test unicode <')
+ testcase:is(utf8.cmp(s1, s1) == 0, true, 'test unicode eq')
+ testcase:is(utf8.cmp(s2, s1) > 0, true, 'test unicode >')
+ testcase:is(utf8.casecmp('a', 'A') == 0, true, 'test icase ==')
+ testcase:is(utf8.casecmp('b', 'A') > 0, true, 'test icase >, first')
+ testcase:is(utf8.casecmp('B', 'a') > 0, true, 'test icase >, second >')
+ testcase:is(utf8.cmp('', '') == 0, true, 'test empty compare')
+ testcase:is(utf8.cmp('', 'a') < 0, true, 'test left empty compare')
+ testcase:is(utf8.cmp('a', '') > 0, true, 'test right empty compare')
+ testcase:is(utf8.casecmp('', '') == 0, true, 'test empty icompare')
+ testcase:is(utf8.casecmp('', 'a') < 0, true, 'test left empty icompare')
+ testcase:is(utf8.casecmp('a', '') > 0, true, 'test right empty icompare')
-- gh-3709: utf8 can not handle an empty string.
- test:is(utf8.lower(''), '', 'lower empty')
- test:is(utf8.upper(''), '', 'upper empty')
+ testcase:is(utf8.lower(''), '', 'lower empty')
+ testcase:is(utf8.upper(''), '', 'upper empty')
end)
os.exit(test:check() == true and 0 or -1)
diff --git a/test/app-tap/tap.test.lua b/test/app-tap/tap.test.lua
index e2a78f630..0a8d8c6a1 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')
@@ -97,17 +97,17 @@ sub2 = test:test("subtest 2")
--
-- Multisubtest
--
-test:test("1 level", function(t)
- t:plan(1)
- t:test("2 level", function(t)
- t:plan(1)
- t:test("3 level", function(t)
- t:plan(1)
- t:test("4 level", function(t)
- t:plan(1)
- t:test("5 level", function(t)
- t:plan(1)
- t:ok(true, 'ok')
+test:test("1 level", function(t1)
+ t1:plan(1)
+ t1:test("2 level", function(t2)
+ t2:plan(1)
+ t2:test("3 level", function(t3)
+ t3:plan(1)
+ t3:test("4 level", function(t4)
+ t4:plan(1)
+ t4:test("5 level", function(t5)
+ t5:plan(1)
+ t5:ok(true, 'ok')
end)
end)
end)
diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua
index 9f1464617..257ce494f 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,
}
@@ -97,23 +96,14 @@ local function tctl_wait_start(dir, name)
fiber.sleep(0.01)
end
::again::
- while true do
- local stat, nb = pcall(require('net.box').new, path, {
- wait_connected = true, console = true
- })
- if stat == false then
- fiber.sleep(0.01)
- goto again
- else
- break
- end
- local stat, msg = pcall(nb.eval, nb, 'require("fiber").time()')
- if stat == false then
- fiber.sleep(0.01)
- else
- break
- end
+ local stat, _ = pcall(require('net.box').new, path, {
+ wait_connected = true, console = true
+ })
+ if stat == false then
+ fiber.sleep(0.01)
+ goto again
end
+ return
end
end
@@ -124,8 +114,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 +213,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 +247,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()
@@ -327,12 +316,12 @@ end
do
local dir = fio.tempdir()
- 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 function test_help(testcase, directory, cmd, e_stderr)
+ local desc = directory and 'with config' or 'without config'
+ directory = directory or './'
+ local _, _, stderr = run_command(directory, cmd)
if e_stderr ~= nil then
- if not test:ok(stderr:find(e_stderr), ("check stderr of '%s' %s"):format(cmd, desc)) then
+ if not testcase: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))
end
end
@@ -381,22 +370,22 @@ do
create_script(dir, 'filler.lua', filler_code)
- local function check_ctlcat_xlog(test, dir, args, delim, lc)
+ local function check_ctlcat_xlog(testcase, directory, args, delim, lc)
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)
- test:is(res, 0, desc .. " result")
- test:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count")
+ local res, stdout, _ = run_command(directory, command_base .. args)
+ testcase:is(res, 0, desc .. " result")
+ testcase:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count")
end
- local function check_ctlcat_snap(test, dir, args, delim, lc)
+ local function check_ctlcat_snap(testcase, directory, args, delim, lc)
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)
- test:is(res, 0, desc .. " result")
- test:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count")
+ local res, stdout, _ = run_command(directory, command_base .. args)
+ testcase:is(res, 0, desc .. " result")
+ testcase:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count")
end
local status, err = pcall(function()
@@ -413,7 +402,8 @@ 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)
- 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 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)
check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 53)
@@ -475,10 +465,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)
@@ -494,7 +484,7 @@ else
end
end
-test:test('filter_xlog', function(test)
+test:test('filter_xlog', function(testcase)
local xlog_data = {
-- [1] =
{
@@ -612,13 +602,13 @@ test:test('filter_xlog', function(test)
exp_result = {x[7], x[9]},
},
}
- test:plan(#cases)
+ testcase:plan(#cases)
rawset(_G, 'TARANTOOLCTL_UNIT_TEST', true)
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
@@ -632,14 +622,14 @@ test:test('filter_xlog', function(test)
end
for _, case in ipairs(cases) do
- local gen, param, state = xlog_data_pairs(xlog_data)
+ local data_pairs, param, state = xlog_data_pairs(xlog_data)
local res = {}
- tarantoolctl.internal.filter_xlog(gen, param, state, case.opts,
+ tarantoolctl.internal.filter_xlog(data_pairs, param, state, case.opts,
function(record)
table.insert(res, record)
end
)
- test:is_deeply(res, case.exp_result, case[1])
+ testcase:is_deeply(res, case.exp_result, case[1])
end
end)
diff --git a/test/app-tap/trigger.test.lua b/test/app-tap/trigger.test.lua
index a31d45e5f..ea23b3325 100755
--- a/test/app-tap/trigger.test.lua
+++ b/test/app-tap/trigger.test.lua
@@ -14,8 +14,8 @@ test:plan(3)
local trigger_list = trigger.new("sweet trigger")
test:ok(trigger_list ~= nil, "test that trigger list is created")
-test:test("simple trigger test", function(test)
- test:plan(10)
+test:test("simple trigger test", function(testcase)
+ testcase:plan(10)
local cnt = 0
local function trigger_cnt() cnt = cnt + 1 end
@@ -23,35 +23,35 @@ test:test("simple trigger test", function(test)
-- Append first trigger
trigger_list(trigger_cnt)
trigger_list:run()
- test:is(cnt, 1, "check first run")
+ testcase:is(cnt, 1, "check first run")
-- Append second trigger
trigger_list(trigger_cnt)
trigger_list:run()
- test:is(cnt, 3, "check first run")
+ testcase:is(cnt, 3, "check first run")
-- Check listing
local list_copy = trigger_list()
- test:is(#list_copy, 2, "trigger() count")
+ testcase:is(#list_copy, 2, "trigger() count")
table.remove(list_copy)
- test:is(#trigger_list(), 2, "check that we've returned copy")
+ testcase:is(#trigger_list(), 2, "check that we've returned copy")
-- Delete both triggers
- test:is(trigger_list(nil, trigger_cnt), trigger_cnt, "pop trigger")
+ testcase:is(trigger_list(nil, trigger_cnt), trigger_cnt, "pop trigger")
trigger_list:run()
- test:is(#trigger_list(), 1, "check trigger count after delete")
- test:is(cnt, 4, "check third run")
- test:is(trigger_list(nil, trigger_cnt), trigger_cnt, "pop trigger")
+ testcase:is(#trigger_list(), 1, "check trigger count after delete")
+ testcase:is(cnt, 4, "check third run")
+ testcase:is(trigger_list(nil, trigger_cnt), trigger_cnt, "pop trigger")
trigger_list:run()
- test:is(#trigger_list(), 0, "check trigger count after delete")
+ testcase:is(#trigger_list(), 0, "check trigger count after delete")
-- 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")
+ testcase:ok(string.find(err, "is not found"), "check error")
end)
-test:test("errored trigger test", function(test)
- test:plan(6)
+test:test("errored trigger test", function(testcase)
+ testcase:plan(6)
--
-- Check that trigger:run() fails on the first error
@@ -61,27 +61,27 @@ test:test("errored trigger test", function(test)
local function trigger_cnt() cnt = cnt + 1 end
local function trigger_errored() error("test error") end
- test:is(#trigger_list(), 0, "check for empty triggers")
+ testcase:is(#trigger_list(), 0, "check for empty triggers")
-- Append first trigger
trigger_list(trigger_cnt)
trigger_list:run()
- test:is(cnt, 1, "check simple trigger")
+ testcase:is(cnt, 1, "check simple trigger")
-- Append errored trigger
trigger_list(trigger_errored)
- local status = pcall(function() trigger_list:run() end)
- test:is(cnt, 2, "check simple+error trigger")
+ pcall(function() trigger_list:run() end)
+ testcase:is(cnt, 2, "check simple+error trigger")
-- Flush triggers
table_clear(trigger_list)
- test:is(#trigger_list(), 0, "successfull flush")
+ testcase:is(#trigger_list(), 0, "successfull flush")
-- Append first trigger
trigger_list(trigger_errored)
- local status = pcall(function() trigger_list:run() end)
- test:is(cnt, 2, "check error trigger")
+ pcall(function() trigger_list:run() end)
+ testcase:is(cnt, 2, "check error trigger")
-- Append errored trigger
trigger_list(trigger_cnt)
- local status = pcall(function() trigger_list:run() end)
- test:is(cnt, 2, "check error+simple trigger")
+ pcall(function() trigger_list:run() end)
+ testcase:is(cnt, 2, "check error+simple trigger")
end)
os.exit(test:check() == true and 0 or -1)
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")
--
2.26.2
More information about the Tarantool-patches
mailing list