1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add unittest that lints builtin JSON files

This commit is contained in:
sfan5 2025-02-26 19:16:41 +01:00
parent 304ce4cd54
commit 47c000a293
2 changed files with 30 additions and 0 deletions

View file

@ -189,6 +189,29 @@ local function test_write_json()
end
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 info = core.get_game_info()
local game_conf = Settings(info.path .. "/game.conf")