diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-10-27 08:43:22 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-10-27 08:43:22 +0100 |
| commit | 5e5bcf37450d07f7f2812255bbd1df35d8e6ce75 (patch) | |
| tree | 14cac4a19d4e35b60f0a56c948f45b158881daa5 /unit_tests/scripts/misc/verbose_errors.lua | |
| parent | 3b4848ca1c4ea40d0e052cdc81bb9f66ce882a8a (diff) | |
| download | lanes-5e5bcf37450d07f7f2812255bbd1df35d8e6ce75.tar.gz lanes-5e5bcf37450d07f7f2812255bbd1df35d8e6ce75.tar.bz2 lanes-5e5bcf37450d07f7f2812255bbd1df35d8e6ce75.zip | |
verbose_errors improvement
* Use std::format instead of sprintf for verbose errors when decoding table keys
* Add a unit test for the different table key types
Diffstat (limited to 'unit_tests/scripts/misc/verbose_errors.lua')
| -rw-r--r-- | unit_tests/scripts/misc/verbose_errors.lua | 34 |
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 @@ | |||
| 1 | local fixture = require "fixture" -- require fixture before lanes so that it is not registered and will cause transfer errors | ||
| 2 | local lanes = require("lanes").configure{verbose_errors = true} | ||
| 3 | local l = lanes.linda{name = "my linda"} | ||
| 4 | |||
| 5 | |||
| 6 | local 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 | ||
| 27 | end | ||
| 28 | |||
| 29 | do_test("bob") | ||
| 30 | do_test(true) | ||
| 31 | do_test(false) | ||
| 32 | do_test(42) | ||
| 33 | do_test(42.44) | ||
| 34 | do_test(lanes.null) | ||
