summaryrefslogtreecommitdiff
path: root/testes/locals.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-18 17:29:46 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-08-18 17:29:46 -0300
commit9405472565cb4b0cb0c339d65babdef4d4cb7abd (patch)
tree386bcb066803310f7481b60e119748c85b13d618 /testes/locals.lua
parent45948e7e55c753cf0e370b251ac1d4e7f3aabedd (diff)
downloadlua-9405472565cb4b0cb0c339d65babdef4d4cb7abd.tar.gz
lua-9405472565cb4b0cb0c339d65babdef4d4cb7abd.tar.bz2
lua-9405472565cb4b0cb0c339d65babdef4d4cb7abd.zip
Improvement in warn-mode '@store' (for testing)
When using warn-mode '@store', from the test library, the tests ensure not only that the expected warnings were issued, but also that there was no extra warnings.
Diffstat (limited to 'testes/locals.lua')
-rw-r--r--testes/locals.lua35
1 files changed, 21 insertions, 14 deletions
diff --git a/testes/locals.lua b/testes/locals.lua
index 595e107a..b4de523d 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -288,9 +288,8 @@ end
288 288
289-- auxiliary functions for testing warnings in '__close' 289-- auxiliary functions for testing warnings in '__close'
290local function prepwarn () 290local function prepwarn ()
291 warn("@off") -- do not show (lots of) warnings 291 if not T then -- no test library?
292 if not T then 292 warn("@off") -- do not show (lots of) warnings
293 _WARN = "OFF" -- signal that warnings are not being captured
294 else 293 else
295 warn("@store") -- to test the warnings 294 warn("@store") -- to test the warnings
296 end 295 end
@@ -298,15 +297,20 @@ end
298 297
299 298
300local function endwarn () 299local function endwarn ()
301 assert(T or _WARN == "OFF") 300 if not T then
302 warn("@on") -- back to normal 301 warn("@on") -- back to normal
303 warn("@normal") 302 else
304 _WARN = nil 303 assert(_WARN == nil)
304 warn("@normal")
305 end
305end 306end
306 307
307 308
308local function checkwarn (msg) 309local function checkwarn (msg)
309 assert(_WARN == "OFF" or string.find(_WARN, msg)) 310 if T then
311 assert(string.find(_WARN, msg))
312 _WARN = nil -- reset variable to check next warning
313 end
310end 314end
311 315
312 316
@@ -333,7 +337,8 @@ do print("testing errors in __close")
333 337
334 local y <close> = 338 local y <close> =
335 func2close(function (self, msg) 339 func2close(function (self, msg)
336 assert(string.find(msg, "@z")) -- error in 'z' 340 assert(string.find(msg, "@z")) -- first error in 'z'
341 checkwarn("@z") -- second error in 'z' generated a warning
337 error("@y") 342 error("@y")
338 end) 343 end)
339 344
@@ -377,14 +382,14 @@ do print("testing errors in __close")
377 382
378 local y <close> = 383 local y <close> =
379 func2close(function (self, msg) 384 func2close(function (self, msg)
380 assert(msg == 4) -- error in body 385 assert(msg == 4) -- error in body
386 checkwarn("@z")
381 error("@y") 387 error("@y")
382 end) 388 end)
383 389
384 local first = true 390 local first = true
385 local z <close> = 391 local z <close> =
386 func2close(function (self, msg) 392 func2close(function (self, msg)
387 checkwarn("@z")
388 -- 'z' close is called once 393 -- 'z' close is called once
389 assert(first and msg == 4) 394 assert(first and msg == 4)
390 first = false 395 first = false
@@ -418,16 +423,18 @@ do print("testing errors in __close")
418 local st, msg = xpcall(foo, debug.traceback) 423 local st, msg = xpcall(foo, debug.traceback)
419 assert(string.match(msg, "^[^ ]* @X")) 424 assert(string.match(msg, "^[^ ]* @X"))
420 assert(string.find(msg, "in metamethod 'close'")) 425 assert(string.find(msg, "in metamethod 'close'"))
426 checkwarn("@Y")
421 427
422 -- error in toclose in vararg function 428 -- error in toclose in vararg function
423 local function foo (...) 429 local function foo (...)
424 local x123 <close> = func2close(function () error("@X") end) 430 local x123 <close> = func2close(function () error("@x123") end)
425 end 431 end
426 432
427 local st, msg = xpcall(foo, debug.traceback) 433 local st, msg = xpcall(foo, debug.traceback)
428 assert(string.match(msg, "^[^ ]* @X")) 434 assert(string.match(msg, "^[^ ]* @x123"))
429
430 assert(string.find(msg, "in metamethod 'close'")) 435 assert(string.find(msg, "in metamethod 'close'"))
436 checkwarn("@x123") -- from second call to close 'x123'
437
431 endwarn() 438 endwarn()
432end 439end
433 440