mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
Add unittest that lints builtin JSON files
This commit is contained in:
parent
304ce4cd54
commit
47c000a293
2 changed files with 30 additions and 0 deletions
|
@ -189,6 +189,29 @@ local function test_write_json()
|
||||||
end
|
end
|
||||||
unittests.register("test_write_json", test_write_json)
|
unittests.register("test_write_json", test_write_json)
|
||||||
|
|
||||||
|
local function lint_json_files()
|
||||||
|
-- Check that files we ship with Luanti are valid JSON
|
||||||
|
local stack = {core.get_builtin_path()}
|
||||||
|
local checked = 0
|
||||||
|
while #stack > 0 do
|
||||||
|
local path = table.remove(stack)
|
||||||
|
for _, name in ipairs(core.get_dir_list(path, true)) do
|
||||||
|
stack[#stack+1] = path .. "/" .. name
|
||||||
|
end
|
||||||
|
for _, name in ipairs(core.get_dir_list(path, false)) do
|
||||||
|
if name:match("%.json$") then
|
||||||
|
local f = io.open(path .. "/" .. name, "rb")
|
||||||
|
print(path .. "/" .. name)
|
||||||
|
assert(core.parse_json(f:read("*all"), -1) ~= nil)
|
||||||
|
f:close()
|
||||||
|
checked = checked + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert(checked > 0, "no files found?!")
|
||||||
|
end
|
||||||
|
unittests.register("lint_json_files", lint_json_files)
|
||||||
|
|
||||||
local function test_game_info()
|
local function test_game_info()
|
||||||
local info = core.get_game_info()
|
local info = core.get_game_info()
|
||||||
local game_conf = Settings(info.path .. "/game.conf")
|
local game_conf = Settings(info.path .. "/game.conf")
|
||||||
|
|
|
@ -659,6 +659,13 @@ bool ScriptApiSecurity::checkPathWithGamedef(lua_State *L,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow read-only access to builtin
|
||||||
|
if (!write_required) {
|
||||||
|
str = fs::AbsolutePath(Server::getBuiltinLuaPath());
|
||||||
|
if (!str.empty() && fs::PathStartsWith(abs_path, str))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Allow read-only access to game directory
|
// Allow read-only access to game directory
|
||||||
if (!write_required) {
|
if (!write_required) {
|
||||||
const SubgameSpec *game_spec = gamedef->getGameSpec();
|
const SubgameSpec *game_spec = gamedef->getGameSpec();
|
||||||
|
|
Loading…
Add table
Reference in a new issue