stylua: apply stylua formatter

This commit is contained in:
Erica Marigold 2024-12-02 11:26:26 +00:00
parent 71d9868a9a
commit b4f50c2fb6
Signed by: DevComp
GPG key ID: 429EF1C337871656

View file

@ -1,55 +1,55 @@
local stdio = require("@lune/stdio") local stdio = require("@lune/stdio")
local frktest = require("@pkg/frktest") local frktest = require("@pkg/frktest")
local Reporter = frktest._reporters.lune_console_reporter local Reporter = frktest._reporters.lune_console_reporter
local STYLE = table.freeze({ local STYLE = table.freeze({
suite = function(name: string) suite = function(name: string)
return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style("reset")} {name}` return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style("reset")} {name}`
end, end,
report = function(name: string, state: "run" | "success" | "error" | "skip") report = function(name: string, state: "run" | "success" | "error" | "skip")
local state_color: stdio.Color = if state == "run" local state_color: stdio.Color = if state == "run"
then "white" then "white"
elseif state == "success" then "green" elseif state == "success" then "green"
elseif state == "error" then "red" elseif state == "error" then "red"
elseif state == "skip" then "yellow" elseif state == "skip" then "yellow"
else error("Invalid test state") else error("Invalid test state")
return ` {stdio.style("bold")}{stdio.color(state_color)}{if state == "skip" then "SKIP" else "TEST"}{stdio.style( return ` {stdio.style("bold")}{stdio.color(state_color)}{if state == "skip" then "SKIP" else "TEST"}{stdio.style(
"reset" "reset"
)} {name}` )} {name}`
end, end,
}) })
--- Clears a the previous line, and moves to its beginning --- Clears a the previous line, and moves to its beginning
local function clear_last_line(): () local function clear_last_line(): ()
return stdio.write("\x1b[A\x1b[K\x1b[0G\x1b[?25h") return stdio.write("\x1b[A\x1b[K\x1b[0G\x1b[?25h")
end end
local ReporterExt = {} local ReporterExt = {}
function ReporterExt.init() function ReporterExt.init()
frktest.test.on_suite_enter(function(suite) frktest.test.on_suite_enter(function(suite)
print(STYLE.suite(suite.name)) print(STYLE.suite(suite.name))
end) end)
frktest.test.on_suite_leave(function() frktest.test.on_suite_leave(function()
stdio.write("\n") stdio.write("\n")
end) end)
frktest.test.on_test_enter(function(test) frktest.test.on_test_enter(function(test)
print(STYLE.report(test.name, "run")) print(STYLE.report(test.name, "run"))
end) end)
frktest.test.on_test_leave(function(test) frktest.test.on_test_leave(function(test)
clear_last_line() clear_last_line()
print(STYLE.report(test.name, if test.failed then "error" else "success")) print(STYLE.report(test.name, if test.failed then "error" else "success"))
end) end)
frktest.test.on_test_skipped(function(test) frktest.test.on_test_skipped(function(test)
print(STYLE.report(test.name, "skip")) print(STYLE.report(test.name, "skip"))
end) end)
Reporter.init() Reporter.init()
end end
return setmetatable(ReporterExt, { __index = Reporter }) return setmetatable(ReporterExt, { __index = Reporter })