Skip to content

Commit

Permalink
luacheck: change global vars to local in sql-tap
Browse files Browse the repository at this point in the history
Fixed luacheck warning 111 (setting non-standard global variable)
in test/sql-tap directory.
Enabled this directory for checking W111 in
config file(.luacheckrc).

Changed almost all variables in test/sql-tap from globals
to locals. In any cases, where variables need to be global,
added explicit _G. prefix (table of globals).

Fixes #5173
Part-of #5464
  • Loading branch information
artemreyt committed Dec 14, 2020
1 parent 9f3e1d0 commit 6356f57
Show file tree
Hide file tree
Showing 261 changed files with 633 additions and 549 deletions.
54 changes: 53 additions & 1 deletion .luacheckrc
Expand Up @@ -30,12 +30,64 @@ exclude_files = {
"build/**/*.lua",
-- Third-party source code.
"test-run/**/*.lua",
"test/**/*.lua",
"test/app/**/*.lua",
"test/app-tap/**/*.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/luajit-tap/**/*.lua",
"test/replication/**/*.lua",
"test/replication-py/**/*.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",
}

files["test/sql-tap/**/*.lua"] = {
ignore = {
-- Accessing an undefined global variable.
"113",
-- Unused local variable.
"211",
-- Unused argument.
"212",
-- Unused loop variable.
"213",
-- Local variable is set but never accessed.
"231",
-- "Value assigned to a local variable is unused."
"311",
-- Unreachable code.
"511",
-- Loop can be executed at most once.
"512",
-- An empty if branch.
"542",
-- A line consists of nothing but whitespace.
"611",
-- A line contains trailing whitespace.
"612",
-- Trailing whitespace in a string.
"613",
-- Trailing whitespace in a comment.
"614",
-- Inconsistent indentation (SPACE followed by TAB).
"621",
-- Line is too long.
"631"
}
}

