summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/hs_parse_args_tests.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/tests/hs_parse_args_tests.c b/src/tests/hs_parse_args_tests.c
index 7b03c24..39c40fb 100644
--- a/src/tests/hs_parse_args_tests.c
+++ b/src/tests/hs_parse_args_tests.c
@@ -20,53 +20,63 @@ static int testfunc(lua_State *L) { return 0; }
#define CHECK_FAIL_BOOL(name) \
lua_pushcfunction(L, name ## _testfunc); lua_pushboolean(L, true); \
mu_assert("incorrectly succeeded in parsing boolean!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_INT(name) \
lua_pushcfunction(L, name ## _testfunc); lua_pushinteger(L, 5); \
mu_assert("incorrectly succeeded in parsing integer!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_NUM(name) \
lua_pushcfunction(L, name ## _testfunc); lua_pushnumber(L, 42.0f); \
mu_assert("incorrectly succeeded in parsing number!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_STRING(name) \
lua_pushcfunction(L, name ## _testfunc); lua_pushstring(L, "hello!"); \
mu_assert("incorrectly succeeded in parsing string!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_TABLE(name) \
lua_pushcfunction(L, name ## _testfunc); lua_getglobal(L, "debug"); \
mu_assert("incorrectly succeeded in parsing table!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_FUNC(name) \
lua_pushcfunction(L, name ## _testfunc); lua_getglobal(L, "test"); \
mu_assert("incorrectly succeeded in parsing function!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_CFUNC(name) \
lua_pushcfunction(L, name ## _testfunc); lua_pushvalue(L, -1); \
mu_assert("incorrectly succeeded in parsing C function!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_USER(name) \
lua_pushcfunction(L, name ## _testfunc); lua_newuserdata(L, sizeof(char)); \
mu_assert("incorrectly succeeded in parsing userdata!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_LIGHT(name) \
int test_data = 5; \
lua_pushcfunction(L, name ## _testfunc); lua_pushlightuserdata(L, &test_data); \
mu_assert("incorrectly succeeded in parsing light userdata!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
#define CHECK_FAIL_NIL(name) \
lua_pushcfunction(L, name ## _testfunc); lua_pushnil(L); \
mu_assert("incorrectly succeeded in parsing nil!", \
- lua_pcall(L, 1, 0, 0) != 0);
+ lua_pcall(L, 1, 0, 0) != 0); \
+ lua_pop(L, 1);
PARSE_TYPECHECK_TEST(parse_bool_typecheck, bool, hs_bool)
@@ -88,7 +98,7 @@ PARSE_TYPECHECK_TEST(parse_bool_typecheck, bool, hs_bool)
return 0;
}
-PARSE_TYPECHECK_TEST(parse_int_typecheck, int, hs_int)
+PARSE_TYPECHECK_TEST(parse_int_typecheck, lua_Integer, hs_int)
{
CHECK_FAIL_BOOL(parse_int_typecheck);
@@ -97,7 +107,9 @@ PARSE_TYPECHECK_TEST(parse_int_typecheck, int, hs_int)
mu_assert("typecheck for int failed!",
lua_pcall(L, 1, 0, 0) == 0);
- CHECK_FAIL_NUM(parse_int_typecheck);
+ // we would check for num, but in lua 5.1 there
+ // isn't a separate integer type, so it would
+ // still work
CHECK_FAIL_STRING(parse_int_typecheck);
CHECK_FAIL_TABLE(parse_int_typecheck);
CHECK_FAIL_FUNC(parse_int_typecheck);
@@ -111,7 +123,9 @@ PARSE_TYPECHECK_TEST(parse_int_typecheck, int, hs_int)
PARSE_TYPECHECK_TEST(parse_num_typecheck, lua_Number, hs_num)
{
CHECK_FAIL_BOOL(parse_num_typecheck);
- CHECK_FAIL_INT(parse_num_typecheck);
+ // we would check for int, but in lua 5.1 there
+ // isn't a separate integer type, so it would
+ // still work
lua_pushcfunction(L, parse_int_typecheck_testfunc);
lua_pushnumber(L, 42.0f);
@@ -347,7 +361,7 @@ TEST(parse_bool)
TEST(parse_int)
{
lua_pushinteger(L, 420);
- int i = 0;
+ lua_Integer i = 0;
hs_parse_args(L, hs_int(i));
mu_assert("failed to properly parse integer!", i == 420);
return 0;
@@ -411,7 +425,7 @@ int should_fail(lua_State *L)
TEST(fail_parse_noncfunc)
{
lua_pushcfunction(L, should_fail);
- lua_getglobal(L, "type");
+ lua_getglobal(L, "print");
mu_assert("incorrectly parsed non-C function!",
lua_pcall(L, 1, 0, 0) != 0);
return 0;
@@ -481,8 +495,8 @@ TEST(parse_all)
int any_index = lua_gettop(L);
bool b;
- int i;
- float f;
+ lua_Integer i;
+ lua_Number f;
char *str;
int i_tbl;
int i_func;