diff options
Diffstat (limited to 'tests/basic.lua')
-rw-r--r-- | tests/basic.lua | 89 |
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 ) |
55 | end | 55 | end |
56 | 56 | ||
57 | --############################################################## | ||
58 | --############################################################## | ||
59 | --############################################################## | ||
57 | 60 | ||
58 | PRINT( "---=== Tasking (basic) ===---") | 61 | PRINT( "\n\n", "---=== Tasking (basic) ===---", "\n\n") |
59 | 62 | ||
60 | local function task( a, b, c ) | 63 | local 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 ) | |||
98 | assert( lane1.status == "done" ) | 101 | assert( lane1.status == "done" ) |
99 | assert( lane1.status == "done" ) | 102 | assert( lane1.status == "done" ) |
100 | 103 | ||
104 | --############################################################## | ||
105 | --############################################################## | ||
106 | --############################################################## | ||
101 | 107 | ||
102 | PRINT( "---=== Tasking (cancelling) ===---") | 108 | PRINT( "\n\n", "---=== Tasking (cancelling) ===---", "\n\n") |
103 | 109 | ||
104 | local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) | 110 | local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) |
105 | 111 | ||
@@ -181,7 +187,11 @@ repeat until wait_receive_batched_lane.status == "cancelled" | |||
181 | print "wait_receive_batched_lane is cancelled" | 187 | print "wait_receive_batched_lane is cancelled" |
182 | --################################################]] | 188 | --################################################]] |
183 | 189 | ||
184 | PRINT( "---=== Communications ===---") | 190 | --############################################################## |
191 | --############################################################## | ||
192 | --############################################################## | ||
193 | |||
194 | PRINT( "\n\n", "---=== Communications ===---", "\n\n") | ||
185 | 195 | ||
186 | local function WR(...) io.stderr:write(...) end | 196 | local function WR(...) io.stderr:write(...) end |
187 | 197 | ||
@@ -246,28 +256,64 @@ assert( tables_match( a, {'a','b','c',d=10} ) ) | |||
246 | assert( PEEK() == nil ) | 256 | assert( PEEK() == nil ) |
247 | SEND(4) | 257 | SEND(4) |
248 | 258 | ||
259 | -- wait | ||
260 | linda: receive( 1, "wait") | ||
261 | |||
262 | --############################################################## | ||
263 | --############################################################## | ||
264 | --############################################################## | ||
249 | 265 | ||
250 | PRINT( "---=== Stdlib naming ===---") | 266 | PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n") |
251 | 267 | ||
252 | local function io_os_f() | 268 | local 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 | ||
257 | end | 275 | end |
258 | 276 | ||
259 | local f1= lanes_gen( "io,os", io_os_f ) -- any delimiter will do | 277 | local function io_os_f( _x) |
260 | local f2= lanes_gen( "io+os", io_os_f ) | 278 | assert(print) |
261 | local 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 | ||
283 | end | ||
284 | |||
285 | local function coro_f( _x) | ||
286 | assert(print) | ||
287 | print( "### checking coroutine lib existence for '" .. _x .. "'") | ||
288 | assert(coroutine) | ||
289 | return true | ||
290 | end | ||
262 | 291 | ||
263 | assert.fails( function() lanes_gen( "xxx", io_os_f ) end ) | 292 | assert.fails( function() lanes_gen( "xxx", io_os_f ) end ) |
264 | 293 | ||
265 | assert( f1()[1] ) | 294 | local stdlib_naming_tests = |
266 | assert( f2()[1] ) | 295 | { |
267 | assert( 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 | |||
307 | for _, 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] ) | ||
310 | end | ||
268 | 311 | ||
312 | --############################################################## | ||
313 | --############################################################## | ||
314 | --############################################################## | ||
269 | 315 | ||
270 | PRINT( "---=== Comms criss cross ===---") | 316 | PRINT( "\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 | |||
293 | local _= a[1],b[1] -- waits until they are both ready | 339 | local _= a[1],b[1] -- waits until they are both ready |
294 | 340 | ||
295 | 341 | ||
296 | PRINT( "---=== Receive & send of code ===---") | 342 | --############################################################## |
343 | --############################################################## | ||
344 | --############################################################## | ||
345 | |||
346 | PRINT( "\n\n", "---=== Receive & send of code ===---", "\n\n") | ||
297 | 347 | ||
298 | local upvalue="123" | 348 | local upvalue="123" |
299 | 349 | ||
@@ -351,8 +401,11 @@ assert( s2==":)" ) | |||
351 | local k,ok2= linda:receive( "up" ) | 401 | local k,ok2= linda:receive( "up" ) |
352 | assert( ok2 == "ok2" ) | 402 | assert( ok2 == "ok2" ) |
353 | 403 | ||
404 | --############################################################## | ||
405 | --############################################################## | ||
406 | --############################################################## | ||
354 | 407 | ||
355 | PRINT( "---=== :join test ===---") | 408 | PRINT( "\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 |