assert_equal('./test/test_assert-gooder.lua:'..curline(-3)..': '..'assertion failed! bad argument #1 \'a\' to the anonymous function at ./test/test_assert-gooder.lua:'..curline(-4)..' (string expected, but got number 2)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-3)..': '..'assertion failed! bad argument #1 \'a\' to \'f\' (string expected, but got number 2)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad key "b" in local \'a\' (string expected, but got number 39)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad key 2 in local \'a\' (string expected, but got number 2)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad key 2 in local \'a\' (string expected, but got number 2)',msg)
assert_equal('[string "return function(a) assert(type(a) == \'string\'..."]:1: '..'assertion failed! bad argument #1 \'a\' to the anonymous function from loaded string (string expected, but got number 42)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-3)..': '..'assertion failed! expression `a == 3 and math.floor(2.522) == 2 or 5 == n` evaluated to false (a was nil, n was nil)',msg)
end)
SUITE:addTest('really complicated expression with modified global',function()
assert_equal('./test/test_assert-gooder.lua:'..curline(-3)..': '..'assertion failed! expression `a == 3 and math.floor(2.522) == 2 or 5 == n and tonumber` evaluated to false (a was nil, n was nil, standard-function tonumber was nil)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-3)..': '..'assertion failed! this assert will always fail, as it\'s body is `false`. assumingly this should be an unreachable part of \'f\'',msg)
end)
SUITE:addTest('constant nil',function()
local_,msg=pcall(function()
assert(nil)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! this assert will always fail, as it\'s body is `nil`. assumingly this should be an unreachable part of the anonymous function at ./test/test_assert-gooder.lua:'..curline(-3),msg)
SUITE:addTest('length of sequence EQUAL',function()
local_,msg=pcall(function()
localseq={1,2,3,4}
assert(#seq==5)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad length of local \'seq\' (length 5 expected, but got length 4)',msg)
end)
SUITE:addTest('length of sequence LESS THAN',function()
local_,msg=pcall(function()
localseq={1,2,3,4}
assert(#seq<3)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad length of local \'seq\' (length less than 3 expected, but got length 4)',msg)
end)
SUITE:addTest('length of sequence COMPARE',function()
local_,msg=pcall(function()
localseq_a={1,2,3,4}
localseq_b={1,2,3}
assert(#seq_a==#seq_b)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad lengths of locals \'seq_a\' and \'seq_b\' (equal lengths expected, but got lengths 4 and 3)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad of local \'obj\' (table similar to { a: string, b: number, ... } expected, but got { a = 42, b = "euclidian fantasyland" })',msg)
end)
SUITE:addTest('table with more keys',function()
-- obj now has an extra key, this is reflected in the error
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad of local \'obj\' (table similar to { a: string, b: number, ... } expected, but got { a = 42, b = "euclidian fantasyland", ... })',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (value of a should be key in local "obj", but was "hullo". close keys in "obj" include "hello", "world" and "there")',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (number less than 5 expected, but got 6)',msg)
end)
SUITE:addTest('Number above something',function()
local_,msg=pcall(function()
locala=6
assert(a>10)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (number greater than 10 expected, but got 6)',msg)
end)
SUITE:addTest('Number between something',function()
local_,msg=pcall(function()
locala=11
assert(a<10and5<a)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (number in range ]5,10[ expected, but got 6)',msg)
end)
SUITE:addTest('Number between something 2',function()
local_,msg=pcall(function()
locala=11
assert(a<10and7<=a)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (number in range [7,10[ expected, but got 6)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (positive number expected, but got negative number -20)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (integer expected, but got decimal number 5.21)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (even number expected, but got odd number 5)',msg)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (odd number expected, but got even number 6)',msg)
end)
SUITE:addTest('Divisible by 3',function()
local_,msg=pcall(function()
locala=7
assert(a%3==0)
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'assertion failed! bad local \'a\' (integer divisible by 3 expected, but got integer 7 with remainder 1)',msg)
assert(type(a)=='string','expected string not %s',type(a))
end)
assert_equal('./test/test_assert-gooder.lua:'..curline(-2)..': '..'expected string not number: bad local \'a\' (string expected, but got number 2)',msg)