diff --git a/base.lua b/base.lua index 31711ce..d00badb 100644 --- a/base.lua +++ b/base.lua @@ -324,6 +324,89 @@ check.pattern = function(pos1, pos2, pattern) end end +--------------------------------------- +--- Colors Management +--- from https://github.com/ldrumm/lua-chroma +-------------------------------------- +rawset(_G, "pprint", setmetatable({ + escapes = { + clear = "\027[0m", + red = "\027[31m", + green = "\027[32m", + orange = "\027[33m", + navy = "\027[34m", + magenta = "\027[35m", + cyan = "\027[36m", + gray = "\027[90m", + grey = "\027[90m", + light_gray = "\027[37m", + light_grey = "\027[37m", + peach = "\027[91m", + light_green = "\027[92m", + yellow = "\027[93m", + blue = "\027[94m", + pink = "\027[95m", + baby_blue = "\027[96m", + + highlight = { + red = "\027[41m", + green = "\027[42m", + orange = "\027[43m", + navy = "\027[44m", + magenta = "\027[45m", + cyan = "\027[46m", + gray = "\027[47m", + grey = "\027[47m", + light_gray = "\027[100m", + light_grey = "\027[100m", + peach = "\027[101m", + light_green = "\027[102m", + yellow = "\027[103m", + blue = "\027[104m", + pink = "\027[105m", + baby_blue = "\027[106m", + }, + + strikethrough = "\027[9m", + underline = "\027[4m", + bold = "\027[1m", + }, + _sequence = '', + _highlight = false, + print = io.write +}, +{ + __call = function(self, ...) return io.write(...) end, + + __index = function(self, index) + local esc = self._highlight and rawget(self, 'escapes').highlight[index] + or rawget(self, 'escapes')[index] + self._highlight = index == 'highlight' + if esc ~= nil then + if type(esc) == 'string' then + self._sequence = self._sequence .. esc + end + return setmetatable({}, { + __call = function(proxy, ...) + if self._sequence then io.write(self._sequence) end + self.print(...) + self._sequence = '' + io.write(rawget(self,'escapes').clear) + return self + end, + __index = function(proxy, k) + return self[k] + end, + }) + else + return rawget(self, index) + end + end, +})) + + + +-------------------------------------- local request_shutdown = function() if failed == 0 then io.close(io.open(minetest.get_worldpath() .. "/tests_ok", "w")) @@ -344,22 +427,35 @@ end local display_tests_summary = function() for mod, tests_list in pairs(tests_by_mod) do - print(string.format("%#70s", mod)) + pprint.baby_blue(string.format("%#60s\n", mod)) for _, test in ipairs(tests_list) do if test.func == nil then - local s = ":"..test.mod..":---- " .. test.name .. " " - print(s .. string.rep("-", 60 - #s)) + local s = ":".. test.mod ..":---- " .. test.name + pprint.light_gray(":".. test.mod ..":").blue("---- " .. test.name) + pprint.blue(string.rep("-", 60 - #s).."\n") elseif test.result ~= nil then - print(string.format(":%s:%-60s %s", test.mod,test.name, test.result.ok and "pass" or "FAIL")) - if not test.result.ok then - print(" " .. test.result.err) + local s = ":"..test.mod..":" + local rest = s .. test.name + pprint.light_gray(s) + pprint(" ") + pprint(test.name) + pprint(string.rep(" ", 60 - #rest)) + if test.result.ok then pprint.green("pass") else pprint.red("FAIL") end + pprint("\n") + if not test.result.ok and test.result.err then + pprint.yellow(" " .. test.result.err .. "\n") end else - print(string.format(":%s:%-60s %s", test.mod, test.name, "No result")) + pprint.light_gray(string.format(":%s:%-60s %s\n", test.mod, test.name, "No result")) end end + pprint.baby_blue(string.rep("-",60),"\n") end - print("Tests done, " .. failed .. " tests failed.") + print(string.rep("-",60)) + pprint.bold("Tests done, ") + if failed == 0 then pprint.bold.green(failed) else pprint.bold.red(failed) end + pprint.bold(" tests failed.\n") + print(string.rep("-",60)) end test_harness.dump = function(o)