diff options
| author | Benoit Germain <bnt.germain@gmail.com> | 2013-01-24 22:46:21 +0100 |
|---|---|---|
| committer | Benoit Germain <bnt.germain@gmail.com> | 2013-01-24 22:46:21 +0100 |
| commit | 68d8db431ec2b739dc53233d6b4d8aeee9324e48 (patch) | |
| tree | d8f0fbe0f8c4e1a07ac4248fd1b7673f49beb4d3 /tests/basic.lua | |
| parent | 623fb3c0cae9beb3d5e7d3f7424b47d80041c1ac (diff) | |
| download | lanes-68d8db431ec2b739dc53233d6b4d8aeee9324e48.tar.gz lanes-68d8db431ec2b739dc53233d6b4d8aeee9324e48.tar.bz2 lanes-68d8db431ec2b739dc53233d6b4d8aeee9324e48.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 'tests/basic.lua')
| -rw-r--r-- | tests/basic.lua | 38 |
1 files changed, 26 insertions, 12 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 | ||
| 10 | local lanes = require "lanes" | 10 | local lanes = require "lanes".configure{ with_timers = false} |
| 11 | lanes.configure() | ||
| 12 | require "assert" -- assert.fails() | 11 | require "assert" -- assert.fails() |
| 13 | 12 | ||
| 14 | local lanes_gen= assert( lanes.gen ) | 13 | local 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 |
| 50 | end | 49 | end |
| 51 | 50 | ||
| 52 | -- true when contents of 'a' and 'b' are identific | 51 | -- true when contents of 'a' and 'b' are identical |
| 53 | -- | 52 | -- |
| 54 | tables_match= function( a, b ) | 53 | tables_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 | ||
| 216 | local function PEEK() return linda:get("<-") end | 215 | local function PEEK() return linda:get("<-") end |
| 217 | local function SEND(...) linda:send( "->", ... ) end | 216 | local function SEND(...) linda:send( "->", ... ) end |
| 218 | local function RECEIVE() local k,v = linda:receive( "<-" ) return v end | 217 | local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end |
| 219 | 218 | ||
| 220 | local t= lanes_gen("io",chunk)(linda) -- prepare & launch | 219 | local t= lanes_gen("io",chunk)(linda) -- prepare & launch |
| 221 | 220 | ||
| @@ -228,7 +227,14 @@ end | |||
| 228 | SEND(3); WR( "3 sent\n" ) | 227 | SEND(3); WR( "3 sent\n" ) |
| 229 | 228 | ||
| 230 | local a,b,c= RECEIVE(), RECEIVE(), RECEIVE() | 229 | local a,b,c= RECEIVE(), RECEIVE(), RECEIVE() |
| 231 | WR( a..", "..b..", "..c.." received\n" ) | 230 | |
| 231 | print( "lane status: " .. t.status) | ||
| 232 | if t.status == "error" then | ||
| 233 | print( t:join()) | ||
| 234 | else | ||
| 235 | WR( a..", "..b..", "..c.." received\n" ) | ||
| 236 | end | ||
| 237 | |||
| 232 | assert( a==1 and b==2 and c==3 ) | 238 | assert( a==1 and b==2 and c==3 ) |
| 233 | 239 | ||
| 234 | local a= RECEIVE(); WR( a.." received\n" ) | 240 | local 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 | -- |
| 330 | local k,s= linda:receive( "up" ) | 336 | local k,s= linda:receive( 1, "up" ) |
| 337 | if t2.status == "error" then | ||
| 338 | print( "t2 error: " , t2:join()) | ||
| 339 | end | ||
| 331 | PRINT(s) | 340 | PRINT(s) |
| 332 | assert( s=="ready!" ) | 341 | assert( 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) | ||
| 359 | end ) | 369 | end ) |
| 360 | 370 | ||
| 361 | h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values | 371 | h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values |
| 362 | 372 | ||
| 363 | local a,b,c,d= h:join() | 373 | local a,b,c,d= h:join() |
| 364 | assert(a==14) | 374 | if h.status == "error" then |
| 365 | assert(b==13) | 375 | print( "h error: " , a, b, c, d) |
| 366 | assert(c==12) | 376 | else |
| 367 | assert(d==nil) | 377 | assert(a==14) |
| 378 | assert(b==13) | ||
| 379 | assert(c==12) | ||
| 380 | assert(d==nil) | ||
| 381 | end | ||
| 368 | 382 | ||
| 369 | -- | 383 | -- |
| 370 | io.stderr:write "Done! :)\n" | 384 | io.stderr:write "Done! :)\n" |
