diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 64 |
1 files changed, 47 insertions, 17 deletions
@@ -79,32 +79,62 @@ static int tpanic (lua_State *L) { | |||
79 | 79 | ||
80 | /* | 80 | /* |
81 | ** Warning function for tests. Fist, it concatenates all parts of | 81 | ** Warning function for tests. Fist, it concatenates all parts of |
82 | ** a warning in buffer 'buff'. Then: | 82 | ** a warning in buffer 'buff'. Then, it has three modes: |
83 | ** - messages starting with '#' are shown on standard output (used to | 83 | ** - 0.normal: messages starting with '#' are shown on standard output; |
84 | ** test explicit warnings); | ||
85 | ** - messages containing '@' are stored in global '_WARN' (used to test | ||
86 | ** errors that generate warnings); | ||
87 | ** - other messages abort the tests (they represent real warning | 84 | ** - other messages abort the tests (they represent real warning |
88 | ** conditions; the standard tests should not generate these conditions | 85 | ** conditions; the standard tests should not generate these conditions |
89 | ** unexpectedly). | 86 | ** unexpectedly); |
87 | ** - 1.allow: all messages are shown; | ||
88 | ** - 2.store: all warnings go to the global '_WARN'; | ||
90 | */ | 89 | */ |
91 | static void warnf (void *ud, const char *msg, int tocont) { | 90 | static void warnf (void *ud, const char *msg, int tocont) { |
92 | static char buff[200] = ""; /* should be enough for tests... */ | 91 | static char buff[200] = ""; /* should be enough for tests... */ |
92 | static int onoff = 1; | ||
93 | static int mode = 0; /* start in normal mode */ | ||
94 | static int lasttocont = 0; | ||
95 | if (!lasttocont && !tocont && *msg == '@') { /* control message? */ | ||
96 | if (buff[0] != '\0') | ||
97 | badexit("Control warning during warning: %s\naborting...\n", msg); | ||
98 | if (strcmp(msg + 1, "off") == 0) | ||
99 | onoff = 0; | ||
100 | else if (strcmp(msg + 1, "on") == 0) | ||
101 | onoff = 1; | ||
102 | else if (strcmp(msg + 1, "normal") == 0) | ||
103 | mode = 0; | ||
104 | else if (strcmp(msg + 1, "allow") == 0) | ||
105 | mode = 1; | ||
106 | else if (strcmp(msg + 1, "store") == 0) | ||
107 | mode = 2; | ||
108 | else | ||
109 | badexit("Invalid control warning in test mode: %s\naborting...\n", msg); | ||
110 | return; | ||
111 | } | ||
112 | lasttocont = tocont; | ||
93 | if (strlen(msg) >= sizeof(buff) - strlen(buff)) | 113 | if (strlen(msg) >= sizeof(buff) - strlen(buff)) |
94 | badexit("%s", "warnf-buffer overflow"); | 114 | badexit("%s", "warnf-buffer overflow"); |
95 | strcat(buff, msg); /* add new message to current warning */ | 115 | strcat(buff, msg); /* add new message to current warning */ |
96 | if (!tocont) { /* message finished? */ | 116 | if (!tocont) { /* message finished? */ |
97 | if (buff[0] == '#') /* expected warning? */ | 117 | switch (mode) { |
98 | printf("Expected Lua warning: %s\n", buff); /* print it */ | 118 | case 0: { /* normal */ |
99 | else if (strchr(buff, '@') != NULL) { /* warning for test purposes? */ | 119 | if (buff[0] != '#' && onoff) /* unexpected warning? */ |
100 | lua_State *L = cast(lua_State *, ud); | 120 | badexit("Unexpected warning in test mode: %s\naborting...\n", buff); |
101 | lua_unlock(L); | 121 | /* else */ /* FALLTHROUGH */ |
102 | lua_pushstring(L, buff); | 122 | } |
103 | lua_setglobal(L, "_WARN"); /* assign message to global '_WARN' */ | 123 | case 1: { /* allow */ |
104 | lua_lock(L); | 124 | if (onoff) |
105 | } | 125 | fprintf(stderr, "Lua warning: %s\n", buff); /* print warning */ |
106 | else /* a real warning; should not happen during tests */ | 126 | break; |
107 | badexit("Unexpected warning in test mode: %s\naborting...\n", buff); | 127 | } |
128 | case 2: { /* store */ | ||
129 | lua_State *L = cast(lua_State *, ud); | ||
130 | lua_unlock(L); | ||
131 | lua_pushstring(L, buff); | ||
132 | lua_setglobal(L, "_WARN"); /* assign message to global '_WARN' */ | ||
133 | lua_lock(L); | ||
134 | buff[0] = '\0'; /* prepare buffer for next warning */ | ||
135 | break; | ||
136 | } | ||
137 | } | ||
108 | buff[0] = '\0'; /* prepare buffer for next warning */ | 138 | buff[0] = '\0'; /* prepare buffer for next warning */ |
109 | } | 139 | } |
110 | } | 140 | } |