diff options
author | Matthew Wild <mwild1@gmail.com> | 2008-11-15 19:05:01 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2008-11-15 19:05:01 +0000 |
commit | 22bd662f3c422ebedd7b9ce15fce128be3f55de1 (patch) | |
tree | da3f356a67ad0c9a15977b851c68d54c16105b3e /tests | |
parent | 32a4306f7afef43e355d5f1a82f9ae23ecba363b (diff) | |
download | prosody-22bd662f3c422ebedd7b9ce15fce128be3f55de1.tar.gz prosody-22bd662f3c422ebedd7b9ce15fce128be3f55de1.zip |
Some fixes for our test runner
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test.lua | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/tests/test.lua b/tests/test.lua index 108dd9a4..c0a27abd 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -1,9 +1,18 @@ local verbosity = tonumber(arg[1]) or 2; -function assert_equal(a, b) +package.path = package.path..";../?.lua"; + +require "util.import" + +local env_mt = { __index = function (t,k) return rawget(_G, k) or print("WARNING: Attempt to access nil global '"..tostring(k).."'"); end }; +function testlib_new_env(t) + return setmetatable(t or {}, env_mt); +end + +function assert_equal(a, b, message) if not (a == b) then - error(getfenv(2).__unit.."assert_equal failed: "..tostring(a).." ~= "..tostring(b), 2); + error("\n assert_equal failed: "..tostring(a).." ~= "..tostring(b)..(message and ("\n Message: "..message) or ""), 2); elseif verbosity >= 4 then print("assert_equal succeeded: "..tostring(a).." == "..tostring(b)); end @@ -52,7 +61,8 @@ function dotest(unitname) else local success, ret = pcall(tests[name], f, unit); if not success then - print("TEST FAILED: ", unitname, name, ret); + print("TEST FAILED! Unit: ["..unitname.."] Function: ["..name.."]"); + print(" Location: "..ret:gsub(":%s*\n", "\n")); elseif verbosity >= 2 then print("TEST SUCCEEDED: ", unitname, name); end @@ -60,5 +70,15 @@ function dotest(unitname) end end -dotest "util.jid" +function runtest(f, msg) + local success, ret = pcall(f); + if success and verbosity >= 2 then + print("SUBTEST PASSED: "..(msg or "(no description)")); + elseif (not success) and verbosity >= 1 then + print("SUBTEST FAILED: "..(msg or "(no description)")); + error(ret, 0); + end +end +dotest "util.jid" +dotest "core.stanza_router" |