aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
Diffstat (limited to 'testes')
-rw-r--r--testes/coroutine.lua45
-rw-r--r--testes/main.lua24
2 files changed, 64 insertions, 5 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua
index 7d42eadd..5674a4dd 100644
--- a/testes/coroutine.lua
+++ b/testes/coroutine.lua
@@ -119,6 +119,51 @@ end
119assert(#a == 25 and a[#a] == 97) 119assert(#a == 25 and a[#a] == 97)
120x, a = nil 120x, a = nil
121 121
122
123-- coroutine kill
124do
125 -- ok to kill a dead coroutine
126 local co = coroutine.create(print)
127 assert(coroutine.resume(co, "testing 'coroutine.kill'"))
128 assert(coroutine.status(co) == "dead")
129 assert(coroutine.kill(co))
130
131 -- cannot kill the running coroutine
132 local st, msg = pcall(coroutine.kill, coroutine.running())
133 assert(not st and string.find(msg, "running"))
134
135 local main = coroutine.running()
136
137 -- cannot kill a "normal" coroutine
138 ;(coroutine.wrap(function ()
139 local st, msg = pcall(coroutine.kill, main)
140 assert(not st and string.find(msg, "normal"))
141 end))()
142
143 -- to-be-closed variables in coroutines
144 local X
145 co = coroutine.create(function ()
146 local *toclose x = function (err) assert(err == nil); X = false end
147 X = true
148 coroutine.yield()
149 end)
150 coroutine.resume(co)
151 assert(X)
152 assert(coroutine.kill(co))
153 assert(not X and coroutine.status(co) == "dead")
154
155 -- error killing a coroutine
156 co = coroutine.create(function()
157 local *toclose x = function (err) assert(err == nil); error(111) end
158 coroutine.yield()
159 end)
160 coroutine.resume(co)
161 local st, msg = coroutine.kill(co)
162 assert(not st and coroutine.status(co) == "dead" and msg == 111)
163
164end
165
166
122-- yielding across C boundaries 167-- yielding across C boundaries
123 168
124co = coroutine.wrap(function() 169co = coroutine.wrap(function()
diff --git a/testes/main.lua b/testes/main.lua
index c7bde0d9..b9dcab1c 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -254,15 +254,15 @@ NoRun("error object is a table value", [[lua %s]], prog)
254 254
255 255
256-- chunk broken in many lines 256-- chunk broken in many lines
257s = [=[ -- 257s = [=[ --
258function f ( x ) 258function f ( x )
259 local a = [[ 259 local a = [[
260xuxu 260xuxu
261]] 261]]
262 local b = "\ 262 local b = "\
263xuxu\n" 263xuxu\n"
264 if x == 11 then return 1 + 12 , 2 + 20 end --[[ test multiple returns ]] 264 if x == 11 then return 1 + 12 , 2 + 20 end --[[ test multiple returns ]]
265 return x + 1 265 return x + 1
266 --\\ 266 --\\
267end 267end
268return( f( 100 ) ) 268return( f( 100 ) )
@@ -272,10 +272,10 @@ s = string.gsub(s, ' ', '\n\n') -- change all spaces for newlines
272prepfile(s) 272prepfile(s)
273RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) 273RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out)
274checkprogout("101\n13\t22\n\n") 274checkprogout("101\n13\t22\n\n")
275 275
276prepfile[[#comment in 1st line without \n at the end]] 276prepfile[[#comment in 1st line without \n at the end]]
277RUN('lua %s', prog) 277RUN('lua %s', prog)
278 278
279prepfile[[#test line number when file starts with comment line 279prepfile[[#test line number when file starts with comment line
280debug = require"debug" 280debug = require"debug"
281print(debug.getinfo(1).currentline) 281print(debug.getinfo(1).currentline)
@@ -306,6 +306,20 @@ NoRun("", "lua %s", prog) -- no message
306prepfile("os.exit(false, true)") 306prepfile("os.exit(false, true)")
307NoRun("", "lua %s", prog) -- no message 307NoRun("", "lua %s", prog) -- no message
308 308
309
310-- to-be-closed variables in main chunk
311prepfile[[
312 local *toclose x = function (err)
313 assert(err == 120)
314 print("Ok")
315 end
316 local *toclose e1 = function () error(120) end
317 os.exit(true, true)
318]]
319RUN('lua %s > %s', prog, out)
320checkprogout("Ok")
321
322
309-- remove temporary files 323-- remove temporary files
310assert(os.remove(prog)) 324assert(os.remove(prog))
311assert(os.remove(otherprog)) 325assert(os.remove(otherprog))