Commit 40cd9ad0 authored by Jamie A. Jennings's avatar Jamie A. Jennings

Changed the way totals are printed

parent 0d2d108a
......@@ -128,14 +128,18 @@ local function run(args)
-- call the test procedure
cli_test = assert(rosie.import("unittest"), "failed to open unittest package")
cli_test.setup(en, rosie.attributes.ROSIE_LIBDIR)
local total_failures, total_tests = 0, 0
local total_errors, total_failures, total_blocked = 0, 0, 0
local total_passed, total_tests = 0, 0
local total_files, total_compiled = 0, 0
for _, fn in ipairs(args.filenames) do
local ok, failures, total = cli_test.run(rosie, en, args, fn)
local ok, errors, failures, blocked, passed, total = cli_test.run(rosie, en, args, fn)
total_files = total_files + 1
if ok then total_compiled = total_compiled + 1; end
total_failures = total_failures + failures
total_tests = total_tests + total
total_errors = total_errors + (errors or 0)
total_failures = total_failures + (failures or 0)
total_blocked = total_blocked + (blocked or 0)
total_passed = total_passed + (passed or 0)
total_tests = total_tests + (total or 0)
end
if args.verbose and (#args.filenames > 1) then
print("\nTOTALS:")
......@@ -145,12 +149,11 @@ local function run(args)
else
io.stdout:write(tostring(total_files-total_compiled), " failed to compile\n")
end
io.stdout:write(tostring(total_tests), " tests attempted, ")
if total_failures~=0 then
io.stdout:write(tostring(total_failures), " tests failed")
else
io.stdout:write("all " .. tostring(total_tests) .. " tests passed\n")
end
cli_test.write_test_result("Tests: ", tostring(total_tests),
" Errors: ", tostring(total_errors),
" Failures: ", tostring(total_failures),
" Blocked: ", tostring(total_blocked),
" Passed: ", tostring(total_passed))
end
if ((total_files - total_compiled) > 0) or (total_failures > 0) then
return cli_common.ERROR_RESULT
......
......@@ -6,6 +6,8 @@
-- LICENSE: MIT License (https://opensource.org/licenses/mit-license.html)
-- AUTHORS: Jamie A. Jennings, Kevin Zander
-- This code badly needs refactoring!
local unittest = {}
local cli_common = import("cli-common")
......@@ -70,8 +72,23 @@ local function indent(str, col)
return str:gsub('\n', '\n' .. string.rep(" ", col))
end
local right_column = 4
function unittest.write_test_result(...)
io.write(string.rep(" ", right_column))
for _,item in ipairs{...} do io.write(item); end
io.write("\n")
end
-- Args:
-- rosie, the rosie module (for creating a new engine, and rplx objects for en)
-- en, the engine that has patterns for extracting test cases
-- args, the CLI args needed to set up the test engine
-- filename, the rpl file to load (compile) and which has the tests
-- Return values:
-- true if no execution errors, and if that is the case, then also:
-- number of test errors, failures, blocked, passed, and total
function unittest.run(rosie, en, args, filename)
local right_column = 4
-- fresh engine for testing this file
local test_engine = rosie.engine.new()
-- set it up using whatever rpl strings or files were given on the command line
......@@ -85,13 +102,8 @@ function unittest.run(rosie, en, args, filename)
io.write(indent(msg, right_column), "\n")
return false, 0, 0
end
local function write_test_result(...)
io.write(string.rep(" ", right_column))
for _,item in ipairs{...} do io.write(item); end
io.write("\n")
end
if args.verbose then
write_test_result("File compiled successfully")
unittest.write_test_result("File compiled successfully")
end
-- read the tests out of the file and run each one
local f, msg = io.open(filename, 'r')
......@@ -99,7 +111,7 @@ function unittest.run(rosie, en, args, filename)
local num_patterns, test_lines = find_test_lines(f:read('*a'))
f:close()
if num_patterns == 0 then
write_test_result("No tests found")
unittest.write_test_result("No tests found")
return true, 0, 0
end
local function find_local(en, pkgname, identifier)
......@@ -119,8 +131,8 @@ function unittest.run(rosie, en, args, filename)
return false
end
local function write_compilation_error(exp, message)
write_test_result("ERROR: " .. message .. ": ",
tostring(exp))
unittest.write_test_result("ERROR: " .. message .. ": ",
tostring(exp))
end
local function test_exp(original_exp, q, should_accept, is_local)
-- returns status, result
......@@ -203,7 +215,7 @@ function unittest.run(rosie, en, args, filename)
-- literals to test against will be in subs at offset 3
local literals = 3
if not m then
write_test_result("ERROR: invalid test syntax: ", p)
unittest.write_test_result("ERROR: invalid test syntax: ", p)
total = total + 1
errors = errors + 1
else
......@@ -212,7 +224,7 @@ function unittest.run(rosie, en, args, filename)
table.remove(m.subs, 1)
end
if #m.subs < literals then
write_test_result("ERROR: invalid test syntax (missing quoted input strings): ", p)
unittest.write_test_result("ERROR: invalid test syntax (missing quoted input strings): ", p)
total = total + 1
errors = errors + 1
else
......@@ -259,13 +271,13 @@ function unittest.run(rosie, en, args, filename)
if msg then
if includes==nil then
blocked = blocked + 1
write_test_result("BLOCKED: ", msg)
unittest.write_test_result("BLOCKED: ", msg)
elseif includes=="error" then
errors = errors + 1
write_test_result("ERROR: ", msg)
unittest.write_test_result("ERROR: ", msg)
else
failures = failures + 1
write_test_result("FAILED: ", msg)
unittest.write_test_result("FAILED: ", msg)
end
else
passed = passed + 1
......@@ -280,7 +292,7 @@ function unittest.run(rosie, en, args, filename)
teststr, esc_err = ustring.unescape_string(m.subs[i].data) -- allow, e.g. \" inside the test string
if not teststr then
errors = errors + 1
write_test_result("ERROR: ", esc_err)
unittest.write_test_result("ERROR: ", esc_err)
else
local result = test_exp(testIdentifier, teststr, should_accept, is_local_identifier)
if not result then
......@@ -291,7 +303,7 @@ function unittest.run(rosie, en, args, filename)
end
if #teststr==0 then teststr = "the empty string"; end -- for display purposes
if result ~= nil then
write_test_result("FAILED: ", testIdentifier, " did not ", m.subs[2].data:sub(1,-2), " ", m.subs[i].data)
unittest.write_test_result("FAILED: ", testIdentifier, " did not ", m.subs[2].data:sub(1,-2), " ", m.subs[i].data)
end
else
passed = passed + 1
......@@ -305,15 +317,15 @@ function unittest.run(rosie, en, args, filename)
end -- for each test line
end
if failures == 0 and errors == 0 and blocked == 0 then
write_test_result("All ", tostring(total), " tests passed")
unittest.write_test_result("All ", tostring(total), " tests passed")
else
write_test_result("Tests: ", tostring(total),
" Errors: ", tostring(errors),
" Failures: ", tostring(failures),
" Blocked: ", tostring(blocked),
" Passed: ", tostring(passed))
unittest.write_test_result("Tests: ", tostring(total),
" Errors: ", tostring(errors),
" Failures: ", tostring(failures),
" Blocked: ", tostring(blocked),
" Passed: ", tostring(passed))
end
return true, failures, total
return true, errors, failures, blocked, passed, total
end
return unittest
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment