Comparison

tests/test.lua @ 509:32899c8a6fe5

Add test for latin1toutf8 (which passes)
author Matthew Wild <mwild1@gmail.com>
date Sun, 30 Nov 2008 18:57:23 +0000
parent 470:2f9d42fdeffa
child 519:cccd610a0ef9
comparison
equal deleted inserted replaced
508:4fd60ae97535 509:32899c8a6fe5
2 function run_all_tests() 2 function run_all_tests()
3 dotest "util.jid" 3 dotest "util.jid"
4 dotest "core.stanza_router" 4 dotest "core.stanza_router"
5 dotest "core.s2smanager" 5 dotest "core.s2smanager"
6 dotest "core.configmanager" 6 dotest "core.configmanager"
7
8 dosingletest("test_sasl.lua", "latin1toutf8");
7 end 9 end
8 10
9 local verbosity = tonumber(arg[1]) or 2; 11 local verbosity = tonumber(arg[1]) or 2;
10 12
11 package.path = package.path..";../?.lua"; 13 package.path = package.path..";../?.lua";
21 function assert_equal(a, b, message) 23 function assert_equal(a, b, message)
22 if not (a == b) then 24 if not (a == b) then
23 error("\n assert_equal failed: "..tostring(a).." ~= "..tostring(b)..(message and ("\n Message: "..message) or ""), 2); 25 error("\n assert_equal failed: "..tostring(a).." ~= "..tostring(b)..(message and ("\n Message: "..message) or ""), 2);
24 elseif verbosity >= 4 then 26 elseif verbosity >= 4 then
25 print("assert_equal succeeded: "..tostring(a).." == "..tostring(b)); 27 print("assert_equal succeeded: "..tostring(a).." == "..tostring(b));
28 end
29 end
30
31 function dosingletest(testname, fname)
32 local tests = setmetatable({}, { __index = _G });
33 tests.__unit = testname;
34 tests.__test = fname;
35 local chunk, err = loadfile(testname);
36 if not chunk then
37 print("WARNING: ", "Failed to load tests for "..testname, err);
38 return;
39 end
40
41 setfenv(chunk, tests);
42 local success, err = pcall(chunk);
43 if not success then
44 print("WARNING: ", "Failed to initialise tests for "..testname, err);
45 return;
46 end
47
48 if type(tests[fname]) ~= "function" then
49 error(testname.." has no test '"..fname.."'", 0);
50 end
51
52
53 local line_hook, line_info = new_line_coverage_monitor(testname);
54 debug.sethook(line_hook, "l")
55 local success, ret = pcall(tests[fname]);
56 debug.sethook();
57 if not success then
58 print("TEST FAILED! Unit: ["..testname.."] Function: ["..fname.."]");
59 print(" Location: "..ret:gsub(":%s*\n", "\n"));
60 line_info(fname, false, report_file);
61 elseif verbosity >= 2 then
62 print("TEST SUCCEEDED: ", testname, fname);
63 print(string.format("TEST COVERED %d/%d lines", line_info(fname, true, report_file)));
64 else
65 line_info(name, success, report_file);
26 end 66 end
27 end 67 end
28 68
29 function dotest(unitname) 69 function dotest(unitname)
30 local tests = setmetatable({}, { __index = _G }); 70 local tests = setmetatable({}, { __index = _G });