diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/errors.lua | 25 | ||||
| -rw-r--r-- | testes/main.lua | 5 | ||||
| -rw-r--r-- | testes/sort.lua | 2 |
3 files changed, 28 insertions, 4 deletions
diff --git a/testes/errors.lua b/testes/errors.lua index 027e1b03..adc111fd 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -45,7 +45,7 @@ end | |||
| 45 | -- test error message with no extra info | 45 | -- test error message with no extra info |
| 46 | assert(doit("error('hi', 0)") == 'hi') | 46 | assert(doit("error('hi', 0)") == 'hi') |
| 47 | 47 | ||
| 48 | -- test error message with no info | 48 | -- test nil error message |
| 49 | assert(doit("error()") == nil) | 49 | assert(doit("error()") == nil) |
| 50 | 50 | ||
| 51 | 51 | ||
| @@ -555,7 +555,7 @@ if not _soft then | |||
| 555 | 555 | ||
| 556 | -- error in error handling | 556 | -- error in error handling |
| 557 | local res, msg = xpcall(error, error) | 557 | local res, msg = xpcall(error, error) |
| 558 | assert(not res and type(msg) == 'string') | 558 | assert(not res and msg == 'error in error handling') |
| 559 | print('+') | 559 | print('+') |
| 560 | 560 | ||
| 561 | local function f (x) | 561 | local function f (x) |
| @@ -586,6 +586,27 @@ if not _soft then | |||
| 586 | end | 586 | end |
| 587 | 587 | ||
| 588 | 588 | ||
| 589 | do -- errors in error handle that not necessarily go forever | ||
| 590 | local function err (n) -- function to be used as message handler | ||
| 591 | -- generate an error unless n is zero, so that there is a limited | ||
| 592 | -- loop of errors | ||
| 593 | if type(n) ~= "number" then -- some other error? | ||
| 594 | return n -- report it | ||
| 595 | elseif n == 0 then | ||
| 596 | return "END" -- that will be the final message | ||
| 597 | else error(n - 1) -- does the loop | ||
| 598 | end | ||
| 599 | end | ||
| 600 | |||
| 601 | local res, msg = xpcall(error, err, 170) | ||
| 602 | assert(not res and msg == "END") | ||
| 603 | |||
| 604 | -- too many levels | ||
| 605 | local res, msg = xpcall(error, err, 300) | ||
| 606 | assert(not res and msg == "C stack overflow") | ||
| 607 | end | ||
| 608 | |||
| 609 | |||
| 589 | do | 610 | do |
| 590 | -- non string messages | 611 | -- non string messages |
| 591 | local t = {} | 612 | local t = {} |
diff --git a/testes/main.lua b/testes/main.lua index 1aa7b217..e0e9cbe8 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
| @@ -310,8 +310,11 @@ checkprogout("ZYX)\nXYZ)\n") | |||
| 310 | -- bug since 5.2: finalizer called when closing a state could | 310 | -- bug since 5.2: finalizer called when closing a state could |
| 311 | -- subvert finalization order | 311 | -- subvert finalization order |
| 312 | prepfile[[ | 312 | prepfile[[ |
| 313 | -- should be called last | 313 | -- ensure tables will be collected only at the end of the program |
| 314 | collectgarbage"stop" | ||
| 315 | |||
| 314 | print("creating 1") | 316 | print("creating 1") |
| 317 | -- this finalizer should be called last | ||
| 315 | setmetatable({}, {__gc = function () print(1) end}) | 318 | setmetatable({}, {__gc = function () print(1) end}) |
| 316 | 319 | ||
| 317 | print("creating 2") | 320 | print("creating 2") |
diff --git a/testes/sort.lua b/testes/sort.lua index 965e1534..290b199e 100644 --- a/testes/sort.lua +++ b/testes/sort.lua | |||
| @@ -199,7 +199,7 @@ do | |||
| 199 | __index = function (_,k) pos1 = k end, | 199 | __index = function (_,k) pos1 = k end, |
| 200 | __newindex = function (_,k) pos2 = k; error() end, }) | 200 | __newindex = function (_,k) pos2 = k; error() end, }) |
| 201 | local st, msg = pcall(table.move, a, f, e, t) | 201 | local st, msg = pcall(table.move, a, f, e, t) |
| 202 | assert(not st and not msg and pos1 == x and pos2 == y) | 202 | assert(not st and pos1 == x and pos2 == y) |
| 203 | end | 203 | end |
| 204 | checkmove(1, maxI, 0, 1, 0) | 204 | checkmove(1, maxI, 0, 1, 0) |
| 205 | checkmove(0, maxI - 1, 1, maxI - 1, maxI) | 205 | checkmove(0, maxI - 1, 1, maxI - 1, maxI) |
