Don't use non existing myerror()
[lunit.git] / lunit-console.lua
blob10c045a61a84a066264c925765d886ded7f2960b
2 --[[--------------------------------------------------------------------------
4 This file is part of lunit 0.4.
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 --]]--------------------------------------------------------------------------
35 --[[
37 begin()
38 run(testcasename, testname)
39 err(fullname, message, traceback)
40 fail(fullname, where, message, usermessage)
41 pass(testcasename, testname)
42 done()
44 Fullname:
45 testcase.testname
46 testcase.testname:setupname
47 testcase.testname:teardownname
49 --]]
52 require "lunit"
54 module( "lunit-console", package.seeall )
57 local function printformat(format, ...)
58 io.write( string.format(format, ...) )
59 end
62 local columns_printed = 0
64 local function writestatus(char)
65 if columns_printed == 0 then
66 io.write(" ")
67 end
68 if columns_printed == 60 then
69 io.write("\n ")
70 columns_printed = 0
71 end
72 io.write(char)
73 io.flush()
74 columns_printed = columns_printed + 1
75 end
78 local msgs = {}
81 function begin()
82 local total_tc = 0
83 local total_tests = 0
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
89 end
90 end
92 printformat("Loaded testsuite with %d tests in %d testcases.\n\n", total_tests, total_tc)
93 end
96 function run(testcasename, testname)
97 -- NOP
98 end
101 function err(fullname, message, traceback)
102 writestatus("E")
103 msgs[#msgs+1] = "Error! ("..fullname.."):\n"..message.."\n\t"..table.concat(traceback, "\n\t") .. "\n"
107 function fail(fullname, where, message, usermessage)
108 writestatus("F")
109 local text = "Failure ("..fullname.."):\n"..
110 where..": "..message.."\n"
112 if usermessage then
113 text = text .. where..": "..usermessage.."\n"
116 msgs[#msgs+1] = text
120 function pass(testcasename, testname)
121 writestatus(".")
126 function done()
127 printformat("\n\n%d Assertions checked.\n", lunit.stats.assertions )
128 print()
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 )