aboutsummaryrefslogtreecommitdiff
path: root/tests/basic.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basic.lua')
-rw-r--r--tests/basic.lua52
1 files changed, 26 insertions, 26 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index ee31ed1..b1e8fd3 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -2,7 +2,7 @@
2-- BASIC.LUA Copyright (c) 2007-08, Asko Kauppi <akauppi@gmail.com> 2-- BASIC.LUA Copyright (c) 2007-08, Asko Kauppi <akauppi@gmail.com>
3-- 3--
4-- Selftests for Lua Lanes 4-- Selftests for Lua Lanes
5-- 5--
6-- To do: 6-- To do:
7-- - ... 7-- - ...
8-- 8--
@@ -20,7 +20,7 @@ local function PRINT(...)
20 for i=1,select('#',...) do 20 for i=1,select('#',...) do
21 str= str..tostring(select(i,...)).."\t" 21 str= str..tostring(select(i,...)).."\t"
22 end 22 end
23 if io then 23 if io then
24 io.stderr:write(str.."\n") 24 io.stderr:write(str.."\n")
25 end 25 end
26end 26end
@@ -55,7 +55,7 @@ tables_match= function( a, b )
55end 55end
56 56
57 57
58---=== Tasking (basic) ===--- 58PRINT( "---=== Tasking (basic) ===---")
59 59
60local function task( a, b, c ) 60local function task( a, b, c )
61 --error "111" -- testing error messages 61 --error "111" -- testing error messages
@@ -98,7 +98,7 @@ assert( lane1.status == "done" )
98assert( lane1.status == "done" ) 98assert( lane1.status == "done" )
99 99
100 100
101---=== Tasking (cancelling) ===--- 101PRINT( "---=== Tasking (cancelling) ===---")
102 102
103local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) 103local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task )
104 104
@@ -136,7 +136,7 @@ PRINT(" "..st)
136assert( st == "cancelled" ) 136assert( st == "cancelled" )
137 137
138 138
139---=== Communications ===--- 139PRINT( "---=== Communications ===---")
140 140
141local function WR(...) io.stderr:write(...) end 141local function WR(...) io.stderr:write(...) end
142 142
@@ -157,7 +157,7 @@ local chunk= function( linda )
157 send { 'a', 'b', 'c', d=10 }; WR( "{'a','b','c',d=10} sent\n" ) 157 send { 'a', 'b', 'c', d=10 }; WR( "{'a','b','c',d=10} sent\n" )
158 158
159 v=receive(); WR( v.." received\n" ); assert( v==4 ) 159 v=receive(); WR( v.." received\n" ); assert( v==4 )
160 160
161 WR( "Lane ends!\n" ) 161 WR( "Lane ends!\n" )
162end 162end
163 163
@@ -195,7 +195,7 @@ assert( PEEK() == nil )
195SEND(4) 195SEND(4)
196 196
197 197
198---=== Stdlib naming ===--- 198PRINT( "---=== Stdlib naming ===---")
199 199
200local function io_os_f() 200local function io_os_f()
201 assert(io) 201 assert(io)
@@ -215,7 +215,7 @@ assert( f2()[1] )
215assert( f3()[1] ) 215assert( f3()[1] )
216 216
217 217
218---=== Comms criss cross ===--- 218PRINT( "---=== Comms criss cross ===---")
219 219
220-- We make two identical lanes, which are using the same Linda channel. 220-- We make two identical lanes, which are using the same Linda channel.
221-- 221--
@@ -241,7 +241,7 @@ local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twis
241local _= a[1],b[1] -- waits until they are both ready 241local _= a[1],b[1] -- waits until they are both ready
242 242
243 243
244---=== Receive & send of code ===--- 244PRINT( "---=== Receive & send of code ===---")
245 245
246local upvalue="123" 246local upvalue="123"
247 247
@@ -251,21 +251,21 @@ local function chunk2( linda )
251 -- function name & line number should be there even as separate thread 251 -- function name & line number should be there even as separate thread
252 -- 252 --
253 local info= debug.getinfo(1) -- 1 = us 253 local info= debug.getinfo(1) -- 1 = us
254 -- 254 --
255 for k,v in pairs(info) do PRINT(k,v) end 255 for k,v in pairs(info) do PRINT(k,v) end
256 256
257 assert( info.nups == 2 ) -- one upvalue + PRINT 257 assert( info.nups == 2 ) -- one upvalue + PRINT
258 assert( info.what == "Lua" ) 258 assert( info.what == "Lua" )
259 259
260 --assert( info.name == "chunk2" ) -- name does not seem to come through 260 --assert( info.name == "chunk2" ) -- name does not seem to come through
261 assert( string.match( info.source, "^@tests[/\\]basic.lua$" ) ) 261 assert( string.match( info.source, "^@basic.lua$" ) )
262 assert( string.match( info.short_src, "^tests[/\\]basic.lua$" ) ) 262 assert( string.match( info.short_src, "^basic.lua$" ) )
263 263
264 -- These vary so let's not be picky (they're there..) 264 -- These vary so let's not be picky (they're there..)
265 -- 265 --
266 assert( info.linedefined > 200 ) -- start of 'chunk2' 266 assert( info.linedefined > 200 ) -- start of 'chunk2'
267 assert( info.currentline > info.linedefined ) -- line of 'debug.getinfo' 267 assert( info.currentline > info.linedefined ) -- line of 'debug.getinfo'
268 assert( info.lastlinedefined > info.currentline ) -- end of 'chunk2' 268 assert( info.lastlinedefined > info.currentline ) -- end of 'chunk2'
269 269
270 local func,k= linda:receive( "down" ) 270 local func,k= linda:receive( "down" )
271 assert( type(func)=="function" ) 271 assert( type(func)=="function" )
@@ -275,7 +275,7 @@ local function chunk2( linda )
275 275
276 local str= linda:receive( "down" ) 276 local str= linda:receive( "down" )
277 assert( str=="ok" ) 277 assert( str=="ok" )
278 278
279 linda:send( "up", function() return ":)" end, "ok2" ) 279 linda:send( "up", function() return ":)" end, "ok2" )
280end 280end
281 281
@@ -304,7 +304,7 @@ local ok2= linda:receive( "up" )
304assert( ok2 == "ok2" ) 304assert( ok2 == "ok2" )
305 305
306 306
307---=== :join test ===--- 307PRINT( "---=== :join test ===---")
308 308
309-- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil 309-- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil
310-- (unless [1..n] has been read earlier, in which case it would seemingly 310-- (unless [1..n] has been read earlier, in which case it would seemingly