Skip to content

Commit 70fe1e5

Browse files
Tarantool: add new fields from 2.3.1
1 parent f7e7eed commit 70fe1e5

File tree

4 files changed

+150
-48
lines changed

4 files changed

+150
-48
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Add SonarQube formatter.
6+
* Tarantool: add new fields from 2.3.1.
67
* Tarantool: Add rules for box.session.
78
Fixes warnings for writing to box.session.storage.
89

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
local luacheck = require "luacheck"
2+
3+
local function get_report(source, standard)
4+
source = source:gsub('\n%s+$', '\n')
5+
local report = luacheck.process_reports({luacheck.get_report(source)}, {std = standard or "tarantool"})
6+
local events = {}
7+
local slice_fields = {"code", "name", "field", "indexing"}
8+
for _, event in ipairs(report[1]) do
9+
local new_event = {}
10+
for _, field in ipairs(slice_fields) do
11+
new_event[field] = event[field]
12+
end
13+
table.insert(events, new_event)
14+
end
15+
return events
16+
end
17+
18+
describe("Tarantool standard", function()
19+
it("differs from `max` standard", function()
20+
local source = [[
21+
box.backup.start()
22+
box.schema.space.create()
23+
package.setsearchroot()
24+
box.backup.invalid()
25+
package.invalid()
26+
]]
27+
assert.same({
28+
{code = "143", name = "box", field = "backup.invalid", indexing = {"backup", "invalid"}},
29+
{code = "143", name = "package", field = "invalid", indexing = {"invalid"}},
30+
}, get_report(source))
31+
assert.same({
32+
{code = "113", name = "box", indexing = {"backup", "start"}},
33+
{code = "113", name = "box", indexing = {"schema", "space", "create"}},
34+
{code = "143", name = "package", field = "setsearchroot", indexing = {"setsearchroot"}},
35+
{code = "113", name = "box", indexing = {"backup", "invalid"}},
36+
{code = "143", name = "package", field = "invalid", indexing = {"invalid"}},
37+
}, get_report(source, "max"))
38+
end)
39+
40+
it("knows all globals", function()
41+
-- local x = require('fun').iter(_G):totable() table.sort(x) return x
42+
assert.same({}, get_report([[
43+
print({
44+
_TARANTOOL,
45+
_VERSION,
46+
arg,
47+
assert,
48+
bit,
49+
box,
50+
collectgarbage,
51+
coroutine,
52+
debug,
53+
dofile,
54+
dostring,
55+
error,
56+
gcinfo,
57+
getfenv,
58+
getmetatable,
59+
io,
60+
ipairs,
61+
jit,
62+
load,
63+
loadfile,
64+
loadstring,
65+
math,
66+
module,
67+
newproxy,
68+
next,
69+
os,
70+
package,
71+
pairs,
72+
pcall,
73+
print,
74+
rawequal,
75+
rawget,
76+
rawset,
77+
require,
78+
select,
79+
setfenv,
80+
setmetatable,
81+
string,
82+
table,
83+
tonumber,
84+
tonumber64,
85+
tostring,
86+
type,
87+
unpack,
88+
xpcall,
89+
})
90+
]]))
91+
end)
92+
93+
it("knows all box fields", function()
94+
-- box.cfg{} local x = require('fun').iter(box):totable() table.sort(x) return x
95+
assert.same({}, get_report([[
96+
print({
97+
box.NULL,
98+
box.atomic,
99+
box.backup,
100+
box.begin,
101+
box.cfg,
102+
box.commit,
103+
box.ctl,
104+
box.error,
105+
box.execute,
106+
box.feedback,
107+
box.func,
108+
box.index,
109+
box.info,
110+
box.internal,
111+
box.is_in_txn,
112+
box.on_commit,
113+
box.on_rollback,
114+
box.once,
115+
box.prepare,
116+
box.priv,
117+
box.rollback,
118+
box.rollback_to_savepoint,
119+
box.runtime,
120+
box.savepoint,
121+
box.schema,
122+
box.sequence,
123+
box.session,
124+
box.slab,
125+
box.snapshot,
126+
box.space,
127+
box.stat,
128+
box.tuple,
129+
box.unprepare,
130+
})
131+
]]))
132+
end)
133+
134+
it('allows to write to box.session.storage', function()
135+
assert.same({
136+
{code = "143", name = "box", field = "session.invalid", indexing = {"session", "invalid"}},
137+
}, get_report([[
138+
box.session.storage.field1 = 1
139+
box.session.storage["field11"] = 1
140+
print(box.session.storage.field2, box.session.storage["field22"])
141+
box.session.push()
142+
box.session.invalid()
143+
]]))
144+
end)
145+
end)

spec/luacheck_spec.lua

-47
Original file line numberDiff line numberDiff line change
@@ -499,53 +499,6 @@ describe("process_reports", function()
499499
std = "none"
500500
})))
501501
end)
502-
503-
-- There is no place to test standards.
504-
it("works with tarantool std", function()
505-
local source = [[
506-
box.backup.start()
507-
box.schema.space.create()
508-
package.setsearchroot()
509-
box.backup.invalid()
510-
package.invalid()
511-
]]
512-
assert.same({
513-
{
514-
{code = "143", name = "box", field = "backup.invalid", indexing = {"backup", "invalid"}},
515-
{code = "143", name = "package", field = "invalid", indexing = {"invalid"}},
516-
},
517-
warnings = 2,
518-
errors = 0,
519-
fatals = 0
520-
}, strip_locations(luacheck.process_reports({luacheck.get_report(source)}, {std = "tarantool"})))
521-
assert.same({
522-
{
523-
{code = "113", name = "box", indexing = {"backup", "start"}},
524-
{code = "113", name = "box", indexing = {"schema", "space", "create"}},
525-
{code = "143", name = "package", field = "setsearchroot", indexing = {"setsearchroot"}},
526-
{code = "113", name = "box", indexing = {"backup", "invalid"}},
527-
{code = "143", name = "package", field = "invalid", indexing = {"invalid"}},
528-
},
529-
warnings = 5,
530-
errors = 0,
531-
fatals = 0
532-
}, strip_locations(luacheck.process_reports({luacheck.get_report(source)}, {std = "max"})))
533-
534-
assert.same({
535-
{
536-
{code = "143", name = "box", field = "session.invalid", indexing = {"session", "invalid"}},
537-
},
538-
warnings = 1,
539-
errors = 0,
540-
fatals = 0,
541-
}, strip_locations(luacheck.process_reports({luacheck.get_report([[
542-
box.session.storage.field1 = 1
543-
box.session.storage['field11'] = 1
544-
print(box.session.storage.field2, box.session.storage['field22'])
545-
box.session.push()
546-
box.session.invalid()
547-
]])}, {std = "tarantool"})))
548-
end)
549502
end)
550503

551504
describe("get_message", function()

src/luacheck/builtin_standards/tarantool.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
local standards = require "luacheck.standards"
22

33
local box_defs = standards.def_fields(
4-
'execute',
54
'NULL',
5+
'execute',
6+
'prepare',
7+
'unprepare',
68
'once',
79
'snapshot',
810
-- https://www.tarantool.io/en/doc/2.2/book/box/box_txn_management/
@@ -41,6 +43,7 @@ local box_table_fields = {
4143
'tuple',
4244
'schema',
4345
'feedback',
46+
'func',
4447
'info',
4548
'ctl',
4649
'index',

0 commit comments

Comments
 (0)