aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/api.lua21
-rw-r--r--testes/db.lua20
-rw-r--r--testes/locals.lua21
3 files changed, 45 insertions, 17 deletions
diff --git a/testes/api.lua b/testes/api.lua
index ed857fd0..6f35e132 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -366,7 +366,7 @@ do
366 -- "argerror" without frames 366 -- "argerror" without frames
367 assert(T.checkpanic("loadstring 4") == 367 assert(T.checkpanic("loadstring 4") ==
368 "bad argument #4 (string expected, got no value)") 368 "bad argument #4 (string expected, got no value)")
369 369
370 370
371 -- memory error 371 -- memory error
372 T.totalmem(T.totalmem()+10000) -- set low memory limit (+10k) 372 T.totalmem(T.totalmem()+10000) -- set low memory limit (+10k)
@@ -987,12 +987,12 @@ do
987 987
988 local a, b = T.testC([[ 988 local a, b = T.testC([[
989 call 0 1 # create resource 989 call 0 1 # create resource
990 pushint 34 990 pushnil
991 toclose -2 # mark call result to be closed 991 toclose -2 # mark call result to be closed
992 toclose -1 # mark number to be closed (will be ignored) 992 toclose -1 # mark nil to be closed (will be ignored)
993 return 2 993 return 2
994 ]], newresource) 994 ]], newresource)
995 assert(a[1] == 11 and b == 34) 995 assert(a[1] == 11 and b == nil)
996 assert(#openresource == 0) -- was closed 996 assert(#openresource == 0) -- was closed
997 997
998 -- repeat the test, but calling function in a 'multret' context 998 -- repeat the test, but calling function in a 'multret' context
@@ -1005,7 +1005,7 @@ do
1005 assert(#openresource == 0) -- was closed 1005 assert(#openresource == 0) -- was closed
1006 1006
1007 -- error 1007 -- error
1008 local a, b = pcall(T.testC, [[ 1008 local a, b = pcall(T.makeCfunc[[
1009 call 0 1 # create resource 1009 call 0 1 # create resource
1010 toclose -1 # mark it to be closed 1010 toclose -1 # mark it to be closed
1011 error # resource is the error object 1011 error # resource is the error object
@@ -1038,6 +1038,13 @@ do
1038 ]], newresource, check) 1038 ]], newresource, check)
1039 assert(a == 3) -- no extra items left in the stack 1039 assert(a == 3) -- no extra items left in the stack
1040 1040
1041 -- non-closable value
1042 local a, b = pcall(T.makeCfunc[[
1043 pushint 32
1044 toclose -1
1045 ]])
1046 assert(not a and string.find(b, "(C temporary)"))
1047
1041end 1048end
1042 1049
1043 1050
@@ -1249,9 +1256,9 @@ do -- closing state with no extra memory
1249 T.closestate(L) 1256 T.closestate(L)
1250 T.alloccount() 1257 T.alloccount()
1251end 1258end
1252 1259
1253do -- garbage collection with no extra memory 1260do -- garbage collection with no extra memory
1254 local L = T.newstate() 1261 local L = T.newstate()
1255 T.loadlib(L) 1262 T.loadlib(L)
1256 local res = (T.doremote(L, [[ 1263 local res = (T.doremote(L, [[
1257 _ENV = require"_G" 1264 _ENV = require"_G"
diff --git a/testes/db.lua b/testes/db.lua
index 5b243c39..976962b0 100644
--- a/testes/db.lua
+++ b/testes/db.lua
@@ -214,14 +214,14 @@ local function foo (a, ...)
214 local t = table.pack(...) 214 local t = table.pack(...)
215 for i = 1, t.n do 215 for i = 1, t.n do
216 local n, v = debug.getlocal(1, -i) 216 local n, v = debug.getlocal(1, -i)
217 assert(n == "(*vararg)" and v == t[i]) 217 assert(n == "(vararg)" and v == t[i])
218 end 218 end
219 assert(not debug.getlocal(1, -(t.n + 1))) 219 assert(not debug.getlocal(1, -(t.n + 1)))
220 assert(not debug.setlocal(1, -(t.n + 1), 30)) 220 assert(not debug.setlocal(1, -(t.n + 1), 30))
221 if t.n > 0 then 221 if t.n > 0 then
222 (function (x) 222 (function (x)
223 assert(debug.setlocal(2, -1, x) == "(*vararg)") 223 assert(debug.setlocal(2, -1, x) == "(vararg)")
224 assert(debug.setlocal(2, -t.n, x) == "(*vararg)") 224 assert(debug.setlocal(2, -t.n, x) == "(vararg)")
225 end)(430) 225 end)(430)
226 assert(... == 430) 226 assert(... == 430)
227 end 227 end
@@ -328,9 +328,9 @@ assert(a[f] and a[g] and a[assert] and a[debug.getlocal] and not a[print])
328-- tests for manipulating non-registered locals (C and Lua temporaries) 328-- tests for manipulating non-registered locals (C and Lua temporaries)
329 329
330local n, v = debug.getlocal(0, 1) 330local n, v = debug.getlocal(0, 1)
331assert(v == 0 and n == "(*temporary)") 331assert(v == 0 and n == "(C temporary)")
332local n, v = debug.getlocal(0, 2) 332local n, v = debug.getlocal(0, 2)
333assert(v == 2 and n == "(*temporary)") 333assert(v == 2 and n == "(C temporary)")
334assert(not debug.getlocal(0, 3)) 334assert(not debug.getlocal(0, 3))
335assert(not debug.getlocal(0, 0)) 335assert(not debug.getlocal(0, 0))
336 336
@@ -607,7 +607,7 @@ co = load[[
607local a = 0 607local a = 0
608-- 'A' should be visible to debugger only after its complete definition 608-- 'A' should be visible to debugger only after its complete definition
609debug.sethook(function (e, l) 609debug.sethook(function (e, l)
610 if l == 3 then a = a + 1; assert(debug.getlocal(2, 1) == "(*temporary)") 610 if l == 3 then a = a + 1; assert(debug.getlocal(2, 1) == "(temporary)")
611 elseif l == 4 then a = a + 1; assert(debug.getlocal(2, 1) == "A") 611 elseif l == 4 then a = a + 1; assert(debug.getlocal(2, 1) == "A")
612 end 612 end
613end, "l") 613end, "l")
@@ -875,15 +875,15 @@ local debug = require'debug'
875local a = 12 -- a local variable 875local a = 12 -- a local variable
876 876
877local n, v = debug.getlocal(1, 1) 877local n, v = debug.getlocal(1, 1)
878assert(n == "(*temporary)" and v == debug) -- unkown name but known value 878assert(n == "(temporary)" and v == debug) -- unkown name but known value
879n, v = debug.getlocal(1, 2) 879n, v = debug.getlocal(1, 2)
880assert(n == "(*temporary)" and v == 12) -- unkown name but known value 880assert(n == "(temporary)" and v == 12) -- unkown name but known value
881 881
882-- a function with an upvalue 882-- a function with an upvalue
883local f = function () local x; return a end 883local f = function () local x; return a end
884n, v = debug.getupvalue(f, 1) 884n, v = debug.getupvalue(f, 1)
885assert(n == "(*no name)" and v == 12) 885assert(n == "(no name)" and v == 12)
886assert(debug.setupvalue(f, 1, 13) == "(*no name)") 886assert(debug.setupvalue(f, 1, 13) == "(no name)")
887assert(a == 13) 887assert(a == 13)
888 888
889local t = debug.getinfo(f) 889local t = debug.getinfo(f)
diff --git a/testes/locals.lua b/testes/locals.lua
index 90a8b845..24681dd9 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -266,6 +266,27 @@ do -- errors in __close
266end 266end
267 267
268 268
269do
270
271 -- errors due to non-closable values
272 local function foo ()
273 local *toclose x = 34
274 end
275 local stat, msg = pcall(foo)
276 assert(not stat and string.find(msg, "variable 'x'"))
277
278
279 -- with other errors, non-closable values are ignored
280 local function foo ()
281 local *toclose x = 34
282 local *toclose y = function () error(32) end
283 end
284 local stat, msg = pcall(foo)
285 assert(not stat and msg == 32)
286
287end
288
289
269if rawget(_G, "T") then 290if rawget(_G, "T") then
270 291
271 -- memory error inside closing function 292 -- memory error inside closing function