aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2013-01-26 20:21:39 +0100
committerBenoit Germain <bnt.germain@gmail.com>2013-01-26 20:21:39 +0100
commitfb0c67b1c95b6a595c0cd34a66136af6193b4d1b (patch)
treebadb5e95c0b7d9acb6be371c9163801b816b8731 /tests
parent68d8db431ec2b739dc53233d6b4d8aeee9324e48 (diff)
downloadlanes-3.4.4.tar.gz
lanes-3.4.4.tar.bz2
lanes-3.4.4.zip
version 3.4.4v3.4.4
* bugfix: take into account the fact that "coroutine" is no longer part of base library in Lua 5.2 * bugfix: if "bit32" was listed in the libraries, it wouldn't open (library list parsing failing on digits) * bugfix: Use luaL_requiref() to open standard libraries in Lua 5.2 as we should * bugfix: any Lua state created by Lanes reuses the allocator function of the originating state * bugfix: don't call on_state_create() while GC is suspended during lua state initialization
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.lua89
1 files changed, 71 insertions, 18 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index c35f16a..1f4eb1e 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -54,8 +54,11 @@ tables_match= function( a, b )
54 return subtable( a, b ) and subtable( b, a ) 54 return subtable( a, b ) and subtable( b, a )
55end 55end
56 56
57--##############################################################
58--##############################################################
59--##############################################################
57 60
58PRINT( "---=== Tasking (basic) ===---") 61PRINT( "\n\n", "---=== Tasking (basic) ===---", "\n\n")
59 62
60local function task( a, b, c ) 63local function task( a, b, c )
61 set_debug_threadname( "task("..a..","..b..","..c..")") 64 set_debug_threadname( "task("..a..","..b..","..c..")")
@@ -98,8 +101,11 @@ assert( v2_hey == true )
98assert( lane1.status == "done" ) 101assert( lane1.status == "done" )
99assert( lane1.status == "done" ) 102assert( lane1.status == "done" )
100 103
104--##############################################################
105--##############################################################
106--##############################################################
101 107
102PRINT( "---=== Tasking (cancelling) ===---") 108PRINT( "\n\n", "---=== Tasking (cancelling) ===---", "\n\n")
103 109
104local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) 110local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task )
105 111
@@ -181,7 +187,11 @@ repeat until wait_receive_batched_lane.status == "cancelled"
181print "wait_receive_batched_lane is cancelled" 187print "wait_receive_batched_lane is cancelled"
182--################################################]] 188--################################################]]
183 189
184PRINT( "---=== Communications ===---") 190--##############################################################
191--##############################################################
192--##############################################################
193
194PRINT( "\n\n", "---=== Communications ===---", "\n\n")
185 195
186local function WR(...) io.stderr:write(...) end 196local function WR(...) io.stderr:write(...) end
187 197
@@ -246,28 +256,64 @@ assert( tables_match( a, {'a','b','c',d=10} ) )
246assert( PEEK() == nil ) 256assert( PEEK() == nil )
247SEND(4) 257SEND(4)
248 258
259-- wait
260linda: receive( 1, "wait")
261
262--##############################################################
263--##############################################################
264--##############################################################
249 265
250PRINT( "---=== Stdlib naming ===---") 266PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n")
251 267
252local function io_os_f() 268local function dump_g( _x)
253 assert(io) 269 assert(print)
254 assert(os) 270 print( "### dumping _G for '" .. _x .. "'")
255 assert(print) 271 for k, v in pairs( _G) do
256 return true 272 print( "\t" .. k .. ": " .. type( v))
273 end
274 return true
257end 275end
258 276
259local f1= lanes_gen( "io,os", io_os_f ) -- any delimiter will do 277local function io_os_f( _x)
260local f2= lanes_gen( "io+os", io_os_f ) 278 assert(print)
261local f3= lanes_gen( "io,os,base", io_os_f ) 279 print( "### checking io and os libs existence for '" .. _x .. "'")
280 assert(io)
281 assert(os)
282 return true
283end
284
285local function coro_f( _x)
286 assert(print)
287 print( "### checking coroutine lib existence for '" .. _x .. "'")
288 assert(coroutine)
289 return true
290end
262 291
263assert.fails( function() lanes_gen( "xxx", io_os_f ) end ) 292assert.fails( function() lanes_gen( "xxx", io_os_f ) end )
264 293
265assert( f1()[1] ) 294local stdlib_naming_tests =
266assert( f2()[1] ) 295{
267assert( f3()[1] ) 296 -- { "", dump_g},
297 -- { "coroutine", dump_g},
298 -- { "io", dump_g},
299 -- { "bit32", dump_g},
300 { "coroutine", coro_f},
301 { "*", io_os_f},
302 { "io,os", io_os_f},
303 { "io+os", io_os_f},
304 { "io,os,base", io_os_f},
305}
306
307for _, t in ipairs( stdlib_naming_tests) do
308 local f= lanes_gen( t[1], t[2]) -- any delimiter will do
309 assert( f(t[1])[1] )
310end
268 311
312--##############################################################
313--##############################################################
314--##############################################################
269 315
270PRINT( "---=== Comms criss cross ===---") 316PRINT( "\n\n", "---=== Comms criss cross ===---", "\n\n")
271 317
272-- We make two identical lanes, which are using the same Linda channel. 318-- We make two identical lanes, which are using the same Linda channel.
273-- 319--
@@ -293,7 +339,11 @@ local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twis
293local _= a[1],b[1] -- waits until they are both ready 339local _= a[1],b[1] -- waits until they are both ready
294 340
295 341
296PRINT( "---=== Receive & send of code ===---") 342--##############################################################
343--##############################################################
344--##############################################################
345
346PRINT( "\n\n", "---=== Receive & send of code ===---", "\n\n")
297 347
298local upvalue="123" 348local upvalue="123"
299 349
@@ -351,8 +401,11 @@ assert( s2==":)" )
351local k,ok2= linda:receive( "up" ) 401local k,ok2= linda:receive( "up" )
352assert( ok2 == "ok2" ) 402assert( ok2 == "ok2" )
353 403
404--##############################################################
405--##############################################################
406--##############################################################
354 407
355PRINT( "---=== :join test ===---") 408PRINT( "\n\n", "---=== :join test ===---", "\n\n")
356 409
357-- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil 410-- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil
358-- (unless [1..n] has been read earlier, in which case it would seemingly 411-- (unless [1..n] has been read earlier, in which case it would seemingly