diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-15 13:44:36 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-15 13:44:36 -0300 |
| commit | a1d8eb27431c02c4529be1efd92143ad65434f3a (patch) | |
| tree | 58db9340ba2b8ea1cb91004b96f15a955f167c58 /testes | |
| parent | f64a1b175a5fa65434a073e6d071b32bb7b0ab69 (diff) | |
| download | lua-a1d8eb27431c02c4529be1efd92143ad65434f3a.tar.gz lua-a1d8eb27431c02c4529be1efd92143ad65434f3a.tar.bz2 lua-a1d8eb27431c02c4529be1efd92143ad65434f3a.zip | |
Added control messages to warnings
Added the concept of control messages to the warning system, plus the
implementation of the controls "@on"/"@off" to turn warnings on/off.
Moreover, the warning system in the test library adds some other
controls to ease the test of warnings.
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/all.lua | 4 | ||||
| -rw-r--r-- | testes/api.lua | 2 | ||||
| -rw-r--r-- | testes/gc.lua | 8 | ||||
| -rw-r--r-- | testes/main.lua | 29 |
4 files changed, 42 insertions, 1 deletions
diff --git a/testes/all.lua b/testes/all.lua index bf27f106..5d698d4b 100644 --- a/testes/all.lua +++ b/testes/all.lua | |||
| @@ -209,6 +209,10 @@ if #msgs > 0 then | |||
| 209 | warn("#tests not performed:\n ", m, "\n") | 209 | warn("#tests not performed:\n ", m, "\n") |
| 210 | end | 210 | end |
| 211 | 211 | ||
| 212 | warn("@off") | ||
| 213 | warn("******** THIS WARNING SHOULD NOT APPEAR **********") | ||
| 214 | warn("******** THIS WARNING ALSO SHOULD NOT APPEAR **********") | ||
| 215 | warn("@on") | ||
| 212 | print("(there should be two warnings now)") | 216 | print("(there should be two warnings now)") |
| 213 | warn("#This is ", "an expected", " warning") | 217 | warn("#This is ", "an expected", " warning") |
| 214 | warn("#This is", " another one") | 218 | warn("#This is", " another one") |
diff --git a/testes/api.lua b/testes/api.lua index f6915c3e..4f9d6717 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
| @@ -977,6 +977,7 @@ assert(t[7] == nil) | |||
| 977 | 977 | ||
| 978 | ------------------------------------------------------------------------- | 978 | ------------------------------------------------------------------------- |
| 979 | do -- testing errors during GC | 979 | do -- testing errors during GC |
| 980 | warn("@off") | ||
| 980 | collectgarbage("stop") | 981 | collectgarbage("stop") |
| 981 | local a = {} | 982 | local a = {} |
| 982 | for i=1,20 do | 983 | for i=1,20 do |
| @@ -994,6 +995,7 @@ do -- testing errors during GC | |||
| 994 | collectgarbage() | 995 | collectgarbage() |
| 995 | assert(A == 10) -- number of normal collections | 996 | assert(A == 10) -- number of normal collections |
| 996 | collectgarbage("restart") | 997 | collectgarbage("restart") |
| 998 | warn("@on") | ||
| 997 | end | 999 | end |
| 998 | ------------------------------------------------------------------------- | 1000 | ------------------------------------------------------------------------- |
| 999 | -- test for userdata vals | 1001 | -- test for userdata vals |
diff --git a/testes/gc.lua b/testes/gc.lua index 9ea054c1..6bdc98ca 100644 --- a/testes/gc.lua +++ b/testes/gc.lua | |||
| @@ -369,6 +369,7 @@ if T then | |||
| 369 | s[n] = i | 369 | s[n] = i |
| 370 | end | 370 | end |
| 371 | 371 | ||
| 372 | warn("@store") | ||
| 372 | collectgarbage() | 373 | collectgarbage() |
| 373 | assert(string.find(_WARN, "error in __gc metamethod")) | 374 | assert(string.find(_WARN, "error in __gc metamethod")) |
| 374 | assert(string.match(_WARN, "@(.-)@") == "expected") | 375 | assert(string.match(_WARN, "@(.-)@") == "expected") |
| @@ -383,6 +384,7 @@ if T then | |||
| 383 | for i = 1, 10 do assert(s[i]) end | 384 | for i = 1, 10 do assert(s[i]) end |
| 384 | 385 | ||
| 385 | getmetatable(u).__gc = nil | 386 | getmetatable(u).__gc = nil |
| 387 | warn("@normal") | ||
| 386 | 388 | ||
| 387 | end | 389 | end |
| 388 | print '+' | 390 | print '+' |
| @@ -475,9 +477,11 @@ end | |||
| 475 | 477 | ||
| 476 | -- errors during collection | 478 | -- errors during collection |
| 477 | if T then | 479 | if T then |
| 480 | warn("@store") | ||
| 478 | u = setmetatable({}, {__gc = function () error "@expected error" end}) | 481 | u = setmetatable({}, {__gc = function () error "@expected error" end}) |
| 479 | u = nil | 482 | u = nil |
| 480 | collectgarbage() | 483 | collectgarbage() |
| 484 | warn("@normal") | ||
| 481 | end | 485 | end |
| 482 | 486 | ||
| 483 | 487 | ||
| @@ -645,7 +649,7 @@ end | |||
| 645 | 649 | ||
| 646 | -- create several objects to raise errors when collected while closing state | 650 | -- create several objects to raise errors when collected while closing state |
| 647 | if T then | 651 | if T then |
| 648 | local error, assert, find = error, assert, string.find | 652 | local error, assert, find, warn = error, assert, string.find, warn |
| 649 | local n = 0 | 653 | local n = 0 |
| 650 | local lastmsg | 654 | local lastmsg |
| 651 | local mt = {__gc = function (o) | 655 | local mt = {__gc = function (o) |
| @@ -659,7 +663,9 @@ if T then | |||
| 659 | else | 663 | else |
| 660 | assert(lastmsg == _WARN) -- subsequent error messages are equal | 664 | assert(lastmsg == _WARN) -- subsequent error messages are equal |
| 661 | end | 665 | end |
| 666 | warn("@store") | ||
| 662 | error"@expected warning" | 667 | error"@expected warning" |
| 668 | warn("@normal") | ||
| 663 | end} | 669 | end} |
| 664 | for i = 10, 1, -1 do | 670 | for i = 10, 1, -1 do |
| 665 | -- create object and preserve it until the end | 671 | -- create object and preserve it until the end |
diff --git a/testes/main.lua b/testes/main.lua index b224b54e..0ef4822d 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
| @@ -221,6 +221,28 @@ 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 | ||
| 225 | RUN('echo "io.stderr:write(1); warn[[XXX]]" | lua -q 2> %s', out) | ||
| 226 | checkout("1") | ||
| 227 | |||
| 228 | prepfile[[ | ||
| 229 | warn("@allow") -- unknown control, ignored | ||
| 230 | warn("@off", "XXX", "@off") -- these are not control messages | ||
| 231 | warn("@off") -- this one is | ||
| 232 | warn("@on", "YYY", "@on") -- not control, but warn is off | ||
| 233 | warn("@off") -- keep it off | ||
| 234 | warn("@on") -- restart warnings | ||
| 235 | warn("", "@on") -- again, no control, real warning | ||
| 236 | warn("@on") -- keep it "started" | ||
| 237 | warn("Z", "Z", "Z") -- common warning | ||
| 238 | ]] | ||
| 239 | RUN('lua %s 2> %s', prog, out) | ||
| 240 | checkout[[ | ||
| 241 | Lua warning: @offXXX@off | ||
| 242 | Lua warning: @on | ||
| 243 | Lua warning: ZZZ | ||
| 244 | ]] | ||
| 245 | |||
| 224 | -- test many arguments | 246 | -- test many arguments |
| 225 | prepfile[[print(({...})[30])]] | 247 | prepfile[[print(({...})[30])]] |
| 226 | RUN('lua %s %s > %s', prog, string.rep(" a", 30), out) | 248 | RUN('lua %s %s > %s', prog, string.rep(" a", 30), out) |
| @@ -355,8 +377,15 @@ if T then -- test library? | |||
| 355 | NoRun("not enough memory", "env MEMLIMIT=100 lua") | 377 | NoRun("not enough memory", "env MEMLIMIT=100 lua") |
| 356 | 378 | ||
| 357 | -- testing 'warn' | 379 | -- testing 'warn' |
| 380 | warn("@store") | ||
| 358 | warn("@123", "456", "789") | 381 | warn("@123", "456", "789") |
| 359 | assert(_WARN == "@123456789") | 382 | assert(_WARN == "@123456789") |
| 383 | |||
| 384 | warn("zip", "", " ", "zap") | ||
| 385 | assert(_WARN == "zip zap") | ||
| 386 | warn("ZIP", "", " ", "ZAP") | ||
| 387 | assert(_WARN == "ZIP ZAP") | ||
| 388 | warn("@normal") | ||
| 360 | end | 389 | end |
| 361 | 390 | ||
| 362 | do | 391 | do |
