Skip to content

Commit

Permalink
test: fix luacheck warnings W113 in test/sql-tap
Browse files Browse the repository at this point in the history
W113 (Accessing an undefined global variable)

Part of #5464

(cherry picked from commit 4e7e099)
  • Loading branch information
ligurio authored and kyukhin committed Mar 2, 2021
1 parent e2bf0b9 commit e3c6359
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 130 deletions.
2 changes: 0 additions & 2 deletions .luacheckrc
Expand Up @@ -51,8 +51,6 @@ exclude_files = {

files["test/sql-tap/**/*.lua"] = {
ignore = {
-- Accessing an undefined global variable.
"113",
-- Unused local variable.
"211",
-- Unused argument.
Expand Down
9 changes: 9 additions & 0 deletions test/sql-tap/analyze5.test.lua
Expand Up @@ -26,6 +26,10 @@ local function eqp(sql)
return test:execsql("EXPLAIN QUERY PLAN"..sql)
end

-- Legacy from the original code. Must be replaced with analogue
-- function.
local X = nil

local function alpha(blob)
local ret = ""
for _, c in ipairs(X(37, "X!cmd", [=[["split",["blob"],""]]=])) do
Expand Down Expand Up @@ -155,6 +159,11 @@ test:do_test(

-- Verify that range queries generate the correct row count estimates
--
-- Legacy from the original code. Must be replaced with analogue
-- functions.
local t1x = nil
local t1y = nil
local t1z = nil
for i, v in pairs({
{'z>=0 AND z<=0', t1z, 400},
{'z>=1 AND z<=1', t1z, 300},
Expand Down
8 changes: 5 additions & 3 deletions test/sql-tap/badutf1.test.lua
Expand Up @@ -93,8 +93,11 @@ test:do_test(
})

-- commented as it uses utf16
if 0>0 then
sql("db2", "")
-- testcases are broken
-- https://github.com/tarantool/tarantool/issues/5743
local is_gh_5743_closed = false
if is_gh_5743_closed then
local sql_exec = nil
test:do_test(
"badutf-1.10",
function()
Expand Down Expand Up @@ -208,7 +211,6 @@ test:do_test(
end



test:do_test(
"badutf-3.1",
function()
Expand Down
13 changes: 9 additions & 4 deletions test/sql-tap/cast.test.lua
Expand Up @@ -786,13 +786,18 @@ test:do_execsql_test(
-- Test to see if it is possible to trick sql into reading past
-- the end of a blob when converting it to a number.
if 0 > 0 then
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local sql_prepare = nil
local sql_bind_blob = nil
local sql_step = nil
local sql_column_int = nil
local STMT
test:do_test(
"cast-3.32.1",
function()
local blob, DB, STMT
blob = 1234567890
DB = sql_connection_pointer("db")
STMT = sql_prepare(DB, "SELECT CAST(? AS NUMBER)", -1, "TAIL")
local blob = 1234567890
STMT = sql_prepare("SELECT CAST(? AS NUMBER)", -1, "TAIL")
sql_bind_blob("-static", STMT, 1, blob, 5)
return sql_step(STMT)
end, {
Expand Down
33 changes: 30 additions & 3 deletions test/sql-tap/e_expr.test.lua
Expand Up @@ -1078,17 +1078,31 @@ test:do_execsql_test(
-- MUST_WORK_TEST prepared statements
if (0>0) then
local function parameter_test(tn, sql, params, result)
local stmt = sql_prepare_v2("db", sql, -1)
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
local sql_prepare_v2 = nil
local sql_bind_parameter_name = nil
local sql_bind_int = nil
local number = nil
local stmt = sql_prepare_v2(sql, -1)
for _ in X(0, "X!foreach", [=[["number name",["params"]]]=]) do
local nm = sql_bind_parameter_name(stmt, number)
X(480, "X!cmd", [=[["do_test",[["tn"],".name.",["number"]],[["list","set","",["nm"]]],["name"]]]=])
sql_bind_int(stmt, number, ((-1) * number))
end
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local sql_column_text = nil
local sql_step = nil
sql_step(stmt)
local res = { }
for _ in X(0, "X!for", [=[["set i 0","$i < [sql_column_count $stmt]","incr i"]]=]) do
for i in X(0, "X!for", [=[["set i 0","$i < [sql_column_count $stmt]","incr i"]]=]) do
table.insert(res,sql_column_text(stmt, i))
end
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local sql_finalize = nil
local rc = sql_finalize(stmt)
X(491, "X!cmd", [=[["do_test",[["tn"],".rc"],[["list","set","",["rc"]]],"sql_OK"]]=])
X(492, "X!cmd", [=[["do_test",[["tn"],".res"],[["list","set","",["res"]]],["result"]]]=])
Expand Down Expand Up @@ -1123,10 +1137,15 @@ if (0>0) then
-- EVIDENCE-OF: R-14068-49671 Parameters that are not assigned values
-- using sql_bind() are treated as NULL.
--
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local sql_prepare_v2 = nil
local sql_column_type = nil
local sql_step = nil
test:do_test(
"e_expr-11.7.1",
function()
local stmt = sql_prepare_v2("db", " SELECT ?, :a, @b, ?d ", -1)
local stmt = sql_prepare_v2(" SELECT ?, :a, @b, ?d ", -1)
sql_step(stmt)
return { sql_column_type(stmt, 0), sql_column_type(stmt, 1), sql_column_type(stmt, 2), sql_column_type(stmt, 3) }
end, {
Expand All @@ -1135,6 +1154,9 @@ if (0>0) then
-- </e_expr-11.7.1>
})

-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local stmt = nil
test:do_sql_finalize_test(
"e_expr-11.7.1",
stmt, {
Expand Down Expand Up @@ -2289,6 +2311,8 @@ test:do_execsql_test(
-- </e_expr-17.2.3>
})

-- Legacy from the original code. Must be replaced with analogue functions.
local db = nil
-- MUST_WORK_TEST uses access to nullvalue... (sql parameters) and built in functions
if 0>0 then
db("nullvalue", "null")
Expand Down Expand Up @@ -2677,6 +2701,9 @@ if 0>0 then
-- comparisons take place.
--

-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
for _ in X(0, "X!foreach", [=[["a b c",[["list",[["expr","3"]],[["expr","4"]],[["expr","5"]]]]]]=]) do
break
end
Expand Down
30 changes: 29 additions & 1 deletion test/sql-tap/e_select1.test.lua
Expand Up @@ -503,6 +503,10 @@ if (0 > 0)
-- left-hand side of the comparison operator (=) for the purposes of
-- collation sequence and affinity precedence.
--

-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
test:do_execsql_test(
"e_select-1.6.0",
[[
Expand All @@ -520,6 +524,10 @@ if (0 > 0)
-- </e_select-1.6.0>
})

-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local res = nil
local tn = nil
for _ in X(0, "X!foreach", [=[["tn select res","\n 1 { SELECT * FROM t5 JOIN_PATTERN t6 USING (a) } {AA cc cc BB dd DD}\n 2 { SELECT * FROM t6 JOIN_PATTERN t5 USING (a) } {}\n 3 { SELECT * FROM (SELECT a COLLATE "unicode_ci", b FROM t6) JOIN_PATTERN t5 USING (a) } \n {aa cc cc bb DD dd}\n 4 { SELECT * FROM t5 JOIN_PATTERN t6 USING (a,b) } {AA cc}\n 5 { SELECT * FROM t6 JOIN_PATTERN t5 USING (a,b) } {}\n "]]=]) do
do_join_test("e_select-1.6."..tn, select, res)
end
Expand Down Expand Up @@ -834,6 +842,13 @@ end

-- MUST_WORK_TEST prepared statement
if 0>0 then
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
local sql_finalize = nil
local sql_prepare_v2 = nil
local nCol = nil
local tn = nil
for _ in X(0, "X!foreach", [=[["tn select nCol","\n 1 \"SELECT a,b,c FROM z1\" 3\n 2 \"SELECT a,b,c FROM z1 NATURAL JOIN z3\" 3\n 3 \"SELECT z1.a,z1.b,z1.c FROM z1 NATURAL JOIN z3\" 3\n 4 \"SELECT z3.a,z3.b FROM z1 NATURAL JOIN z3\" 2\n 5 \"SELECT z1.a,z1.b,z1.c, z3.a,z3.b FROM z1 NATURAL JOIN z3\" 5\n 6 \"SELECT 1, 2, z1.a,z1.b,z1.c FROM z1\" 5\n 7 \"SELECT a, a,b,c, b, c FROM z1\" 6\n"]]=]) do
local stmt = sql_prepare_v2("db", select, -1, "DUMMY")
test:do_sql_column_count_test(
Expand Down Expand Up @@ -961,6 +976,11 @@ test:do_select_tests(
--
-- MUST_WORK_TEST prepared statements
if 0>0 then
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
local sql_finalize = nil
local sql_prepare_v2 = nil
for _ in X(0, "X!foreach", [=[["tn select","\n 8.1 \"SELECT count(*) FROM a1\"\n 8.2 \"SELECT count(*) FROM a1 WHERE 0\"\n 8.3 \"SELECT count(*) FROM a1 WHERE 1\"\n 8.4 \"SELECT max(a1.one)+min(two), a1.one, two, * FROM a1, a2 WHERE 1\"\n 8.5 \"SELECT max(a1.one)+min(two), a1.one, two, * FROM a1, a2 WHERE 0\"\n"]]=]) do
-- Set $nRow to the number of rows returned by $select:
local stmt, nRow
Expand All @@ -973,6 +993,10 @@ for _ in X(0, "X!foreach", [=[["tn select","\n 8.1 \"SELECT count(*) FROM a1\"
local rc = sql_finalize(stmt)
-- Test that $nRow==1 and that statement execution was successful
-- (rc==sql_OK).

-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
X(983, "X!cmd", [=[["do_test",["e_select-4.",["tn"]],[["list","list",["rc"],["nRow"]]],"sql_OK 1"]]=])
end
end
Expand Down Expand Up @@ -1539,6 +1563,10 @@ test:do_select_tests(
--
-- MUST_WORK_TEST
if 0>0 then
-- Legacy from the original code. Must be replaced with analogue
-- functions and valid values.
local db = nil
local null = nil
db("nullvalue", "null")
test:do_select_tests(
"e_select-7.9",
Expand Down Expand Up @@ -2195,7 +2223,7 @@ test:do_select_tests(
{"1", "SELECT b FROM f1 ORDER BY a LIMIT 0 ", {}},
{"2", "SELECT b FROM f1 ORDER BY a DESC LIMIT 4 ", {"z", "y", "x", "w"}},
{"3", "SELECT b FROM f1 ORDER BY a DESC LIMIT 8 ", {"z", "y", "x", "w", "v", "u", "t", "s"}},
{"4", "SELECT b FROM f1 ORDER BY a DESC LIMIT 12 ", {"z", y, "x", "w", "v", "u", "t", "s", "r", "q", "p", "o"}},
{"4", "SELECT b FROM f1 ORDER BY a DESC LIMIT 12 ", {"z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o"}},
})

-- EVIDENCE-OF: R-54935-19057 Or, if the SELECT statement would return
Expand Down
29 changes: 21 additions & 8 deletions test/sql-tap/func.test.lua
Expand Up @@ -1048,7 +1048,9 @@ test:do_execsql_test(
--
-- MUST_WORK_TEST testfunc not implemented
if 0 > 0 then
local DB = sql_connection_pointer("db")
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
X(525, "X!cmd", [=[["sql_register_test_function",["::DB"],"testfunc"]]=])
test:do_catchsql_test(
"func-10.1",
Expand Down Expand Up @@ -1142,6 +1144,17 @@ end
--
-- MUST_WORK_TEST test_destructor_count not implemented
if 0 > 0 then
local X = nil
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local sql_prepare = nil
local sql_bind_text = nil
local sql_bind_blob = nil
local sql_column_text = nil
local sql_step = nil
local sql_finalize = nil
local db = nil

if X(595, "X!cmd", "[\"expr\",\"[db eval {PRAGMA encoding}]==\\\"UTF-8\\\"\"]")
then
test:do_execsql_test(
Expand Down Expand Up @@ -1300,10 +1313,9 @@ test:do_execsql_test(
test:do_test(
"func-13.7",
function()
local DB, sql, STMT, res
DB = sql_connection_pointer("db")
local sql, STMT, res
sql = "SELECT test_auxdata( ? , a ) FROM t4;"
STMT = sql_prepare(DB, sql, -1, "TAIL")
STMT = sql_prepare(sql, -1, "TAIL")
sql_bind_text(STMT, 1, "hello\0", -1)
res = { }
while X(690, "X!cmd", [=[["expr"," \"sql_ROW\"==[sql_step $STMT] "]]=])
Expand Down Expand Up @@ -1455,7 +1467,7 @@ test:do_test(
test:execsql([[
CREATE TABLE tbl2(id integer primary key, a INT, b INT);
]])
local STMT = sql_prepare(DB, "INSERT INTO tbl2 VALUES(1, ?, ?)", -1, "TAIL")
local STMT = sql_prepare("INSERT INTO tbl2 VALUES(1, ?, ?)", -1, "TAIL")
sql_bind_blob(STMT, 1, "abc", 3)
sql_step(STMT)
sql_finalize(STMT)
Expand Down Expand Up @@ -2439,6 +2451,7 @@ test:do_execsql_test(
--
-- MUST_WORK_TEST
if 0>0 then
local X = nil
test:do_execsql_test(
"func-25.1",
[[
Expand Down Expand Up @@ -2470,7 +2483,7 @@ test:do_test(
"func-26.2",
function()
local a = ""
for _ in X(0, "X!for", [=[["set i 1","$i<=$::sql_MAX_FUNCTION_ARG","incr i"]]=]) do
for i in X(0, "X!for", [=[["set i 1","$i<=$::sql_MAX_FUNCTION_ARG","incr i"]]=]) do
table.insert(a,i)
end
return test:execsql(string.format([[
Expand All @@ -2486,7 +2499,7 @@ test:do_test(
"func-26.3",
function()
local a = ""
for _ in X(0, "X!for", [=[["set i 1","$i<=$::sql_MAX_FUNCTION_ARG+1","incr i"]]=]) do
for i in X(0, "X!for", [=[["set i 1","$i<=$::sql_MAX_FUNCTION_ARG+1","incr i"]]=]) do
table.insert(a,i)
end
return test:catchsql(string.format([[
Expand All @@ -2502,7 +2515,7 @@ test:do_test(
"func-26.4",
function()
local a = ""
for _ in X(0, "X!for", [=[["set i 1","$i<=$::sql_MAX_FUNCTION_ARG-1","incr i"]]=]) do
for i in X(0, "X!for", [=[["set i 1","$i<=$::sql_MAX_FUNCTION_ARG-1","incr i"]]=]) do
table.insert(a,i)
end
return test:catchsql(string.format([[
Expand Down
4 changes: 3 additions & 1 deletion test/sql-tap/index1.test.lua
Expand Up @@ -585,7 +585,9 @@ test:do_test(
for i = 1, 50, 1 do
test:execsql(string.format("INSERT INTO t3 VALUES('x%sx',%s,0.%s)", i, i, i))
end
local sql_search_count = 0
-- Legacy from the original code. Must be replaced with analogue
-- functions from box.
local X = nil
return X(381, "X!cmd", [=[["concat",[["execsql","SELECT c FROM t3 WHERE b==10"]],["sql_search_count"]]]=])
end, {
-- <index-11.1>
Expand Down
3 changes: 3 additions & 0 deletions test/sql-tap/lua/sqltester.lua
Expand Up @@ -85,6 +85,9 @@ local function is_deeply_regex(got, expected)
return (got - expected < min_delta) and (expected - got < min_delta)
end

-- Legacy from the original code. Must be replaced with analogue
-- function.
local table_match_regex_p = nil
if string_regex_p(expected) then
return table_match_regex_p(got, expected)
end
Expand Down
8 changes: 6 additions & 2 deletions test/sql-tap/lua_sql.test.lua
Expand Up @@ -51,7 +51,7 @@ for _, val in ipairs({
{result})
end

_G.from_sql_to_lua = {
local from_sql_to_lua = {
[1] = {1, 1},
[2] = {"1", 1},
[3] = {"1.5", 1.5},
Expand All @@ -61,6 +61,8 @@ _G.from_sql_to_lua = {
[7] = {"123123123123123", 123123123123123LL},
}

_G.from_sql_to_lua = from_sql_to_lua

box.schema.func.create('CHECK_FROM_SQL_TO_LUA', {language = 'Lua',
is_deterministic = true,
body = [[
Expand All @@ -82,7 +84,7 @@ for i = 1, #from_sql_to_lua, 1 do
{1})
end

_G.from_lua_to_sql = {
local from_lua_to_sql = {
[1] = {1, 1},
[2] = {"1.5", 1.5},
[3] = {"'1'", "1"},
Expand All @@ -91,6 +93,8 @@ _G.from_lua_to_sql = {
[6] = {12, 12LL},
}

_G.from_lua_to_sql = from_lua_to_sql

box.schema.func.create('CHECK_FROM_LUA_TO_SQL', {language = 'Lua',
is_deterministic = true,
body = [[
Expand Down

0 comments on commit e3c6359

Please sign in to comment.