Commit 549c00df authored by François Perrad's avatar François Perrad
Browse files

switch to Test.Assertion

parent 18f316b3
Pipeline #393397 passed with stages
in 17 seconds
......@@ -4,29 +4,30 @@ read_globals = {
'done_testing',
'skip_all',
'BAIL_OUT',
'ok',
'nok',
'is',
'isnt',
'like',
'unlike',
'cmp_ok',
'type_ok',
'subtest',
'pass',
'fail',
'require_ok',
'eq_array',
'is_deeply',
'error_is',
'error_like',
'lives_ok',
'diag',
'note',
'skip',
'todo_skip',
'skip_rest',
'todo',
-- Test.Assertion
'equals',
'not_equals',
'array_equals',
'is_cdata',
'is_function',
'is_number',
'is_table',
'same',
'falsy',
'truthy',
'fails',
'passes',
'matches',
'error_matches',
'not_errors',
'require_ok',
-- testsuite
'Point',
}
......
......@@ -93,7 +93,7 @@ rock:
bed:
hererocks bed $(BED_OPTS) --no-readline --luarocks latest --verbose
bed/bin/luarocks install lua-testmore
bed/bin/luarocks install lua-testassertion
bed/bin/luarocks install lua-coat
bed/bin/luarocks install lbc
bed/bin/luarocks install luacov
......
#! /usr/bin/lua
require 'Test.More'
require 'Test.Assertion'
plan(8)
......@@ -9,14 +9,14 @@ if not require_ok 'MessagePack' then
end
local m = require 'MessagePack'
type_ok( m, 'table' )
like( m._COPYRIGHT, 'Perrad', "_COPYRIGHT" )
like( m._DESCRIPTION, 'MessagePack', "_DESCRIPTION" )
like( m._VERSION, '^%d%.%d%.%d$', "_VERSION" )
is_table( m )
matches( m._COPYRIGHT, 'Perrad', "_COPYRIGHT" )
matches( m._DESCRIPTION, 'MessagePack', "_DESCRIPTION" )
matches( m._VERSION, '^%d%.%d%.%d$', "_VERSION" )
type_ok( m.packers, 'table', "table packers" )
type_ok( m.unpack_cursor, 'function', "function unpack_cursor" )
type_ok( m.build_ext, 'function', "function build_ext" )
is_table( m.packers, "table packers" )
is_function( m.unpack_cursor, "function unpack_cursor" )
is_function( m.build_ext, "function build_ext" )
if m.full64bits then
diag "full 64bits with Lua 5.3"
......
......@@ -2,7 +2,7 @@
local unpack = table.unpack or unpack
require 'Test.More'
require 'Test.Assertion'
local mp = require 'MessagePack'
......@@ -176,11 +176,11 @@ local mpac = string.char(unpack(t))
local i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(val, data[i], "reference " .. data[i+1])
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(val, data[i], "reference " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(val, data[i], "reference " .. data[i+1])
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(val, data[i], "reference " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
......@@ -213,9 +213,9 @@ f = io.open('cases.mpac', 'r')
local s = ltn12.source.file(f)
for _, val in mp.unpacker(s) do
if type(val) == 'table' then
is_deeply(val, data[i], "reference " .. data[i+1])
same(val, data[i], "reference " .. data[i+1])
else
is(val, data[i], "reference " .. data[i+1])
equals(val, data[i], "reference " .. data[i+1])
end
i = i + 2
end
......@@ -226,9 +226,9 @@ mp.set_string'string'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
......@@ -238,9 +238,9 @@ mp.set_string'binary'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
......@@ -251,9 +251,9 @@ mp.set_integer'signed'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
......@@ -264,9 +264,9 @@ mp.set_array'with_hole'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
......@@ -276,9 +276,9 @@ mp.set_array'always_as_map'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
......@@ -289,9 +289,9 @@ mp.set_number'float'
i = 1
for _, val in mp.unpacker(mpac) do
if type(val) == 'table' then
is_deeply(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
same(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
else
is(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
equals(mp.unpack(mp.pack(data[i])), data[i], "unpack/pack " .. data[i+1])
end
i = i + 2
end
#! /usr/bin/lua
require 'Test.More'
require 'Test.Assertion'
plan(24)
local mp = require 'MessagePack'
error_like( function ()
error_matches( function ()
mp.pack( print )
end,
"pack 'function' is unimplemented" )
end,
"pack 'function' is unimplemented" )
error_like( function ()
error_matches( function ()
mp.pack( coroutine.create(plan) )
end,
"pack 'thread' is unimplemented" )
end,
"pack 'thread' is unimplemented" )
error_like( function ()
error_matches( function ()
mp.pack( io.stdin )
end,
"pack 'userdata' is unimplemented" )
end,
"pack 'userdata' is unimplemented" )
error_like( function ()
error_matches( function ()
local a = {}
a.foo = a
mp.pack( a )
end,
"stack overflow", -- from Lua interpreter
"direct cycle" )
end,
"stack overflow", -- from Lua interpreter
"direct cycle" )
error_like( function ()
error_matches( function ()
local a = {}
local b = {}
a.foo = b
b.foo = a
mp.pack( a )
end,
"stack overflow", -- from Lua interpreter
"indirect cycle" )
end,
"stack overflow", -- from Lua interpreter
"indirect cycle" )
error_like( function ()
error_matches( function ()
mp.unpack(string.char(0xC1))
end,
"unpack '0xc1' is unimplemented" )
end,
"unpack '0xc1' is unimplemented" )
is( mp.unpack(mp.pack("text")), "text" )
equals( mp.unpack(mp.pack("text")), "text" )
error_like( function ()
error_matches( function ()
mp.unpack(mp.pack("text"):sub(1, -2))
end,
"missing bytes" )
end,
"missing bytes" )
error_like( function ()
error_matches( function ()
mp.unpack(mp.pack("text") .. "more")
end,
"extra bytes" )
end,
"extra bytes" )
error_like( function ()
error_matches( function ()
mp.unpack(mp.pack("text") .. "1")
end,
"extra bytes" )
end,
"extra bytes" )
error_like( function ()
error_matches( function ()
mp.unpack( {} )
end,
"bad argument #1 to unpack %(string expected, got table%)" )
end,
"bad argument #1 to unpack %(string expected, got table%)" )
error_like( function ()
error_matches( function ()
mp.unpacker( false )
end,
"bad argument #1 to unpacker %(string or function expected, got boolean%)" )
end,
"bad argument #1 to unpacker %(string or function expected, got boolean%)" )
error_like( function ()
error_matches( function ()
mp.unpacker( {} )
end,
"bad argument #1 to unpacker %(string or function expected, got table%)" )
end,
"bad argument #1 to unpacker %(string or function expected, got table%)" )
for _, val in mp.unpacker(string.rep(mp.pack("text"), 2)) do
is( val, "text" )
equals( val, "text" )
end
error_like( function ()
error_matches( function ()
for _, val in mp.unpacker(string.rep(mp.pack("text"), 2):sub(1, -2)) do
is( val, "text" )
equals( val, "text" )
end
end,
"missing bytes" )
end,
"missing bytes" )
error_like( function ()
error_matches( function ()
mp.set_string'bad'
end,
"bad argument #1 to set_string %(invalid option 'bad'%)" )
end,
"bad argument #1 to set_string %(invalid option 'bad'%)" )
error_like( function ()
error_matches( function ()
mp.set_number'bad'
end,
"bad argument #1 to set_number %(invalid option 'bad'%)" )
end,
"bad argument #1 to set_number %(invalid option 'bad'%)" )
error_like( function ()
error_matches( function ()
mp.set_integer'bad'
end,
"bad argument #1 to set_integer %(invalid option 'bad'%)" )
end,
"bad argument #1 to set_integer %(invalid option 'bad'%)" )
error_like( function ()
error_matches( function ()
mp.set_array'bad'
end,
"bad argument #1 to set_array %(invalid option 'bad'%)" )
end,
"bad argument #1 to set_array %(invalid option 'bad'%)" )
error_like( function ()
error_matches( function ()
mp.packers['fixext4'](nil, 1, '123')
end,
"bad length for fixext4" )
end,
"bad length for fixext4" )
lives_ok( function ()
not_errors( function ()
mp.packers['fixext4']({}, 1, '1234')
end,
"fixext4" )
end,
"fixext4" )
lives_ok( function ()
not_errors( function ()
for _ in ipairs(mp.packers) do end
end,
"cannot iterate packers" )
end,
"cannot iterate packers" )
#! /usr/bin/lua
require 'Test.More'
require 'Test.Assertion'
plan(42)
local mp = require 'MessagePack'
is( mp.unpack(mp.pack(1.0/0.0)), 1.0/0.0, "inf" )
equals( mp.unpack(mp.pack(1.0/0.0)), 1.0/0.0, "inf" )
is( mp.unpack(mp.pack(-1.0/0.0)), -1.0/0.0, "-inf" )
equals( mp.unpack(mp.pack(-1.0/0.0)), -1.0/0.0, "-inf" )
local nan = mp.unpack(mp.pack(0.0/0.0))
type_ok( nan, 'number', "nan" )
ok( nan ~= nan )
is_number( nan, "nan" )
truthy( nan ~= nan )
is( mp.pack{}:byte(), 0x90, "empty table as array" )
equals( mp.pack{}:byte(), 0x90, "empty table as array" )
local t = setmetatable( { 'a', 'b', 'c' }, { __index = { [4] = 'd' } } )
is( t[4], 'd' )
equals( t[4], 'd' )
t = mp.unpack(mp.pack(t))
is( t[2], 'b' )
is( t[4], nil, "don't follow metatable" )
equals( t[2], 'b' )
equals( t[4], nil, "don't follow metatable" )
t = setmetatable( { a = 1, b = 2, c = 3 }, { __index = { d = 4 } } )
is( t.d, 4 )
equals( t.d, 4 )
t = mp.unpack(mp.pack(t))
is( t.b, 2 )
is( t.d, nil, "don't follow metatable" )
equals( t.b, 2 )
equals( t.d, nil, "don't follow metatable" )
t = { 10, 20, nil, 40 }
mp.set_array'without_hole'
is( mp.pack(t):byte(), 0x80 + 3, "array with hole as map" )
is_deeply( mp.unpack(mp.pack(t)), t )
equals( mp.pack(t):byte(), 0x80 + 3, "array with hole as map" )
same( mp.unpack(mp.pack(t)), t )
mp.set_array'with_hole'
is( mp.pack(t):byte(), 0x90 + 4, "array with hole as array" )
is_deeply( mp.unpack(mp.pack(t)), t )
equals( mp.pack(t):byte(), 0x90 + 4, "array with hole as array" )
same( mp.unpack(mp.pack(t)), t )
mp.set_array'always_as_map'
is( mp.pack(t):byte(), 0x80 + 3, "always_as_map" )
is_deeply( mp.unpack(mp.pack(t)), t )
equals( mp.pack(t):byte(), 0x80 + 3, "always_as_map" )
same( mp.unpack(mp.pack(t)), t )
t = {}
mp.set_array'without_hole'
is( mp.pack(t):byte(), 0x90, "empty table as array" )
equals( mp.pack(t):byte(), 0x90, "empty table as array" )
mp.set_array'with_hole'
is( mp.pack(t):byte(), 0x90, "empty table as array" )
equals( mp.pack(t):byte(), 0x90, "empty table as array" )
mp.set_array'always_as_map'
is( mp.pack(t):byte(), 0x80, "empty table as map" )
equals( mp.pack(t):byte(), 0x80, "empty table as map" )
mp.set_number'float'
lives_ok( function ()
not_errors( function ()
mp.pack(1.5000001)
end,
"float 1.5000001" )
is( mp.pack(3.402824e+38), mp.pack(1.0/0.0), "float 3.402824e+38")
is( mp.pack(7e42), mp.pack(1.0/0.0), "inf (downcast double -> float)")
is( mp.pack(-7e42), mp.pack(-1.0/0.0), "-inf (downcast double -> float)")
is( mp.unpack(mp.pack(7e42)), 1.0/0.0, "inf (downcast double -> float)")
is( mp.unpack(mp.pack(-7e42)), -1.0/0.0, "-inf (downcast double -> float)")
is( mp.unpack(mp.pack(7e-46)), 0.0, "epsilon (downcast double -> float)")
is( mp.unpack(mp.pack(-7e-46)), -0.0, "-epsilon (downcast double -> float)")
end,
"float 1.5000001" )
equals( mp.pack(3.402824e+38), mp.pack(1.0/0.0), "float 3.402824e+38")
equals( mp.pack(7e42), mp.pack(1.0/0.0), "inf (downcast double -> float)")
equals( mp.pack(-7e42), mp.pack(-1.0/0.0), "-inf (downcast double -> float)")
equals( mp.unpack(mp.pack(7e42)), 1.0/0.0, "inf (downcast double -> float)")
equals( mp.unpack(mp.pack(-7e42)), -1.0/0.0, "-inf (downcast double -> float)")
equals( mp.unpack(mp.pack(7e-46)), 0.0, "epsilon (downcast double -> float)")
equals( mp.unpack(mp.pack(-7e-46)), -0.0, "-epsilon (downcast double -> float)")
if mp.long_double then
mp.set_number'double'
is( mp.pack(7e400), mp.pack(1.0/0.0), "inf (downcast long double -> double)")
is( mp.pack(-7e400), mp.pack(-1.0/0.0), "-inf (downcast long double -> double)")
is( mp.unpack(mp.pack(7e400)), 1.0/0.0, "inf (downcast long double -> double)")
is( mp.unpack(mp.pack(-7e400)), -1.0/0.0, "-inf (downcast long double -> double)")
is( mp.unpack(mp.pack(7e-400)), 0.0, "epsilon (downcast long double -> double)")
is( mp.unpack(mp.pack(-7e-400)), -0.0, "-epsilon (downcast long double -> double)")
equals( mp.pack(7e400), mp.pack(1.0/0.0), "inf (downcast long double -> double)")
equals( mp.pack(-7e400), mp.pack(-1.0/0.0), "-inf (downcast long double -> double)")
equals( mp.unpack(mp.pack(7e400)), 1.0/0.0, "inf (downcast long double -> double)")
equals( mp.unpack(mp.pack(-7e400)), -1.0/0.0, "-inf (downcast long double -> double)")
equals( mp.unpack(mp.pack(7e-400)), 0.0, "epsilon (downcast long double -> double)")
equals( mp.unpack(mp.pack(-7e-400)), -0.0, "-epsilon (downcast long double -> double)")
else
skip("no long double", 6)
end
mp.set_integer'unsigned'
is( mp.unpack(mp.pack(0xF0)), 0xF0, "packint 0xF0")
is( mp.unpack(mp.pack(0xF000)), 0xF000, "packint 0xF000")
is( mp.unpack(mp.pack(0xF0000000)), 0xF0000000, "packint 0xF0000000")
equals( mp.unpack(mp.pack(0xF0)), 0xF0, "packint 0xF0")
equals( mp.unpack(mp.pack(0xF000)), 0xF000, "packint 0xF000")
equals( mp.unpack(mp.pack(0xF0000000)), 0xF0000000, "packint 0xF0000000")
local buffer = {}
mp.packers.float(buffer, 0)
is( mp.unpack(table.concat(buffer)), 0)
equals( mp.unpack(table.concat(buffer)), 0)
if mp.small_lua then
skip("Small Lua (32 bits)", 1)
else
buffer = {}
mp.packers.double(buffer, 0)
is( mp.unpack(table.concat(buffer)), 0)
equals( mp.unpack(table.concat(buffer)), 0)
end
local mpac = string.char(0x82, 0xC0, 0x01, 0xA2, 0x69, 0x64, 0x02)
t = mp.unpack(mpac)
is( t.id, 2, "unpack map with nil as table index" )
equals( t.id, 2, "unpack map with nil as table index" )
mp.sentinel = {}
t = mp.unpack(mpac)
is( t[mp.sentinel], 1, "unpack using a sentinel for nil as table index" )
is( t.id, 2 )
equals( t[mp.sentinel], 1, "unpack using a sentinel for nil as table index" )
equals( t.id, 2 )
#! /usr/bin/lua
require 'Test.More'
require 'Test.Assertion'
plan(41)
......@@ -11,95 +11,95 @@ if mp.small_lua then
elseif mp.long_double then
skip("long double", 2)
else
is( mp.unpack(mp.pack(1.0e+300)), 1.0e+300, "1.0e+300" )
is( mp.unpack(mp.pack(math.pi)), math.pi, "pi" )
equals( mp.unpack(mp.pack(1.0e+300)), 1.0e+300, "1.0e+300" )
equals( mp.unpack(mp.pack(math.pi)), math.pi, "pi" )
end
mp.set_number'float'
local nan = mp.unpack(mp.pack(0/0))
type_ok( nan, 'number', "nan" )
ok( nan ~= nan )
is( mp.unpack(mp.pack(3.140625)), 3.140625, "3.140625" )
is_number( nan, "nan" )
truthy( nan ~= nan )
equals( mp.unpack(mp.pack(3.140625)), 3.140625, "3.140625" )
mp.set_integer'signed'
is( mp.unpack(mp.pack(2^5)), 2^5, "2^5" )
is( mp.unpack(mp.pack(-2^5)), -2^5, "-2^5" )
is( mp.unpack(mp.pack(2^11)), 2^11, "2^11" )
is( mp.unpack(mp.pack(-2^11)), -2^11, "-2^11" )
is( mp.unpack(mp.pack(2^21)), 2^21, "2^21" )
is( mp.unpack(mp.pack(-2^21)), -2^21, "-2^21" )
equals( mp.unpack(mp.pack(2^5)), 2^5, "2^5" )
equals( mp.unpack(mp.pack(-2^5)), -2^5, "-2^5" )
equals( mp.unpack(mp.pack(2^11)), 2^11, "2^11" )
equals( mp.unpack(mp.pack(-2^11)), -2^11, "-2^11" )
equals( mp.unpack(mp.pack(2^21)), 2^21, "2^21" )
equals( mp.unpack(mp.pack(-2^21)), -2^21, "-2^21" )
if mp.small_lua then
skip("Small Lua (32 bits)", 2)
else
is( mp.unpack(mp.pack(2^51)), 2^51, "2^51" )
is( mp.unpack(mp.pack(-2^51)), -2^51, "-2^51" )
equals( mp.unpack(mp.pack(2^51)), 2^51, "2^51" )
equals( mp.unpack(mp.pack(-2^51)), -2^51, "-2^51" )
end
if mp.full64bits then
is( mp.unpack(mp.pack(2^61)), 2^61, "2^61" )
is( mp.unpack(mp.pack(-2^61)), -2^61, "-2^61" )
equals( mp.unpack(mp.pack(2^61)), 2^61, "2^61" )
equals( mp.unpack(mp.pack(-2^61)), -2^61, "-2^61" )
else
skip("only 53 bits", 2)
end
mp.set_integer'unsigned'
is( mp.unpack(mp.pack(2^5)), 2^5, "2^5" )
is( mp.unpack(mp.pack(-2^5)), -2^5, "-2^5" )
is( mp.unpack(mp.pack(2^11)), 2^11, "2^11" )
is( mp.unpack(mp.pack(-2^11)), -2^11, "-2^11" )
is( mp.unpack(mp.pack(2^21)), 2^21, "2^21" )