aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/ltests.c b/ltests.c
index 0b5ed90b..5ea8b080 100644
--- a/ltests.c
+++ b/ltests.c
@@ -63,10 +63,36 @@ static void pushobject (lua_State *L, const TValue *o) {
63} 63}
64 64
65 65
66static void badexit (void) {
67 /* avoid assertion failures when exiting */
68 l_memcontrol.numblocks = l_memcontrol.total = 0;
69 exit(EXIT_FAILURE);
70}
71
72
66static int tpanic (lua_State *L) { 73static int tpanic (lua_State *L) {
67 fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n", 74 fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
68 lua_tostring(L, -1)); 75 lua_tostring(L, -1));
69 return (exit(EXIT_FAILURE), 0); /* do not return to Lua */ 76 return (badexit(), 0); /* do not return to Lua */
77}
78
79
80static int islast (const char *message) {
81 size_t len = strlen(message);
82 return (len > 0 && message[len - 1] == '\n');
83}
84
85
86static void warnf (void **pud, const char *msg) {
87 if (*pud == NULL) /* continuation line? */
88 printf("%s", msg); /* print it */
89 else if (msg[0] == '*') /* expected warning? */
90 printf("Expected Lua warning: %s", msg + 1); /* print without the star */
91 else { /* a real warning; should not happen during tests */
92 fprintf(stderr, "Warning in test mode (%s), aborting...\n", msg);
93 badexit();
94 }
95 *pud = islast(msg) ? pud : NULL;
70} 96}
71 97
72 98
@@ -1405,6 +1431,10 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1405 const char *msg = getstring; 1431 const char *msg = getstring;
1406 printf("%s\n", msg); 1432 printf("%s\n", msg);
1407 } 1433 }
1434 else if EQ("warning") {
1435 const char *msg = getstring;
1436 lua_warning(L1, msg);
1437 }
1408 else if EQ("pushbool") { 1438 else if EQ("pushbool") {
1409 lua_pushboolean(L1, getnum); 1439 lua_pushboolean(L1, getnum);
1410 } 1440 }
@@ -1743,6 +1773,7 @@ static void checkfinalmem (void) {
1743int luaB_opentests (lua_State *L) { 1773int luaB_opentests (lua_State *L) {
1744 void *ud; 1774 void *ud;
1745 lua_atpanic(L, &tpanic); 1775 lua_atpanic(L, &tpanic);
1776 lua_setwarnf(L, &warnf, L);
1746 atexit(checkfinalmem); 1777 atexit(checkfinalmem);
1747 lua_assert(lua_getallocf(L, &ud) == debug_realloc); 1778 lua_assert(lua_getallocf(L, &ud) == debug_realloc);
1748 lua_assert(ud == cast_voidp(&l_memcontrol)); 1779 lua_assert(ud == cast_voidp(&l_memcontrol));