diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/all.lua | 1 | ||||
| -rw-r--r-- | testes/coroutine.lua | 4 | ||||
| -rw-r--r-- | testes/cstack.lua | 62 | ||||
| -rw-r--r-- | testes/pm.lua | 12 |
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') |
| 174 | end | 174 | end |
| 175 | dofile('cstack.lua') | ||
| 175 | dofile('nextvar.lua') | 176 | dofile('nextvar.lua') |
| 176 | dofile('pm.lua') | 177 | dofile('pm.lua') |
| 177 | dofile('utf8.lua') | 178 | dofile('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) |
| 108 | end | 108 | end |
| 109 | 109 | ||
| 110 | local x = gen(100) | 110 | local x = gen(80) |
| 111 | local a = {} | 111 | local a = {} |
| 112 | while 1 do | 112 | while 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) |
| 117 | end | 117 | end |
| 118 | 118 | ||
| 119 | assert(#a == 25 and a[#a] == 97) | 119 | assert(#a == 22 and a[#a] == 79) |
| 120 | x, a = nil | 120 | x, 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 | |||
| 4 | print"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 | |||
| 11 | local function checkerror (msg, f, ...) | ||
| 12 | local s, err = pcall(f, ...) | ||
| 13 | assert(not s and string.find(err, msg)) | ||
| 14 | end | ||
| 15 | |||
| 16 | |||
| 17 | do -- 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) | ||
| 25 | end | ||
| 26 | |||
| 27 | |||
| 28 | -- bug since 2.5 (C-stack overflow in recursion inside pattern matching) | ||
| 29 | do | ||
| 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) | ||
| 38 | end | ||
| 39 | |||
| 40 | |||
| 41 | -- testing stack-overflow in recursive 'gsub' | ||
| 42 | do | ||
| 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) | ||
| 60 | end | ||
| 61 | |||
| 62 | print'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") | |||
| 237 | checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a") | 237 | checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a") |
| 238 | checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x") | 238 | checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x") |
| 239 | 239 | ||
| 240 | -- bug since 2.5 (C-stack overflow) | ||
| 241 | do | ||
| 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")) | ||
| 251 | end | ||
| 252 | 240 | ||
| 253 | if not _soft then | 241 | if not _soft then |
| 254 | print("big strings") | 242 | print("big strings") |
