Software /
code /
prosody
Comparison
tests/test.lua @ 569:5216efe6088b
Add hostmanager, and eventmanager
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 06 Dec 2008 03:41:49 +0000 |
parent | 519:cccd610a0ef9 |
child | 615:4ae3e81513f3 |
comparison
equal
deleted
inserted
replaced
568:b2464849c1b0 | 569:5216efe6088b |
---|---|
19 | 19 |
20 | 20 |
21 | 21 |
22 function run_all_tests() | 22 function run_all_tests() |
23 dotest "util.jid" | 23 dotest "util.jid" |
24 dotest "util.multitable" | |
24 dotest "core.stanza_router" | 25 dotest "core.stanza_router" |
25 dotest "core.s2smanager" | 26 dotest "core.s2smanager" |
26 dotest "core.configmanager" | 27 dotest "core.configmanager" |
27 | 28 |
28 dosingletest("test_sasl.lua", "latin1toutf8"); | 29 dosingletest("test_sasl.lua", "latin1toutf8"); |
38 local env_mt = { __index = function (t,k) return rawget(_G, k) or print("WARNING: Attempt to access nil global '"..tostring(k).."'"); end }; | 39 local env_mt = { __index = function (t,k) return rawget(_G, k) or print("WARNING: Attempt to access nil global '"..tostring(k).."'"); end }; |
39 function testlib_new_env(t) | 40 function testlib_new_env(t) |
40 return setmetatable(t or {}, env_mt); | 41 return setmetatable(t or {}, env_mt); |
41 end | 42 end |
42 | 43 |
43 function assert_equal(a, b, message) | 44 function assert_equal(a, b, message, level) |
44 if not (a == b) then | 45 if not (a == b) then |
45 error("\n assert_equal failed: "..tostring(a).." ~= "..tostring(b)..(message and ("\n Message: "..message) or ""), 2); | 46 error("\n assert_equal failed: "..tostring(a).." ~= "..tostring(b)..(message and ("\n Message: "..message) or ""), (level or 1) + 1); |
46 elseif verbosity >= 4 then | 47 elseif verbosity >= 4 then |
47 print("assert_equal succeeded: "..tostring(a).." == "..tostring(b)); | 48 print("assert_equal succeeded: "..tostring(a).." == "..tostring(b)); |
48 end | 49 end |
49 end | 50 end |
51 | |
52 function assert_table(a, message, level) | |
53 assert_equal(type(a), "table", message, (level or 1) + 1); | |
54 end | |
55 function assert_function(a, message, level) | |
56 assert_equal(type(a), "function", message, (level or 1) + 1); | |
57 end | |
58 function assert_string(a, message, level) | |
59 assert_equal(type(a), "string", message, (level or 1) + 1); | |
60 end | |
61 function assert_boolean(a, message) | |
62 assert_equal(type(a), "boolean", message); | |
63 end | |
64 function assert_is(a, message) | |
65 assert_equal(not not a, true, message); | |
66 end | |
67 function assert_is_not(a, message) | |
68 assert_equal(not not a, false, message); | |
69 end | |
70 | |
50 | 71 |
51 function dosingletest(testname, fname) | 72 function dosingletest(testname, fname) |
52 local tests = setmetatable({}, { __index = _G }); | 73 local tests = setmetatable({}, { __index = _G }); |
53 tests.__unit = testname; | 74 tests.__unit = testname; |
54 tests.__test = fname; | 75 tests.__test = fname; |