Skip to content

Commit

Permalink
Add a test to ensure that our luajit is working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper93 authored and arch1t3cht committed Jan 6, 2025
1 parent da7d1da commit 6eb8d57
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
14 changes: 3 additions & 11 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,9 @@ endif
luajit = dependency('luajit', version: '>=2.0.0', required: get_option('system_luajit'),
allow_fallback: false, method: 'pkg-config')
if luajit.found() and luajit.type_name() != 'internal'
luajit_test = cc.run('''#include <lauxlib.h>
int main(void)
{
lua_State *L = luaL_newstate();
if (!L) return 1;
// This is valid in lua 5.2, but a syntax error in 5.1
const char testprogram[] = "function foo() while true do break return end end";
return luaL_loadstring(L, testprogram) == LUA_ERRSYNTAX;
}''', dependencies: luajit)

if luajit_test.returncode() == 1
luajit_test = cc.run(files('tests/tests/luajit_52.c'), dependencies: luajit)

if luajit_test.returncode() != 0
if get_option('system_luajit')
error('System luajit found but not compiled in 5.2 mode')
else
Expand Down
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ runner = executable(
)

test('gtest main', runner)
test('luajit-52', executable('luajit-52', 'tests/luajit_52.c', dependencies: luajit))

# setup test env
if host_machine.system() == 'windows'
Expand Down
32 changes: 32 additions & 0 deletions tests/tests/luajit_52.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>

#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>

int main(void) {
int ret = 0;

lua_State *L = luaL_newstate();
if (!L)
return 1;

luaL_openlibs(L);

const char *test = "function foo() while true do table.pack(1,2) break return end end foo()";
if (luaL_loadstring(L, test) == LUA_ERRSYNTAX) {
printf("%s\n", lua_tostring(L, -1));
ret = 2;
goto exit;
}

if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
printf("%s\n", lua_tostring(L, -1));
ret = 3;
goto exit;
}

exit:
lua_close(L);
return ret;
}

0 comments on commit 6eb8d57

Please sign in to comment.