Add tests for pcall, add error() builtin, fix assert(), error levels.

This commit is contained in:
James Roseborough
2007-10-23 00:34:04 +00:00
parent 8248cca2bf
commit 932960c846
12 changed files with 92 additions and 49 deletions

36
src/test/res/pcalls.lua Normal file
View File

@@ -0,0 +1,36 @@
-- sample lua function that returns values in reverse order
local function lc(a,b,c)
return c,b,a
end
-- sample lua function that throws a lua error
local function le(a,b,c)
error( 'sample error', 0 )
end
-- function that does a plain call to the underlying function
local function cp(f,a,b,c)
global = f(a,b,c)
return global
end
-- function that does a tail call to the underlying function
local function ct(f,a,b,c)
return f(a,b,c)
end
-- lua calls
print( 'lc(22,33,44)', lc(22,33,44) )
print( 'pcall(lc,22,33,44)', pcall(lc,22,33,44) )
print( 'pcall(le,22,33,44)', pcall(le,22,33,44) )
print( 'cp(lc,22,33,44)', cp(lc,22,33,44) )
print( 'pcall(cp,lc,22,33,44)', pcall(cp,lc,22,33,44) )
print( 'pcall(cp,le,22,33,44)', pcall(cp,le,22,33,44) )
print( 'ct(lc,22,33,44)', ct(lc,22,33,44) )
print( 'pcall(ct,lc,22,33,44)', pcall(ct,lc,22,33,44) )
print( 'pcall(ct,le,22,33,44)', pcall(ct,le,22,33,44) )
print( "assert(true,'a','b','c')", assert( true, 'a', 'b', 'c' ) )
print( "pcall(assert,true,'a','b','c')", pcall(assert, true, 'a', 'b', 'c' ) )
print( "pcall(assert,false,'a','b','c')", pcall(assert, false, 'a', 'b', 'c' ) )