diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2025-07-24 16:51:49 +0200 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2025-07-24 16:51:49 +0200 |
commit | d8acb18ce8bf6e89a042d166f61b2934e8722cf0 (patch) | |
tree | 69f5046056f4aa38b868b057055da8144e029846 /unit_tests | |
parent | eb997664a5a0a7890efa050982854a1447aec70f (diff) | |
download | lanes-d8acb18ce8bf6e89a042d166f61b2934e8722cf0.tar.gz lanes-d8acb18ce8bf6e89a042d166f61b2934e8722cf0.tar.bz2 lanes-d8acb18ce8bf6e89a042d166f61b2934e8722cf0.zip |
Rework function bytecode dumping to be Lua5.5-ready
* prepare the luaL_Buffer in the destination state instead of the source state to prevent stack issues when everything happens in the same state
Diffstat (limited to 'unit_tests')
-rw-r--r-- | unit_tests/UnitTests.vcxproj.filters | 3 | ||||
-rw-r--r-- | unit_tests/linda_tests.cpp | 1 | ||||
-rw-r--r-- | unit_tests/scripts/lane/tasking_send_receive_code.lua | 18 | ||||
-rw-r--r-- | unit_tests/scripts/linda/send_receive_func_and_string.lua | 13 |
4 files changed, 25 insertions, 10 deletions
diff --git a/unit_tests/UnitTests.vcxproj.filters b/unit_tests/UnitTests.vcxproj.filters index a1db461..33d484a 100644 --- a/unit_tests/UnitTests.vcxproj.filters +++ b/unit_tests/UnitTests.vcxproj.filters | |||
@@ -146,5 +146,8 @@ | |||
146 | <None Include="scripts\coro\cancelling_suspended.lua"> | 146 | <None Include="scripts\coro\cancelling_suspended.lua"> |
147 | <Filter>Scripts\coro</Filter> | 147 | <Filter>Scripts\coro</Filter> |
148 | </None> | 148 | </None> |
149 | <None Include="scripts\linda\send_receive_func_and_string.lua"> | ||
150 | <Filter>Scripts\linda</Filter> | ||
151 | </None> | ||
149 | </ItemGroup> | 152 | </ItemGroup> |
150 | </Project> \ No newline at end of file | 153 | </Project> \ No newline at end of file |
diff --git a/unit_tests/linda_tests.cpp b/unit_tests/linda_tests.cpp index a36723a..8d3cd50 100644 --- a/unit_tests/linda_tests.cpp +++ b/unit_tests/linda_tests.cpp | |||
@@ -390,6 +390,7 @@ TEST_CASE("scripted_tests." #DIR "." #FILE) \ | |||
390 | 390 | ||
391 | MAKE_TEST_CASE(linda, multiple_keepers) | 391 | MAKE_TEST_CASE(linda, multiple_keepers) |
392 | MAKE_TEST_CASE(linda, send_receive) | 392 | MAKE_TEST_CASE(linda, send_receive) |
393 | MAKE_TEST_CASE(linda, send_receive_func_and_string) | ||
393 | MAKE_TEST_CASE(linda, send_registered_userdata) | 394 | MAKE_TEST_CASE(linda, send_registered_userdata) |
394 | MAKE_TEST_CASE(linda, wake_period) | 395 | MAKE_TEST_CASE(linda, wake_period) |
395 | 396 | ||
diff --git a/unit_tests/scripts/lane/tasking_send_receive_code.lua b/unit_tests/scripts/lane/tasking_send_receive_code.lua index cb3663f..fdc2602 100644 --- a/unit_tests/scripts/lane/tasking_send_receive_code.lua +++ b/unit_tests/scripts/lane/tasking_send_receive_code.lua | |||
@@ -53,28 +53,26 @@ local function chunk2(linda) | |||
53 | assert(info.linedefined == 32, "bad linedefined") -- start of 'chunk2' | 53 | assert(info.linedefined == 32, "bad linedefined") -- start of 'chunk2' |
54 | assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' | 54 | assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' |
55 | assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' | 55 | assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' |
56 | local k,func= linda:receive("down") | 56 | assert(linda:count("down") == 2, "bad linda contents") -- function, "ok" |
57 | assert(type(func)=="function", "not a function") | 57 | local k,func,str= linda:receive_batched("down", 2) |
58 | assert(k=="down") | 58 | assert(k=="down") |
59 | assert(type(func)=="function", "not a function") | ||
60 | assert(str=="ok", "bad receive result: " .. tostring(k) .. " -> ".. tostring(str)) | ||
61 | assert(linda:count("down") == 0, "bad linda contents") -- nothing | ||
59 | 62 | ||
60 | func(linda) | 63 | func(linda) |
61 | |||
62 | local k,str= linda:receive("down") | ||
63 | assert(str=="ok", "bad receive result") | ||
64 | |||
65 | linda:send("up", function() return ":)" end, "ok2") | 64 | linda:send("up", function() return ":)" end, "ok2") |
66 | end | 65 | end |
67 | 66 | ||
68 | local linda = lanes_linda{name = "auto"} | 67 | local linda = lanes_linda{name = "auto"} |
69 | local t2= lanes_gen("debug,package,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch | 68 | local t2= lanes_gen("debug,package,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch |
70 | linda:send("down", function(linda) linda:send("up", "ready!") end, | 69 | linda:send("down", function(linda) linda:send("up", "ready!") end, "ok") |
71 | "ok") | ||
72 | -- wait to see if the tiny function gets executed | 70 | -- wait to see if the tiny function gets executed |
73 | -- | 71 | -- |
74 | local k,s= linda:receive(1, "up") | 72 | local k,s= linda:receive(1, "up") |
75 | if t2.status == "error" then | 73 | if t2.status == "error" then |
76 | PRINT("t2 error: " , t2:join()) | 74 | local n,err,s = t2:join() |
77 | assert(false) | 75 | assert(false, "t2 error: " .. err) |
78 | end | 76 | end |
79 | PRINT(s) | 77 | PRINT(s) |
80 | assert(s=="ready!", s .. " is not 'ready!'") | 78 | assert(s=="ready!", s .. " is not 'ready!'") |
diff --git a/unit_tests/scripts/linda/send_receive_func_and_string.lua b/unit_tests/scripts/linda/send_receive_func_and_string.lua new file mode 100644 index 0000000..188cfcd --- /dev/null +++ b/unit_tests/scripts/linda/send_receive_func_and_string.lua | |||
@@ -0,0 +1,13 @@ | |||
1 | local lanes = require "lanes" | ||
2 | |||
3 | -- a newly created linda doesn't contain anything | ||
4 | local l = lanes.linda() | ||
5 | |||
6 | -- send a function and a string, make sure that's what we read back | ||
7 | l:send("k", function() end, "str") | ||
8 | local c = l:count("k") | ||
9 | assert(c == 2, "got " .. c) | ||
10 | local k, v1, v2 = l:receive_batched("k", 2) | ||
11 | local tv1, tv2 = type(v1), type(v2) | ||
12 | assert(k == "k" and tv1 == "function" and tv2 == "string", "got " .. tv1 .. " " .. tv2) | ||
13 | assert(l:count("k") == 0) | ||