|
| 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) |
0 commit comments