diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2017-09-16 17:19:35 +0200 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2017-09-16 17:19:35 +0200 |
| commit | 09b201c87c904066e1de5d44cf1e02538970c168 (patch) | |
| tree | e56be07e08699f920482212f07342acf8f9526ae /tests/testmod.c | |
| parent | 3b52d81dcf1b5d6d49e1837612e207b2cab6b74d (diff) | |
| download | lua-compat-5.3-09b201c87c904066e1de5d44cf1e02538970c168.tar.gz lua-compat-5.3-09b201c87c904066e1de5d44cf1e02538970c168.tar.bz2 lua-compat-5.3-09b201c87c904066e1de5d44cf1e02538970c168.zip | |
Add tests for `luaL_load{buffer,file}x`.
Fix bug regarding empty input in `lua_load`.
Adapt error message and error code.
Diffstat (limited to 'tests/testmod.c')
| -rw-r--r-- | tests/testmod.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/testmod.c b/tests/testmod.c index 868136b..1034d20 100644 --- a/tests/testmod.c +++ b/tests/testmod.c | |||
| @@ -274,6 +274,33 @@ static int test_exec (lua_State *L) { | |||
| 274 | return luaL_execresult(L, system(cmd)); | 274 | return luaL_execresult(L, system(cmd)); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | static int test_loadstring (lua_State *L) { | ||
| 278 | size_t len = 0; | ||
| 279 | char const* s = luaL_checklstring(L, 1, &len); | ||
| 280 | char const* mode = luaL_optstring(L, 2, "bt"); | ||
| 281 | lua_pushinteger(L, luaL_loadbufferx(L, s, len, s, mode)); | ||
| 282 | return 2; | ||
| 283 | } | ||
| 284 | |||
| 285 | static int test_loadfile (lua_State *L) { | ||
| 286 | char filename[L_tmpnam+1] = { 0 }; | ||
| 287 | size_t len = 0; | ||
| 288 | char const* s = luaL_checklstring(L, 1, &len); | ||
| 289 | char const* mode = luaL_optstring(L, 2, "bt"); | ||
| 290 | if (tmpnam(filename)) { | ||
| 291 | FILE* f = fopen(filename, "wb"); | ||
| 292 | if (f) { | ||
| 293 | fwrite(s, 1, len, f); | ||
| 294 | fclose(f); | ||
| 295 | lua_pushinteger(L, luaL_loadfilex(L, filename, mode)); | ||
| 296 | remove(filename); | ||
| 297 | return 2; | ||
| 298 | } else | ||
| 299 | remove(filename); | ||
| 300 | } | ||
| 301 | return 0; | ||
| 302 | } | ||
| 303 | |||
| 277 | 304 | ||
| 278 | static const luaL_Reg funcs[] = { | 305 | static const luaL_Reg funcs[] = { |
| 279 | { "isinteger", test_isinteger }, | 306 | { "isinteger", test_isinteger }, |
| @@ -297,6 +324,8 @@ static const luaL_Reg funcs[] = { | |||
| 297 | { "pushstring", test_pushstring }, | 324 | { "pushstring", test_pushstring }, |
| 298 | { "buffer", test_buffer }, | 325 | { "buffer", test_buffer }, |
| 299 | { "exec", test_exec }, | 326 | { "exec", test_exec }, |
| 327 | { "loadstring", test_loadstring }, | ||
| 328 | { "loadfile", test_loadfile }, | ||
| 300 | { NULL, NULL } | 329 | { NULL, NULL } |
| 301 | }; | 330 | }; |
| 302 | 331 | ||
