diff options
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 60 |
1 files changed, 22 insertions, 38 deletions
| @@ -63,11 +63,8 @@ static void pushobject (lua_State *L, const TValue *o) { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | static void badexit (const char *fmt, ...) { | 66 | static void badexit (const char *fmt, const char *s) { |
| 67 | va_list argp; | 67 | fprintf(stderr, fmt, s); |
| 68 | va_start(argp, fmt); | ||
| 69 | vfprintf(stderr, fmt, argp); | ||
| 70 | va_end(argp); | ||
| 71 | /* avoid assertion failures when exiting */ | 68 | /* avoid assertion failures when exiting */ |
| 72 | l_memcontrol.numblocks = l_memcontrol.total = 0; | 69 | l_memcontrol.numblocks = l_memcontrol.total = 0; |
| 73 | exit(EXIT_FAILURE); | 70 | exit(EXIT_FAILURE); |
| @@ -81,52 +78,35 @@ static int tpanic (lua_State *L) { | |||
| 81 | } | 78 | } |
| 82 | 79 | ||
| 83 | 80 | ||
| 84 | static int islast (const char *message) { | ||
| 85 | size_t len = strlen(message); | ||
| 86 | return (len > 0 && message[len - 1] == '\n'); | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | /* | 81 | /* |
| 91 | ** Warning function for tests. Fist, it concatenates all parts of | 82 | ** Warning function for tests. Fist, it concatenates all parts of |
| 92 | ** a warning in buffer 'buff'. Then: | 83 | ** a warning in buffer 'buff'. Then: |
| 93 | ** messages starting with '#' are shown on standard output (used to | 84 | ** - messages starting with '#' are shown on standard output (used to |
| 94 | ** test explicit warnings); | 85 | ** test explicit warnings); |
| 95 | ** messages containing '@' are stored in global '_WARN' (used to test | 86 | ** - messages containing '@' are stored in global '_WARN' (used to test |
| 96 | ** errors that generate warnings); | 87 | ** errors that generate warnings); |
| 97 | ** other messages abort the tests (they represent real warning conditions; | 88 | ** - other messages abort the tests (they represent real warning |
| 98 | ** the standard tests should not generate these conditions unexpectedly). | 89 | ** conditions; the standard tests should not generate these conditions |
| 90 | ** unexpectedly). | ||
| 99 | */ | 91 | */ |
| 100 | static void warnf (void **pud, const char *msg) { | 92 | static void warnf (void *ud, const char *msg, int tocont) { |
| 101 | static char buff[200]; /* should be enough for tests... */ | 93 | static char buff[200] = ""; /* should be enough for tests... */ |
| 102 | static int cont = 0; /* message to be continued */ | 94 | if (strlen(msg) >= sizeof(buff) - strlen(buff)) |
| 103 | if (cont) { /* continuation? */ | 95 | badexit("%s", "warnf-buffer overflow"); |
| 104 | if (strlen(msg) >= sizeof(buff) - strlen(buff)) | 96 | strcat(buff, msg); /* add new message to current warning */ |
| 105 | badexit("warnf-buffer overflow"); | 97 | if (!tocont) { /* message finished? */ |
| 106 | strcat(buff, msg); /* add new message to current warning */ | ||
| 107 | } | ||
| 108 | else { /* new warning */ | ||
| 109 | if (strlen(msg) >= sizeof(buff)) | ||
| 110 | badexit("warnf-buffer overflow"); | ||
| 111 | strcpy(buff, msg); /* start a new warning */ | ||
| 112 | } | ||
| 113 | if (!islast(msg)) /* message not finished yet? */ | ||
| 114 | cont = 1; /* wait for more */ | ||
| 115 | else { /* handle message */ | ||
| 116 | cont = 0; /* prepare for next message */ | ||
| 117 | if (buff[0] == '#') /* expected warning? */ | 98 | if (buff[0] == '#') /* expected warning? */ |
| 118 | printf("Expected Lua warning: %s", buff); /* print it */ | 99 | printf("Expected Lua warning: %s\n", buff); /* print it */ |
| 119 | else if (strchr(buff, '@') != NULL) { /* warning for test purposes? */ | 100 | else if (strchr(buff, '@') != NULL) { /* warning for test purposes? */ |
| 120 | lua_State *L = cast(lua_State *, *pud); | 101 | lua_State *L = cast(lua_State *, ud); |
| 121 | lua_unlock(L); | 102 | lua_unlock(L); |
| 122 | lua_pushstring(L, buff); | 103 | lua_pushstring(L, buff); |
| 123 | lua_setglobal(L, "_WARN"); /* assign message to global '_WARN' */ | 104 | lua_setglobal(L, "_WARN"); /* assign message to global '_WARN' */ |
| 124 | lua_lock(L); | 105 | lua_lock(L); |
| 125 | return; | ||
| 126 | } | 106 | } |
| 127 | else { /* a real warning; should not happen during tests */ | 107 | else /* a real warning; should not happen during tests */ |
| 128 | badexit("Unexpected warning in test mode: %s\naborting...\n", buff); | 108 | badexit("Unexpected warning in test mode: %s\naborting...\n", buff); |
| 129 | } | 109 | buff[0] = '\0'; /* prepare buffer for next warning */ |
| 130 | } | 110 | } |
| 131 | } | 111 | } |
| 132 | 112 | ||
| @@ -1466,9 +1446,13 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 1466 | const char *msg = getstring; | 1446 | const char *msg = getstring; |
| 1467 | printf("%s\n", msg); | 1447 | printf("%s\n", msg); |
| 1468 | } | 1448 | } |
| 1449 | else if EQ("warningC") { | ||
| 1450 | const char *msg = getstring; | ||
| 1451 | lua_warning(L1, msg, 1); | ||
| 1452 | } | ||
| 1469 | else if EQ("warning") { | 1453 | else if EQ("warning") { |
| 1470 | const char *msg = getstring; | 1454 | const char *msg = getstring; |
| 1471 | lua_warning(L1, msg); | 1455 | lua_warning(L1, msg, 0); |
| 1472 | } | 1456 | } |
| 1473 | else if EQ("pushbool") { | 1457 | else if EQ("pushbool") { |
| 1474 | lua_pushboolean(L1, getnum); | 1458 | lua_pushboolean(L1, getnum); |
