From 7c040842b09f952e98187b65019cd55176a5ddf4 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 4 Jul 2025 09:18:19 +0200 Subject: Split coro tests in several scripts --- unit_tests/scripts/_utils.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'unit_tests/scripts/_utils.lua') diff --git a/unit_tests/scripts/_utils.lua b/unit_tests/scripts/_utils.lua index d710702..9f46237 100644 --- a/unit_tests/scripts/_utils.lua +++ b/unit_tests/scripts/_utils.lua @@ -68,8 +68,26 @@ local function dump_error_stack(error_reporting_mode_, stack) end end +-- a function that yields back what got in, one element at a time +local yield_one_by_one = function(...) + local PRINT = MAKE_PRINT() + PRINT "In lane" + for _i = 1, select('#', ...) do + local _val = select(_i, ...) + PRINT("yielding #", _i, _val) + local _ack = coroutine.yield(_val) + if cancel_test and cancel_test() then -- cancel_test does not exist when run immediately (not in a Lane) + return "cancelled!" + end + -- of course, if we are cancelled, we were not resumed, and yield() didn't return what we expect + assert(_ack == _i) + end + return "bye!" +end + return { MAKE_PRINT = MAKE_PRINT, tables_match = tables_match, - dump_error_stack = dump_error_stack + dump_error_stack = dump_error_stack, + yield_one_by_one = yield_one_by_one } -- cgit v1.2.3-55-g6feb