diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-20 13:42:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-20 13:42:26 -0300 |
commit | be78aeae4c429d7d68af3a3e1b0cf8e52fcff160 (patch) | |
tree | e81d25014e238f589997f109ba10a875c3a875dc | |
parent | 5bc47fe83087e0686f4639d031801837846e4c65 (diff) | |
download | lua-be78aeae4c429d7d68af3a3e1b0cf8e52fcff160.tar.gz lua-be78aeae4c429d7d68af3a3e1b0cf8e52fcff160.tar.bz2 lua-be78aeae4c429d7d68af3a3e1b0cf8e52fcff160.zip |
Default for warnings changed to "off"
Warnings are mostly a tool to help developers (e.g., by showing hidden
error messages); regular users usually don't need to see them.
-rwxr-xr-x | all | 2 | ||||
-rw-r--r-- | lauxlib.c | 2 | ||||
-rw-r--r-- | ltests.c | 2 | ||||
-rw-r--r-- | lua.c | 10 | ||||
-rw-r--r-- | manual/manual.of | 4 | ||||
-rw-r--r-- | testes/all.lua | 5 | ||||
-rw-r--r-- | testes/coroutine.lua | 1 | ||||
-rw-r--r-- | testes/gc.lua | 2 | ||||
-rw-r--r-- | testes/locals.lua | 1 | ||||
-rw-r--r-- | testes/main.lua | 11 |
10 files changed, 23 insertions, 17 deletions
@@ -2,7 +2,7 @@ make -s -j | |||
2 | cd testes/libs; make -s | 2 | cd testes/libs; make -s |
3 | cd .. # back to directory 'testes' | 3 | cd .. # back to directory 'testes' |
4 | ulimit -S -s 2000 | 4 | ulimit -S -s 2000 |
5 | if { ../lua all.lua; } then | 5 | if { ../lua -W all.lua; } then |
6 | echo -e "\n\n final OK!!!!\n\n" | 6 | echo -e "\n\n final OK!!!!\n\n" |
7 | else | 7 | else |
8 | echo -e "\n\n >>>> BUG!!!!\n\n" | 8 | echo -e "\n\n >>>> BUG!!!!\n\n" |
@@ -1037,7 +1037,7 @@ LUALIB_API lua_State *luaL_newstate (void) { | |||
1037 | lua_atpanic(L, &panic); | 1037 | lua_atpanic(L, &panic); |
1038 | warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0); | 1038 | warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0); |
1039 | luaL_ref(L, LUA_REGISTRYINDEX); /* make sure it won't be collected */ | 1039 | luaL_ref(L, LUA_REGISTRYINDEX); /* make sure it won't be collected */ |
1040 | *warnstate = 1; /* next message starts a new warning */ | 1040 | *warnstate = 0; /* default is warnings off */ |
1041 | lua_setwarnf(L, warnf, warnstate); | 1041 | lua_setwarnf(L, warnf, warnstate); |
1042 | } | 1042 | } |
1043 | return L; | 1043 | return L; |
@@ -92,7 +92,7 @@ static int tpanic (lua_State *L) { | |||
92 | static void warnf (void *ud, const char *msg, int tocont) { | 92 | static void warnf (void *ud, const char *msg, int tocont) { |
93 | lua_State *L = cast(lua_State *, ud); | 93 | lua_State *L = cast(lua_State *, ud); |
94 | static char buff[200] = ""; /* should be enough for tests... */ | 94 | static char buff[200] = ""; /* should be enough for tests... */ |
95 | static int onoff = 1; | 95 | static int onoff = 0; |
96 | static int mode = 0; /* start in normal mode */ | 96 | static int mode = 0; /* start in normal mode */ |
97 | static int lasttocont = 0; | 97 | static int lasttocont = 0; |
98 | if (!lasttocont && !tocont && *msg == '@') { /* control message? */ | 98 | if (!lasttocont && !tocont && *msg == '@') { /* control message? */ |
@@ -73,7 +73,7 @@ static void print_usage (const char *badoption) { | |||
73 | " -l name require library 'name' into global 'name'\n" | 73 | " -l name require library 'name' into global 'name'\n" |
74 | " -v show version information\n" | 74 | " -v show version information\n" |
75 | " -E ignore environment variables\n" | 75 | " -E ignore environment variables\n" |
76 | " -q turn warnings off\n" | 76 | " -W turn warnings on\n" |
77 | " -- stop handling options\n" | 77 | " -- stop handling options\n" |
78 | " - stop handling options and execute stdin\n" | 78 | " - stop handling options and execute stdin\n" |
79 | , | 79 | , |
@@ -264,7 +264,7 @@ static int collectargs (char **argv, int *first) { | |||
264 | return has_error; /* invalid option */ | 264 | return has_error; /* invalid option */ |
265 | args |= has_E; | 265 | args |= has_E; |
266 | break; | 266 | break; |
267 | case 'q': | 267 | case 'W': |
268 | if (argv[i][2] != '\0') /* extra characters? */ | 268 | if (argv[i][2] != '\0') /* extra characters? */ |
269 | return has_error; /* invalid option */ | 269 | return has_error; /* invalid option */ |
270 | break; | 270 | break; |
@@ -295,7 +295,7 @@ static int collectargs (char **argv, int *first) { | |||
295 | 295 | ||
296 | /* | 296 | /* |
297 | ** Processes options 'e' and 'l', which involve running Lua code, and | 297 | ** Processes options 'e' and 'l', which involve running Lua code, and |
298 | ** 'q', which also affects the state. | 298 | ** 'W', which also affects the state. |
299 | ** Returns 0 if some code raises an error. | 299 | ** Returns 0 if some code raises an error. |
300 | */ | 300 | */ |
301 | static int runargs (lua_State *L, char **argv, int n) { | 301 | static int runargs (lua_State *L, char **argv, int n) { |
@@ -315,8 +315,8 @@ static int runargs (lua_State *L, char **argv, int n) { | |||
315 | if (status != LUA_OK) return 0; | 315 | if (status != LUA_OK) return 0; |
316 | break; | 316 | break; |
317 | } | 317 | } |
318 | case 'q': | 318 | case 'W': |
319 | lua_warning(L, "@off", 0); /* no warnings */ | 319 | lua_warning(L, "@on", 0); /* warnings on */ |
320 | break; | 320 | break; |
321 | } | 321 | } |
322 | } | 322 | } |
diff --git a/manual/manual.of b/manual/manual.of index a3990d33..292d1e51 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -8735,7 +8735,7 @@ The options are: | |||
8735 | @item{@T{-i}| enters interactive mode after running @rep{script};} | 8735 | @item{@T{-i}| enters interactive mode after running @rep{script};} |
8736 | @item{@T{-v}| prints version information;} | 8736 | @item{@T{-v}| prints version information;} |
8737 | @item{@T{-E}| ignores environment variables;} | 8737 | @item{@T{-E}| ignores environment variables;} |
8738 | @item{@T{-q}| turn warnings off;} | 8738 | @item{@T{-W}| turn warnings on;} |
8739 | @item{@T{--}| stops handling options;} | 8739 | @item{@T{--}| stops handling options;} |
8740 | @item{@T{-}| executes @id{stdin} as a file and stops handling options.} | 8740 | @item{@T{-}| executes @id{stdin} as a file and stops handling options.} |
8741 | } | 8741 | } |
@@ -8761,7 +8761,7 @@ setting the values of | |||
8761 | @Lid{package.path} and @Lid{package.cpath} | 8761 | @Lid{package.path} and @Lid{package.cpath} |
8762 | with the default paths defined in @id{luaconf.h}. | 8762 | with the default paths defined in @id{luaconf.h}. |
8763 | 8763 | ||
8764 | The options @T{-e}, @T{-l}, and @T{-q} are handled in | 8764 | The options @T{-e}, @T{-l}, and @T{-W} are handled in |
8765 | the order they appear. | 8765 | the order they appear. |
8766 | For instance, an invocation like | 8766 | For instance, an invocation like |
8767 | @verbatim{ | 8767 | @verbatim{ |
diff --git a/testes/all.lua b/testes/all.lua index 42809b9a..db074dd8 100644 --- a/testes/all.lua +++ b/testes/all.lua | |||
@@ -5,8 +5,8 @@ | |||
5 | 5 | ||
6 | local version = "Lua 5.4" | 6 | local version = "Lua 5.4" |
7 | if _VERSION ~= version then | 7 | if _VERSION ~= version then |
8 | warn("This test suite is for ", version, | 8 | io.stderr:write("This test suite is for ", version, |
9 | ", not for ", _VERSION, "\nExiting tests") | 9 | ", not for ", _VERSION, "\nExiting tests") |
10 | return | 10 | return |
11 | end | 11 | end |
12 | 12 | ||
@@ -210,6 +210,7 @@ if #msgs > 0 then | |||
210 | end | 210 | end |
211 | 211 | ||
212 | print("(there should be two warnings now)") | 212 | print("(there should be two warnings now)") |
213 | warn("@on") | ||
213 | warn("#This is ", "an expected", " warning") | 214 | warn("#This is ", "an expected", " warning") |
214 | warn("@off") | 215 | warn("@off") |
215 | warn("******** THIS WARNING SHOULD NOT APPEAR **********") | 216 | warn("******** THIS WARNING SHOULD NOT APPEAR **********") |
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 4fc23261..79bbf2ea 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
@@ -163,6 +163,7 @@ do | |||
163 | assert(not X and coroutine.status(co) == "dead") | 163 | assert(not X and coroutine.status(co) == "dead") |
164 | 164 | ||
165 | -- error closing a coroutine | 165 | -- error closing a coroutine |
166 | warn("@on") | ||
166 | local x = 0 | 167 | local x = 0 |
167 | co = coroutine.create(function() | 168 | co = coroutine.create(function() |
168 | local y <close> = func2close(function (self,err) | 169 | local y <close> = func2close(function (self,err) |
diff --git a/testes/gc.lua b/testes/gc.lua index 34854d6f..bb4e3493 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
@@ -369,7 +369,7 @@ if T then | |||
369 | s[n] = i | 369 | s[n] = i |
370 | end | 370 | end |
371 | 371 | ||
372 | warn("@store") | 372 | warn("@on"); warn("@store") |
373 | collectgarbage() | 373 | collectgarbage() |
374 | assert(string.find(_WARN, "error in __gc metamethod")) | 374 | assert(string.find(_WARN, "error in __gc metamethod")) |
375 | assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = nil | 375 | assert(string.match(_WARN, "@(.-)@") == "expected"); _WARN = nil |
diff --git a/testes/locals.lua b/testes/locals.lua index b4de523d..58ad18cc 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
@@ -313,6 +313,7 @@ local function checkwarn (msg) | |||
313 | end | 313 | end |
314 | end | 314 | end |
315 | 315 | ||
316 | warn("@on") | ||
316 | 317 | ||
317 | do print("testing errors in __close") | 318 | do print("testing errors in __close") |
318 | 319 | ||
diff --git a/testes/main.lua b/testes/main.lua index 5d2652cb..de14a088 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
@@ -221,8 +221,11 @@ assert(string.find(getoutput(), "error calling 'print'")) | |||
221 | RUN('echo "io.stderr:write(1000)\ncont" | lua -e "require\'debug\'.debug()" 2> %s', out) | 221 | RUN('echo "io.stderr:write(1000)\ncont" | lua -e "require\'debug\'.debug()" 2> %s', out) |
222 | checkout("lua_debug> 1000lua_debug> ") | 222 | checkout("lua_debug> 1000lua_debug> ") |
223 | 223 | ||
224 | -- test warnings | 224 | |
225 | RUN('echo "io.stderr:write(1); warn[[XXX]]" | lua -q 2> %s', out) | 225 | print("testing warnings") |
226 | |||
227 | -- no warnings by default | ||
228 | RUN('echo "io.stderr:write(1); warn[[XXX]]" | lua 2> %s', out) | ||
226 | checkout("1") | 229 | checkout("1") |
227 | 230 | ||
228 | prepfile[[ | 231 | prepfile[[ |
@@ -236,7 +239,7 @@ warn("", "@on") -- again, no control, real warning | |||
236 | warn("@on") -- keep it "started" | 239 | warn("@on") -- keep it "started" |
237 | warn("Z", "Z", "Z") -- common warning | 240 | warn("Z", "Z", "Z") -- common warning |
238 | ]] | 241 | ]] |
239 | RUN('lua %s 2> %s', prog, out) | 242 | RUN('lua -W %s 2> %s', prog, out) |
240 | checkout[[ | 243 | checkout[[ |
241 | Lua warning: @offXXX@off | 244 | Lua warning: @offXXX@off |
242 | Lua warning: @on | 245 | Lua warning: @on |
@@ -250,7 +253,7 @@ warn("@allow") | |||
250 | u1 = setmetatable({}, {__gc = function () error("XYZ") end}) | 253 | u1 = setmetatable({}, {__gc = function () error("XYZ") end}) |
251 | u2 = setmetatable({}, {__gc = function () error("ZYX") end}) | 254 | u2 = setmetatable({}, {__gc = function () error("ZYX") end}) |
252 | ]] | 255 | ]] |
253 | RUN('lua %s 2> %s', prog, out) | 256 | RUN('lua -W %s 2> %s', prog, out) |
254 | checkprogout("ZYX)\nXYZ)\n") | 257 | checkprogout("ZYX)\nXYZ)\n") |
255 | 258 | ||
256 | 259 | ||