test/lunit.lua

Wed, 15 Jul 2009 10:39:10 -0400

author
Thomas Harning Jr <harningt@gmail.com>
date
Wed, 15 Jul 2009 10:39:10 -0400
changeset 64
dd47dbe85bec
parent 35
4f81725a1e5f
permissions
-rw-r--r--

Merge branch 'v0.2'

35
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
1
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
2 --[[--------------------------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
3
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
4 This file is part of lunit 0.4pre (alpha).
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
5
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
6 For Details about lunit look at: http://www.nessie.de/mroth/lunit/
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
7
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
8 Author: Michael Roth <mroth@nessie.de>
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
9
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
10 Copyright (c) 2004 Michael Roth <mroth@nessie.de>
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
11
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
12 Permission is hereby granted, free of charge, to any person
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
13 obtaining a copy of this software and associated documentation
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
14 files (the "Software"), to deal in the Software without restriction,
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
15 including without limitation the rights to use, copy, modify, merge,
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
16 publish, distribute, sublicense, and/or sell copies of the Software,
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
17 and to permit persons to whom the Software is furnished to do so,
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
18 subject to the following conditions:
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
19
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
20 The above copyright notice and this permission notice shall be
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
21 included in all copies or substantial portions of the Software.
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
22
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
26 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
27 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
28 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
30
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
31 --]]--------------------------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
32
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
33
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
34
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
35
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
36 -----------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
37 -- Intialize package --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
38 -----------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
39
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
40 local P = { }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
41 lunit = P
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
42
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
43 -- Import
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
44 local type = type
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
45 local print = print
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
46 local ipairs = ipairs
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
47 local pairs = pairs
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
48 local string = string
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
49 local table = table
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
50 local pcall = pcall
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
51 local xpcall = xpcall
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
52 local traceback = debug.traceback
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
53 local error = error
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
54 local setmetatable = setmetatable
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
55 local rawset = rawset
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
56 local orig_assert = assert
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
57 local getfenv = getfenv
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
58 local setfenv = setfenv
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
59 local tostring = tostring
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
60
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
61
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
62 -- Start package scope
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
63 setfenv(1, P)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
64
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
65
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
66
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
67
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
68 --------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
69 -- Private data and functions --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
70 --------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
71
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
72 local run_testcase
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
73 local do_assert, check_msg
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
74 local stats = { }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
75 local testcases = { }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
76 local stats_inc, tc_mt
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
77
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
78
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
79
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
80
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
81 --------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
82 -- Type check functions --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
83 --------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
84
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
85 function is_nil(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
86 return type(x) == "nil"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
87 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
88
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
89 function is_boolean(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
90 return type(x) == "boolean"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
91 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
92
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
93 function is_number(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
94 return type(x) == "number"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
95 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
96
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
97 function is_string(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
98 return type(x) == "string"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
99 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
100
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
101 function is_table(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
102 return type(x) == "table"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
103 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
104
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
105 function is_function(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
106 return type(x) == "function"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
107 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
108
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
109 function is_thread(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
110 return type(x) == "thread"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
111 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
112
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
113 function is_userdata(x)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
114 return type(x) == "userdata"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
115 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
116
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
117
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
118
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
119
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
120 ----------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
121 -- Assert functions --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
122 ----------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
123
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
124 function assert(assertion, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
125 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
126 check_msg("assert", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
127 do_assert(not not assertion, "assertion failed (was: "..tostring(assertion)..")", msg) -- (convert assertion to bool)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
128 return assertion
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
129 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
130
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
131
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
132 function assert_fail(msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
133 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
134 check_msg("assert_fail", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
135 do_assert(false, "failure", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
136 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
137
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
138
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
139 function assert_true(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
140 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
141 check_msg("assert_true", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
142 do_assert(is_boolean(actual), "true expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
143 do_assert(actual == true, "true expected but was false", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
144 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
145 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
146
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
147
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
148 function assert_false(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
149 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
150 check_msg("assert_false", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
151 do_assert(is_boolean(actual), "false expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
152 do_assert(actual == false, "false expected but was true", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
153 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
154 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
155
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
156
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
157 function assert_equal(expected, actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
158 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
159 check_msg("assert_equal", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
160 do_assert(expected == actual, "expected '"..tostring(expected).."' but was '"..tostring(actual).."'", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
161 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
162 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
163
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
164
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
165 function assert_not_equal(unexpected, actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
166 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
167 check_msg("assert_not_equal", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
168 do_assert(unexpected ~= actual, "'"..tostring(expected).."' not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
169 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
170 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
171
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
172
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
173 function assert_match(pattern, actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
174 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
175 check_msg("assert_match", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
176 do_assert(is_string(pattern), "assert_match expects the pattern as a string")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
177 do_assert(is_string(actual), "expected a string to match pattern '"..pattern.."' but was a '"..type(actual).."'", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
178 do_assert(not not string.find(actual, pattern), "expected '"..actual.."' to match pattern '"..pattern.."' but doesn't", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
179 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
180 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
181
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
182
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
183 function assert_not_match(pattern, actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
184 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
185 check_msg("assert_not_match", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
186 do_assert(is_string(actual), "expected a string to not match pattern '"..pattern.."' but was a '"..type(actual).."'", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
187 do_assert(string.find(actual, pattern) == nil, "expected '"..actual.."' to not match pattern '"..pattern.."' but it does", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
188 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
189 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
190
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
191
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
192 function assert_nil(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
193 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
194 check_msg("assert_nil", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
195 do_assert(is_nil(actual), "nil expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
196 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
197 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
198
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
199
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
200 function assert_not_nil(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
201 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
202 check_msg("assert_not_nil", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
203 do_assert(not is_nil(actual), "nil not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
204 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
205 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
206
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
207
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
208 function assert_boolean(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
209 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
210 check_msg("assert_boolean", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
211 do_assert(is_boolean(actual), "boolean expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
212 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
213 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
214
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
215
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
216 function assert_not_boolean(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
217 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
218 check_msg("assert_not_boolean", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
219 do_assert(not is_boolean(actual), "boolean not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
220 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
221 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
222
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
223
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
224 function assert_number(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
225 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
226 check_msg("assert_number", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
227 do_assert(is_number(actual), "number expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
228 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
229 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
230
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
231
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
232 function assert_not_number(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
233 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
234 check_msg("assert_not_number", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
235 do_assert(not is_number(actual), "number not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
236 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
237 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
238
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
239
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
240 function assert_string(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
241 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
242 check_msg("assert_string", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
243 do_assert(is_string(actual), "string expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
244 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
245 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
246
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
247
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
248 function assert_not_string(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
249 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
250 check_msg("assert_not_string", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
251 do_assert(not is_string(actual), "string not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
252 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
253 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
254
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
255
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
256 function assert_table(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
257 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
258 check_msg("assert_table", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
259 do_assert(is_table(actual), "table expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
260 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
261 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
262
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
263
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
264 function assert_not_table(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
265 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
266 check_msg("assert_not_table", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
267 do_assert(not is_table(actual), "table not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
268 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
269 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
270
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
271
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
272 function assert_function(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
273 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
274 check_msg("assert_function", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
275 do_assert(is_function(actual), "function expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
276 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
277 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
278
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
279
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
280 function assert_not_function(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
281 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
282 check_msg("assert_not_function", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
283 do_assert(not is_function(actual), "function not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
284 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
285 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
286
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
287
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
288 function assert_thread(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
289 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
290 check_msg("assert_thread", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
291 do_assert(is_thread(actual), "thread expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
292 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
293 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
294
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
295
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
296 function assert_not_thread(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
297 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
298 check_msg("assert_not_thread", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
299 do_assert(not is_thread(actual), "thread not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
300 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
301 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
302
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
303
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
304 function assert_userdata(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
305 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
306 check_msg("assert_userdata", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
307 do_assert(is_userdata(actual), "userdata expected but was a "..type(actual), msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
308 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
309 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
310
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
311
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
312 function assert_not_userdata(actual, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
313 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
314 check_msg("assert_not_userdata", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
315 do_assert(not is_userdata(actual), "userdata not expected but was one", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
316 return actual
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
317 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
318
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
319
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
320 function assert_error(msg, func)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
321 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
322 if is_nil(func) then func, msg = msg, nil end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
323 check_msg("assert_error", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
324 do_assert(is_function(func), "assert_error expects a function as the last argument but it was a "..type(func))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
325 local ok, errmsg = pcall(func)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
326 do_assert(ok == false, "error expected but no error occurred", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
327 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
328
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
329
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
330 function assert_pass(msg, func)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
331 stats_inc("assertions")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
332 if is_nil(func) then func, msg = msg, nil end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
333 check_msg("assert_pass", msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
334 do_assert(is_function(func), "assert_pass expects a function as the last argument but it was a "..type(func))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
335 local ok, errmsg = pcall(func)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
336 if not ok then do_assert(ok == true, "no error expected but error was: "..errmsg, msg) end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
337 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
338
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
339
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
340
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
341
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
342 -----------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
343 -- Assert implementation that assumes it was called from --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
344 -- lunit code which was called directly from user code. --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
345 -----------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
346
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
347 function do_assert(assertion, base_msg, user_msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
348 orig_assert(is_boolean(assertion))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
349 orig_assert(is_string(base_msg))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
350 orig_assert(is_string(user_msg) or is_nil(user_msg))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
351 if not assertion then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
352 if user_msg then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
353 error(base_msg..": "..user_msg, 3)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
354 else
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
355 error(base_msg.."!", 3)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
356 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
357 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
358 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
359
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
360 -------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
361 -- Checks the msg argument in assert_xxx --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
362 -------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
363
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
364 function check_msg(name, msg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
365 orig_assert(is_string(name))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
366 if not (is_nil(msg) or is_string(msg)) then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
367 error("lunit."..name.."() expects the optional message as a string but it was a "..type(msg).."!" ,3)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
368 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
369 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
370
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
371
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
372
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
373
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
374 -------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
375 -- Creates a new TestCase 'Object' --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
376 -------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
377
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
378 function TestCase(name)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
379 do_assert(is_string(name), "lunit.TestCase() needs a string as an argument")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
380 local tc = {
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
381 __lunit_name = name;
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
382 __lunit_setup = nil;
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
383 __lunit_tests = { };
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
384 __lunit_teardown = nil;
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
385 }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
386 setmetatable(tc, tc_mt)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
387 table.insert(testcases, tc)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
388 return tc
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
389 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
390
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
391 tc_mt = {
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
392 __newindex = function(tc, key, value)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
393 rawset(tc, key, value)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
394 if is_string(key) and is_function(value) then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
395 local name = string.lower(key)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
396 if string.find(name, "^test") or string.find(name, "test$") then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
397 table.insert(tc.__lunit_tests, key)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
398 elseif name == "setup" then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
399 tc.__lunit_setup = value
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
400 elseif name == "teardown" then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
401 tc.__lunit_teardown = value
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
402 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
403 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
404 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
405 }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
406
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
407
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
408
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
409 -----------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
410 -- Wrap Functions in a TestCase object --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
411 -----------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
412
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
413 function wrap(name, ...)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
414 if is_function(name) then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
415 table.insert(arg, 1, name)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
416 name = "Anonymous Testcase"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
417 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
418
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
419 local tc = TestCase(name)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
420 for index, test in ipairs(arg) do
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
421 tc["Test #"..index] = test
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
422 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
423 return tc
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
424 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
425
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
426
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
427
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
428
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
429
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
430
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
431 ----------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
432 -- Runs the complete Test Suite --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
433 ----------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
434
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
435 function run()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
436
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
437 ---------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
438 -- Initialize statistics --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
439 ---------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
440
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
441 stats.testcases = 0 -- Total number of Test Cases
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
442 stats.tests = 0 -- Total number of all Tests in all Test Cases
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
443 stats.run = 0 -- Number of Tests run
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
444 stats.notrun = 0 -- Number of Tests not run
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
445 stats.failed = 0 -- Number of Tests failed
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
446 stats.warnings = 0 -- Number of Warnings (teardown)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
447 stats.errors = 0 -- Number of Errors (setup)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
448 stats.passed = 0 -- Number of Test passed
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
449 stats.assertions = 0 -- Number of all assertions made in all Test in all Test Cases
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
450
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
451 --------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
452 -- Count Test Cases and Tests --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
453 --------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
454
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
455 stats.testcases = table.getn(testcases)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
456
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
457 for _, tc in ipairs(testcases) do
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
458 stats_inc("tests" , table.getn(tc.__lunit_tests))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
459 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
460
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
461 ------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
462 -- Print Header --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
463 ------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
464
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
465 print()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
466 print("#### Test Suite with "..stats.tests.." Tests in "..stats.testcases.." Test Cases loaded.")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
467
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
468 ------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
469 -- Run all Test Cases --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
470 ------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
471
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
472 for _, tc in ipairs(testcases) do
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
473 run_testcase(tc)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
474 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
475
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
476 ------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
477 -- Print Footer --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
478 ------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
479
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
480 print()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
481 print("#### Test Suite finished.")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
482
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
483 local msg_assertions = stats.assertions.." Assertions checked. "
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
484 local msg_passed = stats.passed == stats.tests and "All Tests passed" or stats.passed.." Tests passed"
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
485 local msg_failed = stats.failed > 0 and ", "..stats.failed.." failed" or ""
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
486 local msg_run = stats.notrun > 0 and ", "..stats.notrun.." not run" or ""
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
487 local msg_warn = stats.warnings > 0 and ", "..stats.warnings.." warnings" or ""
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
488
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
489 print()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
490 print(msg_assertions..msg_passed..msg_failed..msg_run..msg_warn.."!")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
491
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
492 -----------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
493 -- Return code --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
494 -----------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
495
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
496 if stats.passed == stats.tests then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
497 return 0
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
498 else
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
499 return 1
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
500 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
501 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
502
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
503
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
504
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
505
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
506 -----------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
507 -- Runs a single Test Case --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
508 -----------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
509
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
510 function run_testcase(tc)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
511
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
512 orig_assert(is_table(tc))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
513 orig_assert(is_table(tc.__lunit_tests))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
514 orig_assert(is_string(tc.__lunit_name))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
515 orig_assert(is_nil(tc.__lunit_setup) or is_function(tc.__lunit_setup))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
516 orig_assert(is_nil(tc.__lunit_teardown) or is_function(tc.__lunit_teardown))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
517
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
518 ----------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
519 -- Protected call to a function --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
520 ----------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
521
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
522 local function call(errprefix, func)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
523 orig_assert(is_string(errprefix))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
524 orig_assert(is_function(func))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
525 local ok, errmsg = xpcall(function() func(tc) end, traceback)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
526 if not ok then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
527 print()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
528 print(errprefix..": "..errmsg)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
529 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
530 return ok
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
531 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
532
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
533 ------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
534 -- Calls setup() on the Test Case --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
535 ------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
536
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
537 local function setup(testname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
538 if tc.__lunit_setup then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
539 return call("ERROR: "..testname..": setup() failed", tc.__lunit_setup)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
540 else
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
541 return true
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
542 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
543 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
544
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
545 ------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
546 -- Calls a single Test on the Test Case --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
547 ------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
548
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
549 local function run(testname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
550 orig_assert(is_string(testname))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
551 orig_assert(is_function(tc[testname]))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
552 local ok = call("FAIL: "..testname, tc[testname])
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
553 if not ok then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
554 stats_inc("failed")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
555 else
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
556 stats_inc("passed")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
557 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
558 return ok
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
559 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
560
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
561 ---------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
562 -- Calls teardown() on the Test Case --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
563 ---------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
564
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
565 local function teardown(testname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
566 if tc.__lunit_teardown then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
567 if not call("WARNING: "..testname..": teardown() failed", tc.__lunit_teardown) then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
568 stats_inc("warnings")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
569 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
570 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
571 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
572
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
573 ---------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
574 -- Run all Tests on a TestCase --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
575 ---------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
576
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
577 print()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
578 print("#### Running '"..tc.__lunit_name.."' ("..table.getn(tc.__lunit_tests).." Tests)...")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
579
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
580 for _, testname in ipairs(tc.__lunit_tests) do
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
581 if setup(testname) then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
582 run(testname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
583 stats_inc("run")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
584 teardown(testname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
585 else
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
586 print("WARN: Skipping '"..testname.."'...")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
587 stats_inc("notrun")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
588 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
589 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
590
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
591 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
592
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
593
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
594
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
595
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
596 ---------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
597 -- Import function --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
598 ---------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
599
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
600 function import(name)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
601
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
602 do_assert(is_string(name), "lunit.import() expects a single string as argument")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
603
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
604 local user_env = getfenv(2)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
605
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
606 --------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
607 -- Installs a specific function in the user env --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
608 --------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
609
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
610 local function install(funcname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
611 user_env[funcname] = P[funcname]
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
612 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
613
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
614
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
615 ----------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
616 -- Install functions matching a pattern in the user env --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
617 ----------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
618
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
619 local function install_pattern(pattern)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
620 for funcname, _ in pairs(P) do
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
621 if string.find(funcname, pattern) then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
622 install(funcname)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
623 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
624 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
625 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
626
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
627 ------------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
628 -- Installs assert() and all assert_xxx() in the user env --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
629 ------------------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
630
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
631 local function install_asserts()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
632 install_pattern("^assert.*")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
633 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
634
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
635 -------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
636 -- Installs all is_xxx() in the user env --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
637 -------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
638
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
639 local function install_tests()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
640 install_pattern("^is_.+")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
641 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
642
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
643 if name == "asserts" or name == "assertions" then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
644 install_asserts()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
645 elseif name == "tests" or name == "checks" then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
646 install_tests()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
647 elseif name == "all" then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
648 install_asserts()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
649 install_tests()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
650 install("TestCase")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
651 elseif string.find(name, "^assert.*") and P[name] then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
652 install(name)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
653 elseif string.find(name, "^is_.+") and P[name] then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
654 install(name)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
655 elseif name == "TestCase" then
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
656 install("TestCase")
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
657 else
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
658 error("luniit.import(): invalid function '"..name.."' to import", 2)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
659 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
660 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
661
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
662
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
663
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
664
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
665 --------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
666 -- Installs a private environment on the caller --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
667 --------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
668
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
669 function setprivfenv()
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
670 local new_env = { }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
671 local new_env_mt = { __index = getfenv(2) }
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
672 setmetatable(new_env, new_env_mt)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
673 setfenv(2, new_env)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
674 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
675
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
676
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
677
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
678
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
679 --------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
680 -- Increments a counter in the statistics table --
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
681 --------------------------------------------------
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
682
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
683 function stats_inc(varname, value)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
684 orig_assert(is_table(stats))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
685 orig_assert(is_string(varname))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
686 orig_assert(is_nil(value) or is_number(value))
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
687 if not stats[varname] then return end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
688 stats[varname] = stats[varname] + (value or 1)
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
689 end
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
690
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
691
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
692
4f81725a1e5f Added lunit 0.4a from Michael Roth (author of Lua-sqlite3)
Michael Roth <mroth@nessie.de>
parents:
diff changeset
693

mercurial