Skip to content

Commit f823dd2

Browse files
committed
Update test/common to handle errors in the test function even when not explicitly testing for errors
1 parent 3c30c99 commit f823dd2

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

vstruct/test/common.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,24 @@ function test.autotest(name, format, buffer, data, output)
5454
output = output or buffer
5555

5656
if type(data) ~= "table" then data = {data} end
57-
58-
local unpacked = vstruct.unpack(format, buffer)
59-
local packed = vstruct.pack(format, unpacked)
60-
61-
record(name.." (U )", eq(unpacked, data), unpack(unpacked))
62-
record(name.." (UP)", eq(packed, output), test.od(packed))
6357

64-
local packed = vstruct.pack(format, data)
65-
local unpacked = vstruct.unpack(format, packed)
66-
67-
record(name.." (P )", eq(packed, output), test.od(packed))
68-
record(name.." (PU)", eq(unpacked, data), unpack(unpacked))
58+
local function tester()
59+
local unpacked = vstruct.unpack(format, buffer)
60+
local packed = vstruct.pack(format, unpacked)
61+
62+
record(name.." (U )", eq(unpacked, data), unpack(unpacked))
63+
record(name.." (UP)", eq(packed, output), test.od(packed))
64+
65+
local packed = vstruct.pack(format, data)
66+
local unpacked = vstruct.unpack(format, packed)
67+
68+
record(name.." (P )", eq(packed, output), test.od(packed))
69+
record(name.." (PU)", eq(unpacked, data), unpack(unpacked))
70+
end
71+
72+
xpcall(tester, function(err)
73+
record(name.." !ERR", false, "Error executing test: "..err)
74+
end)
6975
end
7076

7177
-- test whether an error is properly reported

0 commit comments

Comments
 (0)