]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Assertions for table comparsion that are nicer to use 2501/head
authorMikhail Galanin <mgalanin@mimecast.com>
Wed, 19 Sep 2018 13:51:01 +0000 (14:51 +0100)
committerMikhail Galanin <mgalanin@mimecast.com>
Wed, 19 Sep 2018 13:51:01 +0000 (14:51 +0100)
test/lua/rspamd_assertions.lua [new file with mode: 0644]
test/lua/tests.lua

diff --git a/test/lua/rspamd_assertions.lua b/test/lua/rspamd_assertions.lua
new file mode 100644 (file)
index 0000000..0f2eb36
--- /dev/null
@@ -0,0 +1,21 @@
+local logger = require "rspamd_logger"
+local telescope = require "telescope"
+local util  = require 'lua_util'
+
+local function rspamd_assert_equals(tbl)
+  return tbl.expect == tbl.actual
+end
+
+local function rspamd_assert_equals_msg(_, tbl)
+  return logger.slog(
+    "Failed asserting that \n  (actual)   %1 \n equals to\n  (expected) %2",
+    tbl.actual, tbl.expect
+  )
+end
+
+local function rspamd_assert_table_equals(tbl)
+  return util.table_cmp(tbl.expect, tbl.actual)
+end
+
+telescope.make_assertion("rspamd_eq",       rspamd_assert_equals_msg, rspamd_assert_equals)
+telescope.make_assertion("rspamd_table_eq", rspamd_assert_equals_msg, rspamd_assert_table_equals)
index 8f64bba4ec562b392be0eb15860c72fc3a596f0b..99d509de0c29dfbce8b2dd5e4d3f206a6b6cc6a7 100644 (file)
@@ -1,6 +1,7 @@
 -- Run all unit tests in 'unit' directory
 
 local telescope = require "telescope"
+require "rspamd_assertions"
 
 local contexts = {}