diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-28 15:42:34 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-28 15:42:34 -0200 |
| commit | 437a5b07d415e1a74160ddfd804017171d6cc5cb (patch) | |
| tree | 861f9a56ae175eaed91c163409c33ab85bee7ff9 /testes | |
| parent | ba7da13ec5938f978c37d63aa40a3e340b301f79 (diff) | |
| download | lua-437a5b07d415e1a74160ddfd804017171d6cc5cb.tar.gz lua-437a5b07d415e1a74160ddfd804017171d6cc5cb.tar.bz2 lua-437a5b07d415e1a74160ddfd804017171d6cc5cb.zip | |
Added a warning system to Lua
The warning system is just a way for Lua to emit warnings, messages
to the programmer that do not interfere with the running program.
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/all.lua | 13 | ||||
| -rw-r--r-- | testes/api.lua | 14 |
2 files changed, 22 insertions, 5 deletions
diff --git a/testes/all.lua b/testes/all.lua index 84ba80a6..bde4195e 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 | io.stderr:write("\nThis test suite is for ", version, ", not for ", _VERSION, | 8 | warn(string.format( |
| 9 | "\nExiting tests\n") | 9 | "This test suite is for %s, not for %s\nExiting tests\n", version, _VERSION)) |
| 10 | return | 10 | return |
| 11 | end | 11 | end |
| 12 | 12 | ||
| @@ -190,11 +190,10 @@ assert(dofile('verybig.lua', true) == 10); collectgarbage() | |||
| 190 | dofile('files.lua') | 190 | dofile('files.lua') |
| 191 | 191 | ||
| 192 | if #msgs > 0 then | 192 | if #msgs > 0 then |
| 193 | print("\ntests not performed:") | 193 | warn("*tests not performed:\n ") |
| 194 | for i=1,#msgs do | 194 | for i=1,#msgs do |
| 195 | print(msgs[i]) | 195 | warn(msgs[i]); warn("\n ") |
| 196 | end | 196 | end |
| 197 | print() | ||
| 198 | end | 197 | end |
| 199 | 198 | ||
| 200 | -- no test module should define 'debug' | 199 | -- no test module should define 'debug' |
| @@ -220,6 +219,10 @@ local _G, showmem, print, format, clock, time, difftime, assert, open = | |||
| 220 | local fname = T and "time-debug.txt" or "time.txt" | 219 | local fname = T and "time-debug.txt" or "time.txt" |
| 221 | local lasttime | 220 | local lasttime |
| 222 | 221 | ||
| 222 | |||
| 223 | warn("*This is "); warn("an expected"); warn(" warning\n") | ||
| 224 | warn("*This is"); warn(" another one\n") | ||
| 225 | |||
| 223 | if not usertests then | 226 | if not usertests then |
| 224 | -- open file with time of last performed test | 227 | -- open file with time of last performed test |
| 225 | local f = io.open(fname) | 228 | local f = io.open(fname) |
diff --git a/testes/api.lua b/testes/api.lua index 6f35e132..b4d63866 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
| @@ -111,6 +111,20 @@ do -- testing 'rotate' | |||
| 111 | tcheck(t, {10, 20, 30, 40}) | 111 | tcheck(t, {10, 20, 30, 40}) |
| 112 | end | 112 | end |
| 113 | 113 | ||
| 114 | |||
| 115 | -- testing warnings | ||
| 116 | T.testC([[ | ||
| 117 | warning "*This " | ||
| 118 | warning "warning " | ||
| 119 | warning "should be in a" | ||
| 120 | warning " single line | ||
| 121 | " | ||
| 122 | warning "*This should be " | ||
| 123 | warning "another warning | ||
| 124 | " | ||
| 125 | ]]) | ||
| 126 | |||
| 127 | |||
| 114 | -- testing message handlers | 128 | -- testing message handlers |
| 115 | do | 129 | do |
| 116 | local f = T.makeCfunc[[ | 130 | local f = T.makeCfunc[[ |
