Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9 #97

Merged
merged 3 commits into from
Jan 13, 2025
Merged

v0.9 #97

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions bin/mineunit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local args = {
verbose = false,
quiet = false,
output = "utfTerminal",
coverage = false,
report = false,
Expand Down Expand Up @@ -248,6 +249,7 @@ do -- Parse cli args
Luarocks package: https://luarocks.org/modules/S-S-X/mineunit
Issue tracker: https://github.com/S-S-X/mineunit/issues
GitHub integration: https://github.com/marketplace/actions/mineunit-runner
Docker images: https://hub.docker.com/r/mineunit/mineunit

Configuration files (in order):
/etc/mineunit/mineunit.conf
Expand All @@ -268,6 +270,7 @@ do -- Parse cli args
elseif v == "-q" or v == "--quiet" then
mineunit_conf_override.print = false
mineunit_conf_override.verbose = 1
args.quiet = true
elseif v == "-x" or v == "--exclude" then
i = i + 1
if not arg[i] then
Expand Down Expand Up @@ -429,21 +432,92 @@ local outputHandlerLoader = require("busted.modules.output_handler_loader")()
require("busted")(busted)
local exit = require("busted.compatibility").exit

mineunit = {}
require("mineunit.print")
busted.export('mineunit', mineunit)

if args.coverage then
load_luacov()
end

-- subscribe for additional output

if args.output == "utfTerminal" and not args.quiet then
local handler = require("busted.outputHandlers.base")()
local first_end
local skip_quiet = not args.verbose
local c = require("term.colors")
local function getFileLine(element)
if element.trace or element.trace.short_src then
return element.trace.short_src:sub(6) .. ':' .. element.trace.currentline
end
return '?:?'
end
busted.subscribe({'file', 'start'}, function(element, parent)
mineunit:prepend_flush()
io.stdout:write(c.cyan('++ Executing ' .. handler.getFullName(element)))
mineunit:prepend_print('\n')
end)
busted.subscribe({'file', 'end'}, function() mineunit:prepend_print('\n') end)
busted.subscribe({'describe', 'start'}, function(element, parent)
local header = c.yellow('⭆ Starting test set ' .. c.bright .. getFileLine(element))
local testname = c.cyan(handler.getFullName(element))
if skip_quiet then
mineunit:prepend_print(header .. ' ⯈ ' .. testname .. '\n')
else
mineunit:prepend_flush()
io.stdout:write(header .. ' ⯈ ' .. testname)
mineunit:prepend_print('\n')
end
end)
busted.subscribe({'describe', 'end'}, function() mineunit:prepend_print('\n') end)
busted.subscribe({'test', 'start'}, function(element, parent)
local header = c.bright(c.white .. '🢆') .. c.yellow(' Running tests from ' .. c.bright .. getFileLine(element))
local testname = c.bright(c.cyan .. handler.getFullName(element))
if skip_quiet then
mineunit:prepend_print(header .. ' ▷ ' .. testname .. '\n')
else
mineunit:prepend_flush()
io.stdout:write(header .. ' ▷ ' .. testname)
mineunit:prepend_print('\n')
end
first_end = true
end)
busted.subscribe({'test', 'end'}, function(element, parent, status)
local space = ''
if not skip_quiet and first_end then
first_end = false
space = ' '
end
if status == 'pending' then
io.stdout:write(space..c.yellow('◌'))
mineunit:prepend_print('\n')
elseif status == 'failure' then
io.stdout:write(space..c.red('◼'))
mineunit:prepend_print('\n')
elseif status == 'error' then
io.stdout:write(space..c.magenta('✱'))
mineunit:prepend_print('\n')
elseif not skip_quiet then
io.stdout:write(space..c.green('●'))
mineunit:prepend_print('\n')
end
end)
end

-- watch for test errors and failures
local failures = 0
local errors = 0

busted.subscribe({ 'error', 'output' }, function(element, parent, message)
io.stderr:write(appName .. ': error: Cannot load output library: ' .. element.name .. '\n' .. message .. '\n')
mineunit:prepend_print(nil)
return nil, true
end)

busted.subscribe({ 'error', 'helper' }, function(element, parent, message)
io.stderr:write(appName .. ': error: Cannot load helper script: ' .. element.name .. '\n' .. message .. '\n')
mineunit:prepend_print(nil)
return nil, true
end)

Expand Down
22 changes: 7 additions & 15 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ local default_config = {
engine_version = "mineunit",
}

for k,v in pairs(mineunit_conf_defaults) do
for k,v in pairs(mineunit_conf_defaults or {}) do
default_config[k] = v
end

mineunit = {
_config = {
modpaths = {},
},
_on_mods_loaded = {},
_on_mods_loaded_exec_count = 0,
mineunit = mineunit or {}
mineunit._config = {
modpaths = {},
}
mineunit._on_mods_loaded = {}
mineunit._on_mods_loaded_exec_count = 0

local tagged_paths = {
["common"] = true,
["game"] = true
}

require("mineunit.print")
require("mineunit.globals")

local function mineunit_path(name)
Expand Down Expand Up @@ -104,14 +104,6 @@ function mineunit:config(key)
end
mineunit._config.source_path = pl.path.normpath(("%s/%s"):format(mineunit:config("root"), mineunit:config("source_path")))

local luaprint = _G.print
function mineunit:debug(...) if self:config("verbose") > 3 then luaprint("D:",...) end end
function mineunit:info(...) if self:config("verbose") > 2 then luaprint("I:",...) end end
function mineunit:warning(...) if self:config("verbose") > 1 then luaprint("W:",...) end end
function mineunit:error(...) if self:config("verbose") > 0 then luaprint("E:",...) end end
function mineunit:print(...) if self:config("print") then luaprint(...) end end
_G.print = function(...) mineunit:print(...) end

function mineunit:set_modpath(name, path)
mineunit:info("Setting modpath", name, path)
self._config.modpaths[name] = path
Expand Down
29 changes: 29 additions & 0 deletions print.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--
-- Wrappers and helpers for print
--

local luaprint = _G.print

function mineunit:prepend_print(s)
self._prepend_output = s
end

function mineunit:prepend_flush()
if self._prepend_output then
io.stdout:write(self._prepend_output)
self._prepend_output = nil
end
end

local function printwrapper(...)
mineunit:prepend_flush()
luaprint(...)
end

function mineunit:debug(...) if self:config("verbose") > 3 then printwrapper("D:",...) end end
function mineunit:info(...) if self:config("verbose") > 2 then printwrapper("I:",...) end end
function mineunit:warning(...) if self:config("verbose") > 1 then printwrapper("W:",...) end end
function mineunit:error(...) if self:config("verbose") > 0 then printwrapper("E:",...) end end
function mineunit:print(...) if self:config("print") then printwrapper(...) end end

_G.print = function(...) mineunit:print(...) end
Loading