Skip to content

Commit 1b90c34

Browse files
authored
Merge pull request #83 from moteus/master
Add. custom test output mode.
2 parents 563a3de + c995bc2 commit 1b90c34

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

test/lunit/console.lua

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
--[[--------------------------------------------------------------------------
3+
4+
This file is part of lunit 0.6.
5+
6+
For Details about lunit look at: http://www.mroth.net/lunit/
7+
8+
Author: Michael Roth <[email protected]>
9+
10+
Copyright (c) 2006-2008 Michael Roth <[email protected]>
11+
12+
Permission is hereby granted, free of charge, to any person
13+
obtaining a copy of this software and associated documentation
14+
files (the "Software"), to deal in the Software without restriction,
15+
including without limitation the rights to use, copy, modify, merge,
16+
publish, distribute, sublicense, and/or sell copies of the Software,
17+
and to permit persons to whom the Software is furnished to do so,
18+
subject to the following conditions:
19+
20+
The above copyright notice and this permission notice shall be
21+
included in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30+
31+
--]]--------------------------------------------------------------------------
32+
33+
34+
35+
--[[
36+
37+
begin()
38+
run(testcasename, testname)
39+
err(fullname, message, traceback)
40+
fail(fullname, where, message, usermessage)
41+
pass(testcasename, testname)
42+
done()
43+
44+
Fullname:
45+
testcase.testname
46+
testcase.testname:setupname
47+
testcase.testname:teardownname
48+
49+
--]]
50+
51+
52+
local lunit = require "lunit"
53+
local string = require "string"
54+
local io = require "io"
55+
local table = require "table"
56+
57+
local _M = {}
58+
59+
local function rfill(str, wdt, ch)
60+
if wdt > #str then str = str .. (ch or ' '):rep(wdt - #str) end
61+
return str
62+
end
63+
64+
local function printformat(format, ...)
65+
io.write( string.format(format, ...) )
66+
end
67+
68+
local columns_printed = 0
69+
70+
local function writestatus(char)
71+
if columns_printed == 0 then
72+
io.write(" ")
73+
end
74+
if columns_printed == 60 then
75+
io.write("\n ")
76+
columns_printed = 0
77+
end
78+
io.write(char)
79+
io.flush()
80+
columns_printed = columns_printed + 1
81+
end
82+
83+
local msgs = {}
84+
85+
function _M.begin()
86+
local total_tc = 0
87+
local total_tests = 0
88+
89+
msgs = {} -- e
90+
91+
for tcname in lunit.testcases() do
92+
total_tc = total_tc + 1
93+
for testname, test in lunit.tests(tcname) do
94+
total_tests = total_tests + 1
95+
end
96+
end
97+
98+
printformat("Loaded testsuite with %d tests in %d testcases.\n\n", total_tests, total_tc)
99+
end
100+
101+
function _M.run(testcasename, testname)
102+
io.write(rfill(testcasename .. '.' .. testname, 70)) io.flush()
103+
end
104+
105+
function _M.err(fullname, message, traceback)
106+
io.write(" - error!\n")
107+
io.write("Error! ("..fullname.."):\n"..message.."\n\t"..table.concat(traceback, "\n\t"), "\n")
108+
end
109+
110+
function _M.fail(fullname, where, message, usermessage)
111+
io.write(" - fail!\n")
112+
io.write(string.format("Failure (%s): %s\n%s: %s", fullname, usermessage or "", where, message), "\n")
113+
end
114+
115+
function _M.skip(fullname, where, message, usermessage)
116+
io.write(" - skip!\n")
117+
io.write(string.format("Skip (%s): %s\n%s: %s", fullname, usermessage or "", where, message), "\n")
118+
end
119+
120+
function _M.pass(testcasename, testname)
121+
io.write(" - pass!\n")
122+
end
123+
124+
function _M.done()
125+
printformat("\n\n%d Assertions checked.\n", lunit.stats.assertions )
126+
print()
127+
128+
printformat("Testsuite finished (%d passed, %d failed, %d errors, %d skipped).\n",
129+
lunit.stats.passed, lunit.stats.failed, lunit.stats.errors, lunit.stats.skipped )
130+
end
131+
132+
return _M

0 commit comments

Comments
 (0)