files["src/lua/help.lua"] = {
-- Globals defined for interactive mode.
globals = {"help", "tutorial"},
Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/aggnested.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(7)

--!./tcltestrunner.lua
Expand Down
16 changes: 8 additions & 8 deletions test/sql-tap/alias.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(9)

--!./tcltestrunner.lua
Expand All @@ -24,7 +24,7 @@ test:plan(9)
-- A procedure to return a sequence of increasing integers.
--

counter = 0
_G.counter = 0

-- Function is declared as deterministic deliberately.
-- Otherwise it would be called as much as it occurs in a query.
Expand Down Expand Up @@ -54,7 +54,7 @@ test:do_test(
test:do_test(
"alias-1.2",
function()
counter = 0
_G.counter = 0
return test:execsql([[
SELECT x, sequence() AS y FROM t1 WHERE y> 0 order by x desc
]])
Expand All @@ -67,7 +67,7 @@ test:do_test(
test:do_test(
"alias-1.3",
function()
counter = 0
_G.counter = 0
return test:execsql([[
SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 order by x desc
]])
Expand All @@ -80,7 +80,7 @@ test:do_test(
test:do_test(
"alias-1.4",
function()
counter = 0
_G.counter = 0
return test:execsql([[
SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 AND y!=55 order by x desc
]])
Expand Down Expand Up @@ -108,7 +108,7 @@ test:do_test(
test:do_test(
"alias-1.6",
function()
counter = 0
_G.counter = 0
return test:execsql([[
SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99 order by x desc
]])
Expand All @@ -121,7 +121,7 @@ test:do_test(
test:do_test(
"alias-1.7",
function()
counter = 0
_G.counter = 0
return test:execsql([[
SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99 order by x desc
]])
Expand All @@ -147,7 +147,7 @@ test:do_test(
test:do_test(
"alias-1.9",
function()
counter = 0
_G.counter = 0
return test:execsql([[
SELECT x, sequence() AS y FROM t1 ORDER BY -y
]])
Expand Down
14 changes: 7 additions & 7 deletions test/sql-tap/alter.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(50)

test:do_execsql_test(
Expand Down Expand Up @@ -90,11 +90,11 @@ test:do_catchsql_test(
test:do_test(
"alter-2.3.prepare",
function()
format = {}
local format = {}
format[1] = { name = 'id', type = 'integer'}
format[2] = { name = 'f2', type = 'number'}
s = box.schema.create_space('t', {format = format})
i = s:create_index('i', {parts= {1, 'integer'}})
local s = box.schema.create_space('t', {format = format})
s:create_index('i', {parts= {1, 'integer'}})

s:replace{1, 4}
s:replace{2, 2}
Expand Down Expand Up @@ -520,10 +520,10 @@ test:do_catchsql_test(
test:do_test(
"alter-8.1.0",
function()
format = {}
local format = {}
format[1] = { name = 'id', type = 'scalar'}
format[2] = { name = 'f2', type = 'scalar'}
s = box.schema.create_space('T', {format = format})
box.schema.create_space('T', {format = format})
end,
{})

Expand Down Expand Up @@ -560,7 +560,7 @@ test:do_catchsql_test(
test:do_test(
"alter-8.3.2",
function()
i = box.space.T.index[1]
local i = box.space.T.index[1]
return i.id
end, 1)

Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/alter2.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(26)

-- This suite is aimed to test ALTER TABLE ADD CONSTRAINT statement.
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/analyze1.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(38)

--!./tcltestrunner.lua
Expand Down Expand Up @@ -384,7 +384,7 @@ test:do_execsql_test(
-- </analyze-5.0>
})

stat = "_sql_stat4"
local stat = "_sql_stat4"

test:do_execsql_test(
"analyze-5.1",
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/analyze3.test.lua
@@ -1,8 +1,8 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(37)

testprefix = "analyze3"
local testprefix = "analyze3"

--!./tcltestrunner.lua
-- 2009 August 06
Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/analyze4.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(4)

--!./tcltestrunner.lua
Expand Down
16 changes: 10 additions & 6 deletions test/sql-tap/analyze5.test.lua
@@ -1,8 +1,8 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(88)

json = require("json")
local json = require("json")

--!./tcltestrunner.lua
-- 2011 January 19
Expand All @@ -21,13 +21,13 @@ json = require("json")
-- with many repeated values and only a few distinct values.
--

testprefix = "analyze5"
local testprefix = "analyze5"
local function eqp(sql)
return test:execsql("EXPLAIN QUERY PLAN"..sql)
end

local function alpha(blob)
ret = ""
local ret = ""
for _, c in ipairs(X(37, "X!cmd", [=[["split",["blob"],""]]=])) do
if X(39, "X!cmd", [=[["string","is","alpha",["c"]]]=])
then
Expand Down Expand Up @@ -64,13 +64,14 @@ test:do_test(
-- test:execsql("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, t INT ,u INT ,v TEXT COLLATE nocase,w INT ,x INT ,y INT ,z INT )")
test:execsql("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, t TEXT ,u TEXT ,v TEXT ,w TEXT ,x TEXT ,y TEXT ,z NUMBER)")
for i=0,999 do -- _ in X(0, "X!for", [=[["set i 0","$i < 1000","incr i"]]=]) do
local y
if ((i >= 25) and (i <= 50)) then
y = 1
else
y = 0
end

z = 0
local z = 0
if i >= 400 then
z = 1
end
Expand All @@ -81,6 +82,7 @@ test:do_test(
z = z + 1
end

local x, w, t, u
x = z
w = z
t = (z + 0.5)
Expand All @@ -99,7 +101,7 @@ test:do_test(
-- if X(65, "X!cmd", [=[["expr","$i%2"]]=]) then
-- v = u
-- end
v = 'NULL'
local v = 'NULL'
test:execsql("INSERT INTO t1 (t,u,v,w,x,y,z) VALUES('"..t.."','"..u.."','"..v.."','"..w.."','"..x.."','"..y.."','"..z.."')")
end
test:execsql([[
Expand Down Expand Up @@ -252,6 +254,7 @@ for i, v in pairs({
test:do_test(
"analyze5-1."..i.."b",
function()
local w2, a1, a2, res
w2 = v[1]:gsub('y', '+y'):gsub('z', '+z')
a1 = test:execsql("SELECT id FROM t1 NOT INDEXED WHERE "..w2.." ORDER BY +id")
a2 = test:execsql("SELECT id FROM t1 WHERE "..v[1].." ORDER BY +id")
Expand Down Expand Up @@ -298,6 +301,7 @@ for i, v in pairs({
test:do_test(
"analyze5-1."..i.."b",
function()
local a1, a2, res
a1 = test:execsql("SELECT id FROM t1 NOT INDEXED WHERE "..v.." ORDER BY +id")
a2 = test:execsql("SELECT id FROM t1 WHERE "..v.." ORDER BY +id")
if (test.is_deeply_regex(a1, a1))
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/analyze6.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(13)

--!./tcltestrunner.lua
Expand All @@ -21,7 +21,7 @@ test:plan(13)
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]

testprefix = "analyze6"
local testprefix = "analyze6"

test:do_test(
"analyze6-1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/analyze7.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(14)

--!./tcltestrunner.lua
Expand Down
5 changes: 3 additions & 2 deletions test/sql-tap/analyze8.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(15)

--!./tcltestrunner.lua
Expand All @@ -18,7 +18,7 @@ test:plan(15)
-- in this file is testing the capabilities of sql_stat3.
--

testprefix = "analyze8"
local testprefix = "analyze8"

-- Scenario:
--
Expand All @@ -39,6 +39,7 @@ test:do_test(
CREATE INDEX t1c ON t1(c);
]])
for i=0, 1000 do
local a, b, c
if (i % 2 == 0)
then
a = i
Expand Down

0 comments on commit 6356f57

Please sign in to comment.