2 --[[--------------------------------------------------------------------------
4 This file is part of lunit 0.5.
6 For Details about lunit look at: http://www.mroth.net/lunit/
8 Author: Michael Roth <mroth@nessie.de>
10 Copyright (c) 2006-2008 Michael Roth <mroth@nessie.de>
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:
20 The above copyright notice and this permission notice shall be
21 included in all copies or substantial portions of the Software.
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.
31 --]]--------------------------------------------------------------------------
38 run(testcasename, testname)
39 err(fullname, message, traceback)
40 fail(fullname, where, message, usermessage)
41 pass(testcasename, testname)
46 testcase.testname:setupname
47 testcase.testname:teardownname
54 module( "lunit-console", package
.seeall
)
57 local function printformat(format, ...)
58 io
.write( string.format(format, ...) )
62 local columns_printed
= 0
64 local function writestatus(char
)
65 if columns_printed
== 0 then
68 if columns_printed
== 60 then
74 columns_printed
= columns_printed
+ 1
85 for tcname
in lunit
.testcases() do
86 total_tc
= total_tc
+ 1
87 for testname
, test
in lunit
.tests(tcname
) do
88 total_tests
= total_tests
+ 1
92 printformat("Loaded testsuite with %d tests in %d testcases.\n\n", total_tests
, total_tc
)
96 function run(testcasename
, testname
)
101 function err(fullname
, message
, traceback
)
103 msgs
[#msgs
+1] = "Error! ("..fullname
.."):\n"..message
.."\n\t"..table.concat(traceback
, "\n\t") .. "\n"
107 function fail(fullname
, where
, message
, usermessage
)
109 local text
= "Failure ("..fullname
.."):\n"..
110 where
..": "..message
.."\n"
113 text
= text
.. where
..": "..usermessage
.."\n"
120 function pass(testcasename
, testname
)
127 printformat("\n\n%d Assertions checked.\n", lunit
.stats
.assertions
)
130 for i
, msg
in ipairs(msgs
) do
131 printformat( "%3d) %s\n", i
, msg
)
134 printformat("Testsuite finished (%d passed, %d failed, %d errors).\n",
135 lunit
.stats
.passed
, lunit
.stats
.failed
, lunit
.stats
.errors
)