aboutsummaryrefslogtreecommitdiff
path: root/testes/db.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/db.lua')
-rw-r--r--testes/db.lua27
1 files changed, 18 insertions, 9 deletions
diff --git a/testes/db.lua b/testes/db.lua
index f891e9b8..02b96aca 100644
--- a/testes/db.lua
+++ b/testes/db.lua
@@ -16,7 +16,7 @@ end
16assert(not debug.gethook()) 16assert(not debug.gethook())
17 17
18local testline = 19 -- line where 'test' is defined 18local testline = 19 -- line where 'test' is defined
19function test (s, l, p) -- this must be line 19 19local function test (s, l, p) -- this must be line 19
20 collectgarbage() -- avoid gc during trace 20 collectgarbage() -- avoid gc during trace
21 local function f (event, line) 21 local function f (event, line)
22 assert(event == 'line') 22 assert(event == 'line')
@@ -50,7 +50,7 @@ end
50 50
51 51
52-- test file and string names truncation 52-- test file and string names truncation
53a = "function f () end" 53local a = "function f () end"
54local function dostring (s, x) return load(s, x)() end 54local function dostring (s, x) return load(s, x)() end
55dostring(a) 55dostring(a)
56assert(debug.getinfo(f).short_src == string.format('[string "%s"]', a)) 56assert(debug.getinfo(f).short_src == string.format('[string "%s"]', a))
@@ -72,7 +72,8 @@ dostring(a, string.format("=%s", string.rep('x', 500)))
72assert(string.find(debug.getinfo(f).short_src, "^x*$")) 72assert(string.find(debug.getinfo(f).short_src, "^x*$"))
73dostring(a, "=") 73dostring(a, "=")
74assert(debug.getinfo(f).short_src == "") 74assert(debug.getinfo(f).short_src == "")
75a = nil; f = nil; 75_G.a = nil; _G.f = nil;
76_G[string.rep("p", 400)] = nil
76 77
77 78
78repeat 79repeat
@@ -120,6 +121,7 @@ else
120end 121end
121]], {2,3,4,7}) 122]], {2,3,4,7})
122 123
124
123test([[ 125test([[
124local function foo() 126local function foo()
125end 127end
@@ -128,6 +130,7 @@ A = 1
128A = 2 130A = 2
129A = 3 131A = 3
130]], {2, 3, 2, 4, 5, 6}) 132]], {2, 3, 2, 4, 5, 6})
133_G.A = nil
131 134
132 135
133test([[-- 136test([[--
@@ -175,6 +178,8 @@ end
175 178
176test([[for i=1,4 do a=1 end]], {1,1,1,1}) 179test([[for i=1,4 do a=1 end]], {1,1,1,1})
177 180
181_G.a = nil
182
178 183
179do -- testing line info/trace with large gaps in source 184do -- testing line info/trace with large gaps in source
180 185
@@ -194,6 +199,7 @@ do -- testing line info/trace with large gaps in source
194 end 199 end
195 end 200 end
196end 201end
202_G.a = nil
197 203
198 204
199do -- testing active lines 205do -- testing active lines
@@ -287,7 +293,6 @@ foo(200, 3, 4)
287local a = {} 293local a = {}
288for i = 1, (_soft and 100 or 1000) do a[i] = i end 294for i = 1, (_soft and 100 or 1000) do a[i] = i end
289foo(table.unpack(a)) 295foo(table.unpack(a))
290a = nil
291 296
292 297
293 298
@@ -307,13 +312,14 @@ do -- test hook presence in debug info
307 debug.sethook() 312 debug.sethook()
308 assert(count == 4) 313 assert(count == 4)
309end 314end
315_ENV.a = nil
310 316
311 317
312-- hook table has weak keys 318-- hook table has weak keys
313assert(getmetatable(debug.getregistry()._HOOKKEY).__mode == 'k') 319assert(getmetatable(debug.getregistry()._HOOKKEY).__mode == 'k')
314 320
315 321
316a = {}; L = nil 322a = {}; local L = nil
317local glob = 1 323local glob = 1
318local oldglob = glob 324local oldglob = glob
319debug.sethook(function (e,l) 325debug.sethook(function (e,l)
@@ -354,7 +360,7 @@ function foo()
354end; foo() -- set L 360end; foo() -- set L
355-- check line counting inside strings and empty lines 361-- check line counting inside strings and empty lines
356 362
357_ = 'alo\ 363local _ = 'alo\
358alo' .. [[ 364alo' .. [[
359 365
360]] 366]]
@@ -403,6 +409,7 @@ function g(a,b) return (a+1) + f() end
403 409
404assert(g(0,0) == 30) 410assert(g(0,0) == 30)
405 411
412_G.f, _G.g = nil
406 413
407debug.sethook(nil); 414debug.sethook(nil);
408assert(not debug.gethook()) 415assert(not debug.gethook())
@@ -446,7 +453,7 @@ local function collectlocals (level)
446end 453end
447 454
448 455
449X = nil 456local X = nil
450a = {} 457a = {}
451function a:f (a, b, ...) local arg = {...}; local c = 13 end 458function a:f (a, b, ...) local arg = {...}; local c = 13 end
452debug.sethook(function (e) 459debug.sethook(function (e)
@@ -469,6 +476,7 @@ a:f(1,2,3,4,5)
469assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) 476assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil)
470assert(XX == 12) 477assert(XX == 12)
471assert(not debug.gethook()) 478assert(not debug.gethook())
479_G.XX = nil
472 480
473 481
474-- testing access to local variables in return hook (bug in 5.2) 482-- testing access to local variables in return hook (bug in 5.2)
@@ -593,6 +601,7 @@ end
593 601
594debug.sethook() 602debug.sethook()
595 603
604local g, g1
596 605
597-- tests for tail calls 606-- tests for tail calls
598local function f (x) 607local function f (x)
@@ -638,7 +647,7 @@ h(false)
638debug.sethook() 647debug.sethook()
639assert(b == 2) -- two tail calls 648assert(b == 2) -- two tail calls
640 649
641lim = _soft and 3000 or 30000 650local lim = _soft and 3000 or 30000
642local function foo (x) 651local function foo (x)
643 if x==0 then 652 if x==0 then
644 assert(debug.getinfo(2).what == "main") 653 assert(debug.getinfo(2).what == "main")
@@ -940,7 +949,7 @@ end
940 949
941 950
942print("testing debug functions on chunk without debug info") 951print("testing debug functions on chunk without debug info")
943prog = [[-- program to be loaded without debug information (strip) 952local prog = [[-- program to be loaded without debug information (strip)
944local debug = require'debug' 953local debug = require'debug'
945local a = 12 -- a local variable 954local a = 12 -- a local variable
946 955