diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-09-19 14:51:01 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-09-19 14:51:01 +0100 |
commit | bd3b9f376ec0dd4a3fd7364d9dcffd4a84da01e0 (patch) | |
tree | 3bb7e43e7a05de89b99dd738e087e219765ca9bc | |
parent | 3f158ae4b49660d38f02bcca6b08f66fce974c19 (diff) | |
download | rspamd-bd3b9f376ec0dd4a3fd7364d9dcffd4a84da01e0.tar.gz rspamd-bd3b9f376ec0dd4a3fd7364d9dcffd4a84da01e0.zip |
[Test] Assertions for table comparsion that are nicer to use
-rw-r--r-- | test/lua/rspamd_assertions.lua | 21 | ||||
-rw-r--r-- | test/lua/tests.lua | 1 |
2 files changed, 22 insertions, 0 deletions
diff --git a/test/lua/rspamd_assertions.lua b/test/lua/rspamd_assertions.lua new file mode 100644 index 000000000..0f2eb3626 --- /dev/null +++ b/test/lua/rspamd_assertions.lua @@ -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) diff --git a/test/lua/tests.lua b/test/lua/tests.lua index 8f64bba4e..99d509de0 100644 --- a/test/lua/tests.lua +++ b/test/lua/tests.lua @@ -1,6 +1,7 @@ -- Run all unit tests in 'unit' directory local telescope = require "telescope" +require "rspamd_assertions" local contexts = {} |