ci: prefer io.write instead of print to have full control of output

This should prevent different output formats on windows and unix.
This commit is contained in:
Dundar Göc 2022-01-31 10:00:07 +01:00 committed by Stephan Seitz
parent 05c963602b
commit 10989cde1b

View file

@ -1,5 +1,11 @@
-- Execute as `nvim --headless -c "luafile ./scripts/check-queries.lua"` -- Execute as `nvim --headless -c "luafile ./scripts/check-queries.lua"`
-- Equivalent to print(), but this will ensure consistent output regardless of
-- operating system.
local function io_print(text)
io.write(text, "\n")
end
local function extract_captures() local function extract_captures()
local lines = vim.fn.readfile "CONTRIBUTING.md" local lines = vim.fn.readfile "CONTRIBUTING.md"
local captures = {} local captures = {}
@ -35,7 +41,7 @@ local function do_check()
local captures = extract_captures() local captures = extract_captures()
local last_error local last_error
print "::group::Check parsers" io_print "::group::Check parsers"
for _, lang in pairs(parsers) do for _, lang in pairs(parsers) do
timings[lang] = {} timings[lang] = {}
@ -45,7 +51,7 @@ local function do_check()
local after = vim.loop.hrtime() local after = vim.loop.hrtime()
local duration = after - before local duration = after - before
table.insert(timings, { duration = duration, lang = lang, query_type = query_type }) table.insert(timings, { duration = duration, lang = lang, query_type = query_type })
print("Checking " .. lang .. " " .. query_type .. string.format(" (%.02fms)", duration * 1e-6)) io_print("Checking " .. lang .. " " .. query_type .. string.format(" (%.02fms)", duration * 1e-6))
if not ok then if not ok then
vim.api.nvim_err_writeln(query) vim.api.nvim_err_writeln(query)
last_error = query last_error = query
@ -58,7 +64,7 @@ local function do_check()
) )
if not is_valid then if not is_valid then
local error = string.format("(x) Invalid capture @%s in %s for %s.", capture, query_type, lang) local error = string.format("(x) Invalid capture @%s in %s for %s.", capture, query_type, lang)
print(error) io_print(error)
last_error = error last_error = error
end end
end end
@ -67,11 +73,11 @@ local function do_check()
end end
end end
print "::endgroup::" io_print "::endgroup::"
if last_error then if last_error then
print() io_print()
print "Last error: " io_print "Last error: "
error(last_error) error(last_error)
end end
return timings return timings
@ -88,28 +94,28 @@ for k, v in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
and not v.install_info.requires_generate_from_grammar and not v.install_info.requires_generate_from_grammar
and not vim.tbl_contains(allowed_to_fail, k) and not vim.tbl_contains(allowed_to_fail, k)
then then
print("Error: parser for " .. k .. " is not installed") io_print("Error: parser for " .. k .. " is not installed")
vim.cmd "cq" vim.cmd "cq"
else else
print("Warning: parser for " .. k .. " is not installed") io_print("Warning: parser for " .. k .. " is not installed")
end end
end end
end end
if ok then if ok then
print "::group::Timings" io_print "::group::Timings"
table.sort(result, function(a, b) table.sort(result, function(a, b)
return a.duration < b.duration return a.duration < b.duration
end) end)
for i, val in ipairs(result) do for i, val in ipairs(result) do
print(string.format("%i. %.02fms %s %s", #result - i + 1, val.duration * 1e-6, val.lang, val.query_type)) io_print(string.format("%i. %.02fms %s %s", #result - i + 1, val.duration * 1e-6, val.lang, val.query_type))
end end
print "::endgroup::" io_print "::endgroup::"
print "Check successful!\n" io_print "Check successful!"
vim.cmd "q" vim.cmd "q"
else else
print "Check failed:" io_print "Check failed:"
print(result) io_print(result)
print "\n" io_print "\n"
vim.cmd "cq" vim.cmd "cq"
end end