[Tarantool-patches] [PATCH 1/3] luacheck: fix warnings in test/box

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Jan 13 19:38:16 MSK 2021


Hi! Thanks for the fixes!

Consider my fixes on top of this commit on the branch, and below with
explanations.

==================================================
diff --git a/.luacheckrc b/.luacheckrc
index 749574378..0ff90450e 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -115,8 +115,3 @@ files["test/box/box.lua"] = {
         "iproto_request",
     }
 }
-files["test/box/lua/bitset.lua"] = {
-    globals = {
-        "dump",
-    }
-}
====================

You don't need to ignore it, because it works fine when declared
'local'. It does not prevent its usage inside of the module, because
local or not, it is still 'global' inside the file.

The only problem was in the test, where it was also saved to a local
variable. Which won't work in non-tap tests, because each line here
is executed as a script. It means, 'local' variables are not visible
out of the line where they are declared. I removed 'local' from the
test file, and it allowed not to ignore anything in bitset.lua.

====================
diff --git a/test/box/bitset.result b/test/box/bitset.result
index 3296f66d8..af3384d3f 100644
--- a/test/box/bitset.result
+++ b/test/box/bitset.result
@@ -1,7 +1,7 @@
 bset = require('bitset')
 ---
 ...
-local dump = bset.dump
+dump = bset.dump
 ---
 ...
 bset.create_space()
diff --git a/test/box/bitset.test.lua b/test/box/bitset.test.lua
index c56a7e1a4..cb7c408f5 100644
--- a/test/box/bitset.test.lua
+++ b/test/box/bitset.test.lua
@@ -1,6 +1,6 @@
 bset = require('bitset')
 
-local dump = bset.dump
+dump = bset.dump
 bset.create_space()
 
 ------------------------------------------------------------------------------
diff --git a/test/box/lua.result b/test/box/lua.result
index 409ab7e8f..4c14f200d 100644
--- a/test/box/lua.result
+++ b/test/box/lua.result
@@ -625,46 +625,46 @@ space = box.schema.space.create('tweedledum')
 tmp = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}, unique = true })
 ---
 ...
-push = require('push')
+push_collection = require('push')
====================

This allowed to revert some big diff from your changes. Everything
below turns into no-diff when squashed into your commit.

====================
 ---
 ...
-push.push_collection(space, 0, 1038784, 'hello')
+push_collection(space, 0, 1038784, 'hello')
 ---
 - [1038784, 'hello']
 ...
-push.push_collection(space, 0, 1038784, 'hello')
+push_collection(space, 0, 1038784, 'hello')
 ---
 - [1038784]
 ...
-push.push_collection(space, 0, 1038784, 'hello')
+push_collection(space, 0, 1038784, 'hello')
 ---
 - [1038784]
 ...
-push.push_collection(space, 1, 1038784, 'hi')
+push_collection(space, 1, 1038784, 'hi')
 ---
 - [1038784, 'hi']
 ...
-push.push_collection(space, 2, 1038784, 'hi')
+push_collection(space, 2, 1038784, 'hi')
 ---
 - [1038784, 'hi', 'hi']
 ...
-push.push_collection(space, 2, 1038784, 'hi')
+push_collection(space, 2, 1038784, 'hi')
 ---
 - [1038784, 'hi', 'hi']
 ...
-push.push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
 ---
 - [1038784, 'hi', 'hi', 'hey']
 ...
-push.push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
 ---
 - [1038784, 'hi', 'hi', 'hey', 'hey']
 ...
-push.push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
 ---
 - [1038784, 'hi', 'hi', 'hey', 'hey', 'hey']
 ...
-push.push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
 ---
 - [1038784, 'hi', 'hey', 'hey', 'hey', 'hey']
 ...
@@ -752,7 +752,7 @@ space:drop()
 --
 -- index:random test
 -- 
-test = require('index_random_test')
+index_random_test = require('index_random_test')
 ---
 ...
 space = box.schema.space.create('tweedledum')
@@ -767,14 +767,14 @@ tmp = space:create_index('secondary', { type = 'hash', parts = {1, 'unsigned'},
 -------------------------------------------------------------------------------
 -- TreeIndex::random()
 -------------------------------------------------------------------------------
-test.index_random_test(space, 'primary')
+index_random_test(space, 'primary')
 ---
 - true
 ...
 -------------------------------------------------------------------------------
 -- HashIndex::random()
 -------------------------------------------------------------------------------
-test.index_random_test(space, 'secondary')
+index_random_test(space, 'secondary')
 ---
 - true
 ...
diff --git a/test/box/lua.test.lua b/test/box/lua.test.lua
index 8d429a7e3..9762e07eb 100644
--- a/test/box/lua.test.lua
+++ b/test/box/lua.test.lua
@@ -225,20 +225,20 @@ space:drop()
 
 space = box.schema.space.create('tweedledum')
 tmp = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}, unique = true })
-push = require('push')
+push_collection = require('push')
 
-push.push_collection(space, 0, 1038784, 'hello')
-push.push_collection(space, 0, 1038784, 'hello')
-push.push_collection(space, 0, 1038784, 'hello')
+push_collection(space, 0, 1038784, 'hello')
+push_collection(space, 0, 1038784, 'hello')
+push_collection(space, 0, 1038784, 'hello')
 
