From 41dcaf101368350a49e756abc41f3e9c3c22ec66 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 24 Jun 2025 08:53:36 +0200 Subject: Move some tests to a separate script --- unit_tests/scripts/lane/body_is_a_c_function.lua | 28 ++++++++++++++++++++++++ unit_tests/scripts/lane/tasking_basic.lua | 27 ----------------------- 2 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 unit_tests/scripts/lane/body_is_a_c_function.lua (limited to 'unit_tests/scripts') diff --git a/unit_tests/scripts/lane/body_is_a_c_function.lua b/unit_tests/scripts/lane/body_is_a_c_function.lua new file mode 100644 index 0000000..d8d329f --- /dev/null +++ b/unit_tests/scripts/lane/body_is_a_c_function.lua @@ -0,0 +1,28 @@ +local lanes = require "lanes".configure() + +-- ################################################################################################## +-- ################################################################################################## +-- ################################################################################################## + +-- we can create a generator where the lane body is a C function +do + local b, g = pcall(lanes.gen, "*", print) + assert(b == true and type(g) == "function") + -- we can start the lane + local b, h = pcall(g, "hello") + -- the lane runs normally + h:join() + assert(h.status == "done") +end + +-- we can create a generator where the lane body is a C function that raises an error +do + local b, g = pcall(lanes.gen, "*", error) + assert(b == true and type(g) == "function") + -- we can start the lane + local b, h = pcall(g, "this is an error") + -- this provides the error that occurred in the lane + local s, e, t = h:join() + assert(h.status == "error") + assert(s == nil and e == "this is an error" and t == nil) +end diff --git a/unit_tests/scripts/lane/tasking_basic.lua b/unit_tests/scripts/lane/tasking_basic.lua index 7a22307..233accf 100644 --- a/unit_tests/scripts/lane/tasking_basic.lua +++ b/unit_tests/scripts/lane/tasking_basic.lua @@ -15,33 +15,6 @@ local lanes_linda = assert(lanes.linda) -- ################################################################################################## -- ################################################################################################## --- we can create a generator where the lane body is a C function -do - local b, g = pcall(lanes.gen, "*", print) - assert(b == true and type(g) == "function") - -- we can start the lane - local b, h = pcall(g, "hello") - -- the lane runs normally - h:join() - assert(h.status == "done") -end - --- we can create a generator where the lane body is a C function that raises an error -do - local b, g = pcall(lanes.gen, "*", error) - assert(b == true and type(g) == "function") - -- we can start the lane - local b, h = pcall(g, "this is an error") - -- this provides the error that occurred in the lane - local s, e, t = h:join() - assert(h.status == "error") - assert(s == nil and e == "this is an error" and t == nil) -end - --- ################################################################################################## --- ################################################################################################## --- ################################################################################################## - local function task(a, b, c) local new_name = "task("..a..","..b..","..c..")" -- test lane naming change -- cgit v1.2.3-55-g6feb