aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts/misc/verbose_errors.lua
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/scripts/misc/verbose_errors.lua')
-rw-r--r--unit_tests/scripts/misc/verbose_errors.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/unit_tests/scripts/misc/verbose_errors.lua b/unit_tests/scripts/misc/verbose_errors.lua
new file mode 100644
index 0000000..40948ca
--- /dev/null
+++ b/unit_tests/scripts/misc/verbose_errors.lua
@@ -0,0 +1,34 @@
1local fixture = require "fixture" -- require fixture before lanes so that it is not registered and will cause transfer errors
2local lanes = require("lanes").configure{verbose_errors = true}
3local l = lanes.linda{name = "my linda"}
4
5
6local do_test = function(key_)
7 local t = {[key_] = fixture.newuserdata()}
8 local b, e = pcall(l.send, l, "k", t)
9 assert(b == false and type(e) == "string")
10 local t_key = type(key_)
11 if t_key == "string" then
12 local x, y = string.find(e, "arg#2." .. key_, 1, true)
13 assert(x and y, "got " .. e)
14 elseif t_key == "boolean" then
15 local x, y = string.find(e, "arg#2[" .. tostring(key_) .. "]", 1, true)
16 assert(x and y, "got " .. e)
17 elseif t_key == "number" then
18 local x, y = string.find(e, "arg#2[" .. key_ .. "]", 1, true)
19 assert(x and y, "got " .. e)
20 elseif t_key == "userdata" then
21 local t_name
22 -- light userdata is formatted by std::format, where the pointer is written as a lowercase hex literal
23 local expected = "arg#2[U:0x" .. string.lower(string.match(tostring(key_), "userdata: (%x+)")) .. "]"
24 local x, y = string.find(e, expected, 1, true)
25 assert(x and y, "expecting " .. expected .. " got " .. e)
26 end
27end
28
29do_test("bob")
30do_test(true)
31do_test(false)
32do_test(42)
33do_test(42.44)
34do_test(lanes.null)