Software /
code /
prosody
Comparison
tests/test.lua @ 271:396edd2f9d2e
Some fixes for our test runner
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 15 Nov 2008 19:05:01 +0000 |
parent | 28:4a238233f278 |
child | 301:fcb7e63630ae |
comparison
equal
deleted
inserted
replaced
270:837c7f701a56 | 271:396edd2f9d2e |
---|---|
1 | 1 |
2 local verbosity = tonumber(arg[1]) or 2; | 2 local verbosity = tonumber(arg[1]) or 2; |
3 | 3 |
4 function assert_equal(a, b) | 4 package.path = package.path..";../?.lua"; |
5 | |
6 require "util.import" | |
7 | |
8 local env_mt = { __index = function (t,k) return rawget(_G, k) or print("WARNING: Attempt to access nil global '"..tostring(k).."'"); end }; | |
9 function testlib_new_env(t) | |
10 return setmetatable(t or {}, env_mt); | |
11 end | |
12 | |
13 function assert_equal(a, b, message) | |
5 if not (a == b) then | 14 if not (a == b) then |
6 error(getfenv(2).__unit.."assert_equal failed: "..tostring(a).." ~= "..tostring(b), 2); | 15 error("\n assert_equal failed: "..tostring(a).." ~= "..tostring(b)..(message and ("\n Message: "..message) or ""), 2); |
7 elseif verbosity >= 4 then | 16 elseif verbosity >= 4 then |
8 print("assert_equal succeeded: "..tostring(a).." == "..tostring(b)); | 17 print("assert_equal succeeded: "..tostring(a).." == "..tostring(b)); |
9 end | 18 end |
10 end | 19 end |
11 | 20 |
50 print("WARNING: ", unitname.."."..name.." has no test!"); | 59 print("WARNING: ", unitname.."."..name.." has no test!"); |
51 end | 60 end |
52 else | 61 else |
53 local success, ret = pcall(tests[name], f, unit); | 62 local success, ret = pcall(tests[name], f, unit); |
54 if not success then | 63 if not success then |
55 print("TEST FAILED: ", unitname, name, ret); | 64 print("TEST FAILED! Unit: ["..unitname.."] Function: ["..name.."]"); |
65 print(" Location: "..ret:gsub(":%s*\n", "\n")); | |
56 elseif verbosity >= 2 then | 66 elseif verbosity >= 2 then |
57 print("TEST SUCCEEDED: ", unitname, name); | 67 print("TEST SUCCEEDED: ", unitname, name); |
58 end | 68 end |
59 end | 69 end |
60 end | 70 end |
61 end | 71 end |
62 | 72 |
73 function runtest(f, msg) | |
74 local success, ret = pcall(f); | |
75 if success and verbosity >= 2 then | |
76 print("SUBTEST PASSED: "..(msg or "(no description)")); | |
77 elseif (not success) and verbosity >= 1 then | |
78 print("SUBTEST FAILED: "..(msg or "(no description)")); | |
79 error(ret, 0); | |
80 end | |
81 end | |
82 | |
63 dotest "util.jid" | 83 dotest "util.jid" |
64 | 84 dotest "core.stanza_router" |