That sure is a nice status bar.
This commit is contained in:
parent
476a2de8f7
commit
cf7ed5b289
|
@ -198,76 +198,34 @@ function TestSuite:runTests (parent_prefix, parent_indent)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not parent_prefix then
|
if not parent_prefix then
|
||||||
io.write(TERM_COLOR_CODE_WHITE)
|
self:writeStatus(nr_errors, nr_tests)
|
||||||
io.write('\n## All tests run! ##\n\n')
|
|
||||||
|
|
||||||
local width_of_bar = 70
|
|
||||||
local size_of_red_bar = math.ceil( width_of_bar * nr_errors/nr_tests)
|
|
||||||
local size_of_green_bar = width_of_bar-size_of_red_bar
|
|
||||||
|
|
||||||
io.write('Status: ')
|
|
||||||
io.write(nr_errors == 0 and TERM_COLOR_CODE_GREEN or TERM_COLOR_CODE_RED)
|
|
||||||
io.write(string.rep('#', width_of_bar))
|
|
||||||
io.write(TERM_COLOR_CODE_WHITE)
|
|
||||||
|
|
||||||
-- Get
|
|
||||||
io.write('\n\nSummary: '..TERM_COLOR_CODE_GREEN..string.rep('#', size_of_green_bar)..TERM_COLOR_CODE_RED..string.rep('#', size_of_red_bar)..'\n\n')
|
|
||||||
io.write(TERM_COLOR_CODE_WHITE)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return nr_errors, nr_tests
|
return nr_errors, nr_tests
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
function TestSuite:writeStatus ( nr_errors, nr_tests )
|
||||||
|
io.write(TERM_COLOR_CODE_WHITE)
|
||||||
|
io.write('\n## All tests run! ##\n\n')
|
||||||
|
|
||||||
local function get_end_of_function (text, start_i)
|
local WIDTH_OR_BAR = 70
|
||||||
local indent, i, end_i = 0, start_i, text:len()
|
local BAR_CHAR = '#'
|
||||||
while i <= end_i do
|
local nr_successes = nr_tests - nr_errors
|
||||||
if text:sub(i,i) == '"' then -- "style" strings
|
local size_of_green_bar = math.floor( WIDTH_OR_BAR * nr_successes/nr_tests)
|
||||||
i = text:find('"', i + 1) + 1
|
|
||||||
elseif text:sub(i,i) == "'" then -- 'style' strings
|
|
||||||
i = text:find("'", i + 1) + 1
|
|
||||||
elseif text:sub(i,i+1) == '[[' then -- [[style]] strings
|
|
||||||
i = text:find(']]', i) + 2
|
|
||||||
elseif text:sub(i,i+3) == '--[[' then -- multi line comments
|
|
||||||
i = text:find(']]', i) + 2
|
|
||||||
elseif text:sub(i,i+1) == '--' then -- single line comments
|
|
||||||
i = text:find('\n', i) + 1
|
|
||||||
elseif text:sub(i-1, i+8):find('%sfunction%s') or i == start_i and text:sub(i, i+7) == 'function' then
|
|
||||||
indent, i = indent + 1, i + 8
|
|
||||||
elseif text:sub(i-1, i+5):find('%swhile%s') or i == start_i and text:sub(i, i+4) == 'while' then
|
|
||||||
indent, i = indent + 1, i + 4
|
|
||||||
elseif text:sub(i-1, i+3):find('%sfor%s') or i == start_i and text:sub(i, i+2) == 'for' then
|
|
||||||
indent, i = indent + 1, i + 2
|
|
||||||
elseif text:sub(i-1, i+2):find('%sif%s') or i == start_i and text:sub(i, i+1) == 'if' then
|
|
||||||
indent, i = indent + 1, i + 2
|
|
||||||
elseif text:sub(i-1, i+3):find('%send%s') or (i == end_i - 2) and text:sub(i, i+2) == 'end' then
|
|
||||||
indent, i = indent - 1, i + 2
|
|
||||||
if indent == 0 then
|
|
||||||
return i
|
|
||||||
end
|
|
||||||
else
|
|
||||||
i = i + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function TestSuite.getLocalFunction (module_name, func_name)
|
io.write('Status: ')
|
||||||
local file = io.open(module_name .. '.lua')
|
io.write(nr_errors == 0 and TERM_COLOR_CODE_GREEN or TERM_COLOR_CODE_RED)
|
||||||
local file_text = file:read('*a')
|
io.write(BAR_CHAR:rep(WIDTH_OR_BAR))
|
||||||
file:close()
|
io.write(TERM_COLOR_CODE_WHITE)
|
||||||
|
|
||||||
local function_start_index = file_text:find('function '..func_name)
|
local numbers_str = ' ' .. nr_successes .. ' / ' .. nr_tests .. ' '
|
||||||
local function_end_index = get_end_of_function(file_text, function_start_index)
|
local half_bar = (WIDTH_OR_BAR-#numbers_str)/2
|
||||||
|
local green_bar = BAR_CHAR:rep(math.floor(half_bar)) .. numbers_str .. BAR_CHAR:rep(math.ceil(half_bar))
|
||||||
|
green_bar = TERM_COLOR_CODE_GREEN .. green_bar:sub(1, size_of_green_bar) .. TERM_COLOR_CODE_RED .. green_bar:sub(size_of_green_bar + 1)
|
||||||
|
|
||||||
local new_text = file_text:sub(1, function_end_index):gsub('local function '..func_name, 'return function')
|
-- Get
|
||||||
assert(new_text ~= file_text, ('No function in module "%s" with name "%s" '):format(module_name, func_name))
|
io.write('\n\nSummary: '..green_bar..'\n\n')
|
||||||
local chunk, error_msg = load(new_text)
|
io.write(TERM_COLOR_CODE_WHITE)
|
||||||
if not chunk then
|
|
||||||
error(('While loading function in module "%s" with name "%s":\n\n\t%s\n'):format(module_name, func_name, error_msg))
|
|
||||||
end
|
|
||||||
assert(chunk, error)
|
|
||||||
return chunk()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -266,12 +266,6 @@ format_test {
|
||||||
expect = '{\n\t[{...}] = \'Hello World\'\n}',
|
expect = '{\n\t[{...}] = \'Hello World\'\n}',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
format_test {
|
|
||||||
input = false,
|
|
||||||
expect = 'true',
|
|
||||||
}
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
return SUITE
|
return SUITE
|
||||||
|
|
Loading…
Reference in New Issue
Block a user