| 1 |
-- Run all unit tests in 'unit' directory |
| 2 |
|
| 3 |
local telescope = require "telescope" |
| 4 |
require "rspamd_assertions" |
| 5 |
local loaded, luacov = pcall(require, 'luacov.runner') |
| 6 |
if not loaded then |
| 7 |
luacov = { |
| 8 |
init = function() end, |
| 9 |
shutdown = function() end, |
| 10 |
run_report = function() end |
| 11 |
} |
| 12 |
end |
| 13 |
luacov.init() |
| 14 |
|
| 15 |
local contexts = {} |
| 16 |
|
| 17 |
for _,t in ipairs(tests_list) do |
| 18 |
telescope.load_contexts(t, contexts) |
| 19 |
end |
| 20 |
local function test_filter(test) |
| 21 |
return test.name:match(test_pattern) |
| 22 |
end |
| 23 |
if not test_pattern then |
| 24 |
test_filter = function(_) return true end |
| 25 |
end |
| 26 |
|
| 27 |
local buffer = {} |
| 28 |
local results = telescope.run(contexts, callbacks, test_filter) |
| 29 |
local summary, data = telescope.summary_report(contexts, results) |
| 30 |
|
| 31 |
table.insert(buffer, telescope.test_report(contexts, results)) |
| 32 |
table.insert(buffer, summary) |
| 33 |
|
| 34 |
local report = telescope.error_report(contexts, results) |
| 35 |
|
| 36 |
if report then |
| 37 |
table.insert(buffer, "") |
| 38 |
table.insert(buffer, report) |
| 39 |
end |
| 40 |
|
| 41 |
if #buffer > 0 then print(table.concat(buffer, "\n")) end |
| 42 |
|
| 43 |
for _, v in pairs(results) do |
| 44 |
if v.status_code == telescope.status_codes.err or |
| 45 |
v.status_code == telescope.status_codes.fail then |
| 46 |
os.exit(1) |
| 47 |
end |
| 48 |
end |
| 49 |
|
| 50 |
luacov:shutdown() |
| 51 |
luacov:run_report() |