diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/calls.lua | 11 | ||||
| -rw-r--r-- | testes/db.lua | 3 | ||||
| -rw-r--r-- | testes/errors.lua | 25 |
3 files changed, 39 insertions, 0 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 12312d60..31028215 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -204,6 +204,17 @@ do print"testing chains of '__call'" | |||
| 204 | assert(Res[i][1] == i) | 204 | assert(Res[i][1] == i) |
| 205 | end | 205 | end |
| 206 | assert(Res[N + 1] == "a" and Res[N + 2] == "b" and Res[N + 3] == "c") | 206 | assert(Res[N + 1] == "a" and Res[N + 2] == "b" and Res[N + 3] == "c") |
| 207 | |||
| 208 | local function u (...) | ||
| 209 | local n = debug.getinfo(1, 't').extraargs | ||
| 210 | assert(select("#", ...) == n) | ||
| 211 | return n | ||
| 212 | end | ||
| 213 | |||
| 214 | for i = 0, N do | ||
| 215 | assert(u() == i) | ||
| 216 | u = setmetatable({}, {__call = u}) | ||
| 217 | end | ||
| 207 | end | 218 | end |
| 208 | 219 | ||
| 209 | 220 | ||
diff --git a/testes/db.lua b/testes/db.lua index 49ff8e3e..fc0db9ea 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
| @@ -624,6 +624,9 @@ local function f (x) | |||
| 624 | end | 624 | end |
| 625 | end | 625 | end |
| 626 | 626 | ||
| 627 | assert(debug.getinfo(print, 't').istailcall == false) | ||
| 628 | assert(debug.getinfo(print, 't').extraargs == 0) | ||
| 629 | |||
| 627 | function g(x) return f(x) end | 630 | function g(x) return f(x) end |
| 628 | 631 | ||
| 629 | function g1(x) g(x) end | 632 | function g1(x) g(x) end |
diff --git a/testes/errors.lua b/testes/errors.lua index 80d91a92..0925fe58 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -117,6 +117,31 @@ else | |||
| 117 | return 1 | 117 | return 1 |
| 118 | ]] | 118 | ]] |
| 119 | assert(string.find(res, "xuxu.-main chunk")) | 119 | assert(string.find(res, "xuxu.-main chunk")) |
| 120 | |||
| 121 | do -- tests for error messages about extra arguments from __call | ||
| 122 | local function createobj (n) | ||
| 123 | -- function that raises an error on its n-th argument | ||
| 124 | local code = string.format("argerror %d 'msg'", n) | ||
| 125 | local func = T.makeCfunc(code) | ||
| 126 | -- create a chain of 2 __call objects | ||
| 127 | local M = setmetatable({}, {__call = func}) | ||
| 128 | M = setmetatable({}, {__call = M}) | ||
| 129 | -- put it as a method for a new object | ||
| 130 | return {foo = M} | ||
| 131 | end | ||
| 132 | |||
| 133 | _G.a = createobj(1) -- error in first (extra) argument | ||
| 134 | checkmessage("a:foo()", "bad extra argument #1") | ||
| 135 | |||
| 136 | _G.a = createobj(2) -- error in second (extra) argument | ||
| 137 | checkmessage("a:foo()", "bad extra argument #2") | ||
| 138 | |||
| 139 | _G.a = createobj(3) -- error in self (after two extra arguments) | ||
| 140 | checkmessage("a:foo()", "bad self") | ||
| 141 | |||
| 142 | _G.a = createobj(4) -- error in first regular argument (after self) | ||
| 143 | checkmessage("a:foo()", "bad argument #1") | ||
| 144 | end | ||
| 120 | end | 145 | end |
| 121 | 146 | ||
| 122 | 147 | ||
