# HG changeset patch # User Matthew Wild # Date 1226775901 0 # Node ID 396edd2f9d2e9b3477578ba2dc93abc7105dfe7f # Parent 837c7f701a5664f172a215c56ca1b9f72c161450 Some fixes for our test runner diff -r 837c7f701a56 -r 396edd2f9d2e tests/test.lua --- a/tests/test.lua Sat Nov 15 04:28:41 2008 +0000 +++ b/tests/test.lua Sat Nov 15 19:05:01 2008 +0000 @@ -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 @@ 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 @@ end end +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"