aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/all.lua1
-rw-r--r--testes/coroutine.lua4
-rw-r--r--testes/cstack.lua62
-rw-r--r--testes/pm.lua12
4 files changed, 65 insertions, 14 deletions
diff --git a/testes/all.lua b/testes/all.lua
index 26d24976..84ba80a6 100644
--- a/testes/all.lua
+++ b/testes/all.lua
@@ -172,6 +172,7 @@ if not _G._soft then
172 assert(f() == 'b') 172 assert(f() == 'b')
173 assert(f() == 'a') 173 assert(f() == 'a')
174end 174end
175dofile('cstack.lua')
175dofile('nextvar.lua') 176dofile('nextvar.lua')
176dofile('pm.lua') 177dofile('pm.lua')
177dofile('utf8.lua') 178dofile('utf8.lua')
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index 5674a4dd..ca30011f 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -107,7 +107,7 @@ function filter (p, g)
107 end) 107 end)
108end 108end
109 109
110local x = gen(100) 110local x = gen(80)
111local a = {} 111local a = {}
112while 1 do 112while 1 do
113 local n = x() 113 local n = x()
@@ -116,7 +116,7 @@ while 1 do
116 x = filter(n, x) 116 x = filter(n, x)
117end 117end
118 118
119assert(#a == 25 and a[#a] == 97) 119assert(#a == 22 and a[#a] == 79)
120x, a = nil 120x, a = nil
121 121
122 122
diff --git a/testes/cstack.lua b/testes/cstack.lua
new file mode 100644
index 00000000..9e5bbaef
--- /dev/null
+++ b/testes/cstack.lua
@@ -0,0 +1,62 @@
1-- $Id: testes/cstack.lua $
2-- See Copyright Notice in file all.lua
3
4print"testing C-stack overflow detection"
5
6-- Segmentation faults in these tests probably result from a C-stack
7-- overflow. To avoid these errors, recompile Lua with a smaller
8-- value for the constant 'LUAI_MAXCCALLS' or else ensure a larger
9-- stack for the program.
10
11local function checkerror (msg, f, ...)
12 local s, err = pcall(f, ...)
13 assert(not s and string.find(err, msg))
14end
15
16
17do -- simple recursion
18 local count = 0
19 local function foo ()
20 count = count + 1
21 foo()
22 end
23 checkerror("stack overflow", foo)
24 print(" maximum recursion: " .. count)
25end
26
27
28-- bug since 2.5 (C-stack overflow in recursion inside pattern matching)
29do
30 local function f (size)
31 local s = string.rep("a", size)
32 local p = string.rep(".?", size)
33 return string.match(s, p)
34 end
35 local m = f(80)
36 assert(#m == 80)
37 checkerror("too complex", f, 200000)
38end
39
40
41-- testing stack-overflow in recursive 'gsub'
42do
43 local count = 0
44 local function foo ()
45 count = count + 1
46 string.gsub("a", ".", foo)
47 end
48 checkerror("stack overflow", foo)
49 print(" maximum 'gsub' nest (calls): " .. count)
50
51 -- can be done with metamethods, too
52 count = 0
53 local t = setmetatable({}, {__index = foo})
54 foo = function ()
55 count = count + 1
56 string.gsub("a", ".", t)
57 end
58 checkerror("stack overflow", foo)
59 print(" maximum 'gsub' nest (metamethods): " .. count)
60end
61
62print'OK'
diff --git a/testes/pm.lua b/testes/pm.lua
index cdcf3bec..1afaccf6 100644
--- a/testes/pm.lua
+++ b/testes/pm.lua
@@ -237,18 +237,6 @@ checkerror("invalid capture index %%0", string.gsub, "alo", "(%0)", "a")
237checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a") 237checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a")
238checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x") 238checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x")
239 239
240-- bug since 2.5 (C-stack overflow)
241do
242 local function f (size)
243 local s = string.rep("a", size)
244 local p = string.rep(".?", size)
245 return pcall(string.match, s, p)
246 end
247 local r, m = f(80)
248 assert(r and #m == 80)
249 r, m = f(200000)
250 assert(not r and string.find(m, "too complex"))
251end
252 240
253if not _soft then 241if not _soft then
254 print("big strings") 242 print("big strings")