summaryrefslogtreecommitdiff
path: root/tests/assertions.lua
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 17:46:24 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 17:46:24 +0200
commitae503e9498553d50cc145d26f4b3457276fc14ba (patch)
treeee8793df7baa4503dcfa13ee342a4e875e65d0d9 /tests/assertions.lua
parent3ef0616d516d8c8059380566a29852474d95e801 (diff)
Share test assertion helpers
Diffstat (limited to 'tests/assertions.lua')
-rw-r--r--tests/assertions.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/assertions.lua b/tests/assertions.lua
new file mode 100644
index 0000000..fb97be0
--- /dev/null
+++ b/tests/assertions.lua
@@ -0,0 +1,40 @@
+local M = {}
+
+function M.same(expected, actual, message)
+ if expected ~= actual then
+ error((message or "values differ")
+ .. ": expected " .. tostring(expected)
+ .. ", got " .. tostring(actual), 2)
+ end
+end
+
+function M.truthy(value, message)
+ if not value then
+ error(message or "value must be true", 2)
+ end
+end
+
+function M.falsy(value, message)
+ if value then
+ error(message or "value must be false", 2)
+ end
+end
+
+function M.fails(body, expected_text)
+ local ok, failure = pcall(body)
+ if ok then
+ error("operation must fail", 2)
+ end
+ if expected_text and not tostring(failure):find(expected_text, 1, true) then
+ error("failure does not contain '" .. expected_text .. "': " .. tostring(failure), 2)
+ end
+end
+
+function M.list_same(expected, actual)
+ M.same(#expected, #actual, "list lengths differ")
+ for index = 1, #expected do
+ M.same(expected[index], actual[index], "list item " .. tostring(index) .. " differs")
+ end
+end
+
+return M