-push.push_collection(space, 1, 1038784, 'hi')
-push.push_collection(space, 2, 1038784, 'hi')
-push.push_collection(space, 2, 1038784, 'hi')
+push_collection(space, 1, 1038784, 'hi')
+push_collection(space, 2, 1038784, 'hi')
+push_collection(space, 2, 1038784, 'hi')
 
-push.push_collection(space, 5, 1038784, 'hey')
-push.push_collection(space, 5, 1038784, 'hey')
-push.push_collection(space, 5, 1038784, 'hey')
-push.push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
+push_collection(space, 5, 1038784, 'hey')
 
 -- # lua box.auto_increment() testing
 -- # http://bugs.launchpad.net/tarantool/+bug/1006354
@@ -277,7 +277,7 @@ space:drop()
 --
 -- index:random test
 -- 
-test = require('index_random_test')
+index_random_test = require('index_random_test')
 space = box.schema.space.create('tweedledum')
 tmp = space:create_index('primary', { type = 'tree', parts = {1, 'unsigned'}, unique = true })
 tmp = space:create_index('secondary', { type = 'hash', parts = {1, 'unsigned'}, unique = true })
@@ -285,13 +285,13 @@ tmp = space:create_index('secondary', { type = 'hash', parts = {1, 'unsigned'},
 -- TreeIndex::random()
 -------------------------------------------------------------------------------
 
-test.index_random_test(space, 'primary')
+index_random_test(space, 'primary')
 
 -------------------------------------------------------------------------------
 -- HashIndex::random()
 -------------------------------------------------------------------------------
 
-test.index_random_test(space, 'secondary')
+index_random_test(space, 'secondary')
 
 space:drop()
 space = nil
diff --git a/test/box/lua/bitset.lua b/test/box/lua/bitset.lua
index 3420727cf..245e9f097 100644
--- a/test/box/lua/bitset.lua
+++ b/test/box/lua/bitset.lua
@@ -32,7 +32,7 @@ local function drop_space()
     box.space['tweedledum']:drop()
 end
 
-function dump(...)
+local function dump(...)
 	return utils.iterate('tweedledum', 'bitset', 1, 2, ...)
 end
 
@@ -50,11 +50,11 @@ local function test_insert_delete(n)
 end
 
 return {
-    clear = clear;
-    create_space = create_space;
-    delete = delete;
-    drop_space = drop_space;
-    dump = dump;
-    fill = fill;
-    test_insert_delete = test_insert_delete;
+    clear = clear,
+    create_space = create_space,
+    delete = delete,
+    drop_space = drop_space,
+    dump = dump,
+    fill = fill,
+    test_insert_delete = test_insert_delete,
====================

We don't use ';' anywhere. It may still be used in some old code,
but not in the new code. I have no idea though if it is stated
anywhere formally.

====================
 }
diff --git a/test/box/lua/fifo.lua b/test/box/lua/fifo.lua
index 9003904e2..3288c8be8 100644
--- a/test/box/lua/fifo.lua
+++ b/test/box/lua/fifo.lua
@@ -32,8 +32,8 @@ local function fifo_top(space, name)
 end
 
 return {
-    find_or_create_fifo = find_or_create_fifo;
-    fifo_push = fifo_push;
-    fifo_top = fifo_top;
-    fifomax = fifomax;
+    find_or_create_fifo = find_or_create_fifo,
+    fifo_push = fifo_push,
+    fifo_top = fifo_top,
+    fifomax = fifomax,
 };
diff --git a/test/box/lua/index_random_test.lua b/test/box/lua/index_random_test.lua
index b6248c07c..d8622a4db 100644
--- a/test/box/lua/index_random_test.lua
+++ b/test/box/lua/index_random_test.lua
@@ -40,6 +40,4 @@ local function index_random_test(space, index_no)
 	return true
 end
 
-return {
-	index_random_test = index_random_test;
-}
+return index_random_test
diff --git a/test/box/lua/push.lua b/test/box/lua/push.lua
index 7c9b36275..5ce0c12bc 100644
--- a/test/box/lua/push.lua
+++ b/test/box/lua/push.lua
@@ -1,4 +1,3 @@
-
 local function push_collection(space, size, cid, ...)
 	local append = { ... }
 	local tuple = space:get{cid}
@@ -15,6 +14,4 @@ local function push_collection(space, size, cid, ...)
 	return space:replace{tuple:unpack()}
 end
 
-return {
-	push_collection = push_collection;
-}
+return push_collection
diff --git a/test/box/lua/utils.lua b/test/box/lua/utils.lua
index 0eb427eb9..e6b3a6b57 100644
--- a/test/box/lua/utils.lua
+++ b/test/box/lua/utils.lua
@@ -209,11 +209,11 @@ end
 return {
     iterate = iterate;
     arithmetic = arithmetic;
-    create_iterator = create_iterator;
-    check_space = check_space;
     table_generate = table_generate;
     table_shuffle = table_shuffle;
     sort = sort;
+    check_space = check_space;
     space_bsize = space_bsize;
+    create_iterator = create_iterator;
====================

In your patch you somewhy moved these 2 functions. I moved
them back to reduce diff.

====================
     setmap = setmap;
 };


More information about the Tarantool-patches mailing list