diff options
Diffstat (limited to 'testes/errors.lua')
-rw-r--r-- | testes/errors.lua | 25 |
1 files changed, 23 insertions, 2 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 = {} |