You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tests.lua 1.2KB

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