Software /
code /
prosody
Comparison
tests/test.lua @ 6824:85578994d376
tests: Return status code depending on whether tests passed
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 Sep 2015 10:55:39 +0100 |
parent | 6602:61b6a4fc65f1 |
child | 6946:31fb9eb9edce |
comparison
equal
deleted
inserted
replaced
6823:3b07f38d70f5 | 6824:85578994d376 |
---|---|
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 | 9 local tests_passed = true; |
10 | 10 |
11 function run_all_tests() | 11 function run_all_tests() |
12 package.loaded["net.connlisteners"] = { get = function () return {} end }; | 12 package.loaded["net.connlisteners"] = { get = function () return {} end }; |
13 dotest "util.jid" | 13 dotest "util.jid" |
14 dotest "util.multitable" | 14 dotest "util.multitable" |
97 local line_hook, line_info = new_line_coverage_monitor(testname); | 97 local line_hook, line_info = new_line_coverage_monitor(testname); |
98 debug.sethook(line_hook, "l") | 98 debug.sethook(line_hook, "l") |
99 local success, ret = pcall(tests[fname]); | 99 local success, ret = pcall(tests[fname]); |
100 debug.sethook(); | 100 debug.sethook(); |
101 if not success then | 101 if not success then |
102 tests_passed = false; | |
102 print("TEST FAILED! Unit: ["..testname.."] Function: ["..fname.."]"); | 103 print("TEST FAILED! Unit: ["..testname.."] Function: ["..fname.."]"); |
103 print(" Location: "..ret:gsub(":%s*\n", "\n")); | 104 print(" Location: "..ret:gsub(":%s*\n", "\n")); |
104 line_info(fname, false, report_file); | 105 line_info(fname, false, report_file); |
105 elseif verbosity >= 2 then | 106 elseif verbosity >= 2 then |
106 print("TEST SUCCEEDED: ", testname, fname); | 107 print("TEST SUCCEEDED: ", testname, fname); |
169 local line_hook, line_info = new_line_coverage_monitor(fn); | 170 local line_hook, line_info = new_line_coverage_monitor(fn); |
170 debug.sethook(line_hook, "l") | 171 debug.sethook(line_hook, "l") |
171 local success, ret = pcall(test, f, unit); | 172 local success, ret = pcall(test, f, unit); |
172 debug.sethook(); | 173 debug.sethook(); |
173 if not success then | 174 if not success then |
175 tests_passed = false; | |
174 print("TEST FAILED! Unit: ["..unitname.."] Function: ["..name.."]"); | 176 print("TEST FAILED! Unit: ["..unitname.."] Function: ["..name.."]"); |
175 print(" Location: "..ret:gsub(":%s*\n", "\n")); | 177 print(" Location: "..ret:gsub(":%s*\n", "\n")); |
176 line_info(name, false, report_file); | 178 line_info(name, false, report_file); |
177 elseif verbosity >= 2 then | 179 elseif verbosity >= 2 then |
178 print("TEST SUCCEEDED: ", unitname, name); | 180 print("TEST SUCCEEDED: ", unitname, name); |
188 if not f then print("SUBTEST NOT FOUND: "..(msg or "(no description)")); return; end | 190 if not f then print("SUBTEST NOT FOUND: "..(msg or "(no description)")); return; end |
189 local success, ret = pcall(f); | 191 local success, ret = pcall(f); |
190 if success and verbosity >= 2 then | 192 if success and verbosity >= 2 then |
191 print("SUBTEST PASSED: "..(msg or "(no description)")); | 193 print("SUBTEST PASSED: "..(msg or "(no description)")); |
192 elseif (not success) and verbosity >= 0 then | 194 elseif (not success) and verbosity >= 0 then |
195 tests_passed = false; | |
193 print("SUBTEST FAILED: "..(msg or "(no description)")); | 196 print("SUBTEST FAILED: "..(msg or "(no description)")); |
194 error(ret, 0); | 197 error(ret, 0); |
195 end | 198 end |
196 end | 199 end |
197 | 200 |
235 return covered_lines, total_active_lines, lines_hit; | 238 return covered_lines, total_active_lines, lines_hit; |
236 end | 239 end |
237 end | 240 end |
238 | 241 |
239 run_all_tests() | 242 run_all_tests() |
243 | |
244 os.exit(tests_passed and 0 or 1); |