diff options
Diffstat (limited to '')
-rw-r--r-- | unit_tests/scripts/lane/stdlib_naming.lua | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/unit_tests/scripts/lane/stdlib_naming.lua b/unit_tests/scripts/lane/stdlib_naming.lua new file mode 100644 index 0000000..2e045c3 --- /dev/null +++ b/unit_tests/scripts/lane/stdlib_naming.lua | |||
@@ -0,0 +1,87 @@ | |||
1 | local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure(config).configure() | ||
2 | print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) | ||
3 | local lanes = require_lanes_result_1 | ||
4 | |||
5 | local require_assert_result_1, require_assert_result_2 = require "_assert" | ||
6 | print("require_assert_result:", require_assert_result_1, require_assert_result_2) | ||
7 | |||
8 | local utils = lanes.require "_utils" | ||
9 | local PRINT = utils.MAKE_PRINT() | ||
10 | |||
11 | local lanes_gen = assert(lanes.gen) | ||
12 | local lanes_linda = assert(lanes.linda) | ||
13 | |||
14 | -- ################################################################################################## | ||
15 | -- ################################################################################################## | ||
16 | -- ################################################################################################## | ||
17 | |||
18 | local function task(a, b, c) | ||
19 | lane_threadname("task("..a..","..b..","..c..")") | ||
20 | --error "111" -- testing error messages | ||
21 | assert(hey) | ||
22 | local v=0 | ||
23 | for i=a,b,c do | ||
24 | v= v+i | ||
25 | end | ||
26 | return v, hey | ||
27 | end | ||
28 | |||
29 | local gc_cb = function(name_, status_) | ||
30 | PRINT(" ---> lane '" .. name_ .. "' collected with status '" .. status_ .. "'") | ||
31 | end | ||
32 | |||
33 | -- ################################################################################################## | ||
34 | -- ################################################################################################## | ||
35 | -- ################################################################################################## | ||
36 | |||
37 | PRINT("\n\n", "---=== Stdlib naming ===---", "\n\n") | ||
38 | |||
39 | local function dump_g(_x) | ||
40 | lane_threadname "dump_g" | ||
41 | assert(print) | ||
42 | print("### dumping _G for '" .. _x .. "'") | ||
43 | for k, v in pairs(_G) do | ||
44 | print("\t" .. k .. ": " .. type(v)) | ||
45 | end | ||
46 | return true | ||
47 | end | ||
48 | |||
49 | local function io_os_f(_x) | ||
50 | lane_threadname "io_os_f" | ||
51 | assert(print) | ||
52 | print("### checking io and os libs existence for '" .. _x .. "'") | ||
53 | assert(io) | ||
54 | assert(os) | ||
55 | return true | ||
56 | end | ||
57 | |||
58 | local function coro_f(_x) | ||
59 | lane_threadname "coro_f" | ||
60 | assert(print) | ||
61 | print("### checking coroutine lib existence for '" .. _x .. "'") | ||
62 | assert(coroutine) | ||
63 | return true | ||
64 | end | ||
65 | |||
66 | assert.fails(function() lanes_gen("xxx", {gc_cb = gc_cb}, io_os_f) end) | ||
67 | |||
68 | local stdlib_naming_tests = | ||
69 | { | ||
70 | -- { "", dump_g}, | ||
71 | -- { "coroutine", dump_g}, | ||
72 | -- { "io", dump_g}, | ||
73 | -- { "bit32", dump_g}, | ||
74 | { "coroutine?", coro_f}, -- in Lua 5.1, the coroutine base library doesn't exist (coroutine table is created when 'base' is opened) | ||
75 | { "*", io_os_f}, | ||
76 | { "io,os", io_os_f}, | ||
77 | { "io+os", io_os_f}, | ||
78 | { "/io;os[base{", io_os_f}, -- use unconventional name separators to check that everything works fine | ||
79 | } | ||
80 | |||
81 | for _, t in ipairs(stdlib_naming_tests) do | ||
82 | local f= lanes_gen(t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do | ||
83 | assert(f(t[1])[1]) | ||
84 | end | ||
85 | |||
86 | PRINT("collectgarbage") | ||
87 | collectgarbage() | ||