summaryrefslogtreecommitdiffstats
path: root/test/lua/tests.lua
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 21:30:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 21:30:40 +0000
commit133a45c109da5310add55824db21af5239951f93 (patch)
treeba6ac4c0a950a0dda56451944315d66409923918 /test/lua/tests.lua
parentInitial commit. (diff)
downloadrspamd-133a45c109da5310add55824db21af5239951f93.tar.xz
rspamd-133a45c109da5310add55824db21af5239951f93.zip
Adding upstream version 3.8.1.upstream/3.8.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/lua/tests.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/lua/tests.lua b/test/lua/tests.lua
new file mode 100644
index 0000000..82c5469
--- /dev/null
+++ b/test/lua/tests.lua
@@ -0,0 +1,51 @@
+-- Run all unit tests in 'unit' directory
+
+local telescope = require "telescope"
+require "rspamd_assertions"
+local loaded, luacov = pcall(require, 'luacov.runner')
+if not loaded then
+ luacov = {
+ init = function() end,
+ shutdown = function() end,
+ run_report = function() end
+ }
+end
+luacov.init()
+
+local contexts = {}
+
+for _,t in ipairs(tests_list) do
+ telescope.load_contexts(t, contexts)
+end
+local function test_filter(test)
+ return test.name:match(test_pattern)
+end
+if not test_pattern then
+ test_filter = function(_) return true end
+end
+
+local buffer = {}
+local results = telescope.run(contexts, callbacks, test_filter)
+local summary, data = telescope.summary_report(contexts, results)
+
+table.insert(buffer, telescope.test_report(contexts, results))
+table.insert(buffer, summary)
+
+local report = telescope.error_report(contexts, results)
+
+if report then
+ table.insert(buffer, "")
+ table.insert(buffer, report)
+end
+
+if #buffer > 0 then print(table.concat(buffer, "\n")) end
+
+for _, v in pairs(results) do
+ if v.status_code == telescope.status_codes.err or
+ v.status_code == telescope.status_codes.fail then
+ os.exit(1)
+ end
+end
+
+luacov:shutdown()
+luacov:run_report()