diff options
-rw-r--r-- | compat53/module.lua | 14 | ||||
-rwxr-xr-x | tests/test.lua | 15 |
2 files changed, 27 insertions, 2 deletions
diff --git a/compat53/module.lua b/compat53/module.lua index 56c9932..4450bd5 100644 --- a/compat53/module.lua +++ b/compat53/module.lua | |||
@@ -147,6 +147,20 @@ if lua_version < "5.3" then | |||
147 | end | 147 | end |
148 | 148 | ||
149 | 149 | ||
150 | -- assert should allow non-string error objects | ||
151 | do | ||
152 | function M.assert(cond, ...) | ||
153 | if cond then | ||
154 | return cond, ... | ||
155 | elseif select('#', ...) > 0 then | ||
156 | error((...), 0) | ||
157 | else | ||
158 | error("assertion failed!", 0) | ||
159 | end | ||
160 | end | ||
161 | end | ||
162 | |||
163 | |||
150 | -- ipairs should respect __index metamethod | 164 | -- ipairs should respect __index metamethod |
151 | do | 165 | do |
152 | local function ipairs_iterator(st, var) | 166 | local function ipairs_iterator(st, var) |
diff --git a/tests/test.lua b/tests/test.lua index 9ac27d4..7e9d57f 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
@@ -45,14 +45,25 @@ end | |||
45 | package.path = "../?.lua;../?/init.lua;"..package.path | 45 | package.path = "../?.lua;../?/init.lua;"..package.path |
46 | package.cpath = "./?-"..V..".so;./?-"..V..".dll;./?.so;./?.dll" | 46 | package.cpath = "./?-"..V..".so;./?-"..V..".dll;./?.so;./?.dll" |
47 | if mode == "module" then | 47 | if mode == "module" then |
48 | print( "testing Lua API using `compat53.module` ..." ) | 48 | print("testing Lua API using `compat53.module` ...") |
49 | _ENV = require("compat53.module") | 49 | _ENV = require("compat53.module") |
50 | if setfenv then setfenv(1, _ENV) end | 50 | if setfenv then setfenv(1, _ENV) end |
51 | else | 51 | else |
52 | print( "testing Lua API using `compat53` ..." ) | 52 | print("testing Lua API using `compat53` ...") |
53 | require("compat53") | 53 | require("compat53") |
54 | end | 54 | end |
55 | 55 | ||
56 | |||
57 | ___'' | ||
58 | do | ||
59 | print("assert", F(pcall(assert, false))) | ||
60 | print("assert", F(pcall(assert, false, nil))) | ||
61 | print("assert", F(pcall(assert, false, "error msg"))) | ||
62 | print("assert", F(pcall(assert, nil, {}))) | ||
63 | print("assert", F(pcall(assert, 1, 2, 3))) | ||
64 | end | ||
65 | |||
66 | |||
56 | ___'' | 67 | ___'' |
57 | do | 68 | do |
58 | local t = setmetatable({}, { __index = { 1, false, "three" } }) | 69 | local t = setmetatable({}, { __index = { 1, false, "three" } }) |