summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2013-01-24 22:46:21 +0100
committerBenoit Germain <bnt.germain@gmail.com>2013-01-24 22:46:21 +0100
commit68d8db431ec2b739dc53233d6b4d8aeee9324e48 (patch)
treed8f0fbe0f8c4e1a07ac4248fd1b7673f49beb4d3 /tests
parent623fb3c0cae9beb3d5e7d3f7424b47d80041c1ac (diff)
downloadlanes-3.4.3.tar.gz
lanes-3.4.3.tar.bz2
lanes-3.4.3.zip
version 3.4.3v3.4.3
* raise an error if lane generator libs specification contains a lib more than once * bit32 is a valid lib name in the libs specification (silently ignored by the Lua 5.1 build) * improved lanes.nameof to search inside table- and userdata- metatables for an object's name * fixed an unwarranted error when trying to discover a function name upon a failed transfer * contents of package.[path,cpath,preload,loaders|searchers] are pulled *only once* inside keeper states at initialisation * Lua function upvalues equal to the global environment aren't copied by value, but bound to the destination's global environment especially useful for Lua 5.2 _ENV * fixed loading of base libraries that didn't create the global tables when built for Lua 5.2
Diffstat (limited to '')
-rw-r--r--tests/basic.lua38
-rw-r--r--tests/keeper.lua3
-rw-r--r--tests/linda_perf.lua5
3 files changed, 31 insertions, 15 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index e913906..c35f16a 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -7,8 +7,7 @@
7-- - ... 7-- - ...
8-- 8--
9 9
10local lanes = require "lanes" 10local lanes = require "lanes".configure{ with_timers = false}
11lanes.configure()
12require "assert" -- assert.fails() 11require "assert" -- assert.fails()
13 12
14local lanes_gen= assert( lanes.gen ) 13local lanes_gen= assert( lanes.gen )
@@ -49,7 +48,7 @@ local function subtable( a, b )
49 return true -- is a subtable 48 return true -- is a subtable
50end 49end
51 50
52-- true when contents of 'a' and 'b' are identific 51-- true when contents of 'a' and 'b' are identical
53-- 52--
54tables_match= function( a, b ) 53tables_match= function( a, b )
55 return subtable( a, b ) and subtable( b, a ) 54 return subtable( a, b ) and subtable( b, a )
@@ -215,7 +214,7 @@ assert( type(linda) == "userdata" )
215 214
216local function PEEK() return linda:get("<-") end 215local function PEEK() return linda:get("<-") end
217local function SEND(...) linda:send( "->", ... ) end 216local function SEND(...) linda:send( "->", ... ) end
218local function RECEIVE() local k,v = linda:receive( "<-" ) return v end 217local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end
219 218
220local t= lanes_gen("io",chunk)(linda) -- prepare & launch 219local t= lanes_gen("io",chunk)(linda) -- prepare & launch
221 220
@@ -228,7 +227,14 @@ end
228SEND(3); WR( "3 sent\n" ) 227SEND(3); WR( "3 sent\n" )
229 228
230local a,b,c= RECEIVE(), RECEIVE(), RECEIVE() 229local a,b,c= RECEIVE(), RECEIVE(), RECEIVE()
231 WR( a..", "..b..", "..c.." received\n" ) 230
231print( "lane status: " .. t.status)
232if t.status == "error" then
233 print( t:join())
234else
235 WR( a..", "..b..", "..c.." received\n" )
236end
237
232assert( a==1 and b==2 and c==3 ) 238assert( a==1 and b==2 and c==3 )
233 239
234local a= RECEIVE(); WR( a.." received\n" ) 240local a= RECEIVE(); WR( a.." received\n" )
@@ -299,7 +305,7 @@ local function chunk2( linda )
299 -- 305 --
300 for k,v in pairs(info) do PRINT(k,v) end 306 for k,v in pairs(info) do PRINT(k,v) end
301 307
302 assert( info.nups == 2 ) -- one upvalue + PRINT 308 assert( info.nups == (_VERSION == "Lua 5.1" and 2 or 3) ) -- one upvalue + PRINT + _ENV (Lua 5.2 only)
303 assert( info.what == "Lua" ) 309 assert( info.what == "Lua" )
304 --assert( info.name == "chunk2" ) -- name does not seem to come through 310 --assert( info.name == "chunk2" ) -- name does not seem to come through
305 assert( string.match( info.source, "^@.*basic.lua$" ) ) 311 assert( string.match( info.source, "^@.*basic.lua$" ) )
@@ -327,7 +333,10 @@ linda:send( "down", function(linda) linda:send( "up", "ready!" ) end,
327 "ok" ) 333 "ok" )
328-- wait to see if the tiny function gets executed 334-- wait to see if the tiny function gets executed
329-- 335--
330local k,s= linda:receive( "up" ) 336local k,s= linda:receive( 1, "up" )
337if t2.status == "error" then
338 print( "t2 error: " , t2:join())
339end
331PRINT(s) 340PRINT(s)
332assert( s=="ready!" ) 341assert( s=="ready!" )
333 342
@@ -355,16 +364,21 @@ local S= lanes_gen( "table",
355 for i, v in ipairs(arg) do 364 for i, v in ipairs(arg) do
356 table.insert (aux, 1, v) 365 table.insert (aux, 1, v)
357 end 366 end
358 return unpack(aux) 367 -- unpack was renamed table.unpack in Lua 5.2: cater for both!
368 return (unpack or table.unpack)(aux)
359end ) 369end )
360 370
361h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values 371h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values
362 372
363local a,b,c,d= h:join() 373local a,b,c,d= h:join()
364assert(a==14) 374if h.status == "error" then
365assert(b==13) 375 print( "h error: " , a, b, c, d)
366assert(c==12) 376else
367assert(d==nil) 377 assert(a==14)
378 assert(b==13)
379 assert(c==12)
380 assert(d==nil)
381end
368 382
369-- 383--
370io.stderr:write "Done! :)\n" 384io.stderr:write "Done! :)\n"
diff --git a/tests/keeper.lua b/tests/keeper.lua
index 40c9e11..73ed3cf 100644
--- a/tests/keeper.lua
+++ b/tests/keeper.lua
@@ -4,8 +4,7 @@
4-- Test program for Lua Lanes 4-- Test program for Lua Lanes
5-- 5--
6 6
7local lanes = require "lanes" 7local lanes = require "lanes".configure{ with_timers = false}
8lanes.configure()
9 8
10local function keeper(linda) 9local function keeper(linda)
11 local mt= { 10 local mt= {
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
index 87e0da7..be582ce 100644
--- a/tests/linda_perf.lua
+++ b/tests/linda_perf.lua
@@ -1,6 +1,9 @@
1local lanes = require "lanes" 1local lanes = require "lanes"
2lanes.configure() 2lanes.configure()
3 3
4-- Lua 5.1/5.2 compatibility
5local table_unpack = unpack or table.unpack
6
4-- this lane eats items in the linda one by one 7-- this lane eats items in the linda one by one
5local eater = function( l, loop) 8local eater = function( l, loop)
6 local key, val = l:receive( "go") 9 local key, val = l:receive( "go")
@@ -131,7 +134,7 @@ local function ziva2( preloop, loop, batch)
131 end 134 end
132 -- create a function that can send several values in one shot 135 -- create a function that can send several values in one shot
133 batch_send = function() 136 batch_send = function()
134 l:send( "key", unpack( batch_values)) 137 l:send( "key", table_unpack( batch_values))
135 end 138 end
136 batch_read = function() 139 batch_read = function()
137 l:receive( l.batched, "key", batch) 140 l:receive( l.batched, "key", batch)