diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 09:18:19 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 09:18:19 +0200 |
| commit | 7c040842b09f952e98187b65019cd55176a5ddf4 (patch) | |
| tree | 0e5c3ac027429ddad0a4a85961eb97381a0f360a /unit_tests/scripts/_utils.lua | |
| parent | 72d7b36e020fd3f11ec002c110e7340f667d6628 (diff) | |
| download | lanes-7c040842b09f952e98187b65019cd55176a5ddf4.tar.gz lanes-7c040842b09f952e98187b65019cd55176a5ddf4.tar.bz2 lanes-7c040842b09f952e98187b65019cd55176a5ddf4.zip | |
Split coro tests in several scripts
Diffstat (limited to 'unit_tests/scripts/_utils.lua')
| -rw-r--r-- | unit_tests/scripts/_utils.lua | 20 |
1 files changed, 19 insertions, 1 deletions
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) | |||
| 68 | end | 68 | end |
| 69 | end | 69 | end |
| 70 | 70 | ||
| 71 | -- a function that yields back what got in, one element at a time | ||
| 72 | local yield_one_by_one = function(...) | ||
| 73 | local PRINT = MAKE_PRINT() | ||
| 74 | PRINT "In lane" | ||
| 75 | for _i = 1, select('#', ...) do | ||
| 76 | local _val = select(_i, ...) | ||
| 77 | PRINT("yielding #", _i, _val) | ||
| 78 | local _ack = coroutine.yield(_val) | ||
| 79 | if cancel_test and cancel_test() then -- cancel_test does not exist when run immediately (not in a Lane) | ||
| 80 | return "cancelled!" | ||
| 81 | end | ||
| 82 | -- of course, if we are cancelled, we were not resumed, and yield() didn't return what we expect | ||
| 83 | assert(_ack == _i) | ||
| 84 | end | ||
| 85 | return "bye!" | ||
| 86 | end | ||
| 87 | |||
| 71 | return { | 88 | return { |
| 72 | MAKE_PRINT = MAKE_PRINT, | 89 | MAKE_PRINT = MAKE_PRINT, |
| 73 | tables_match = tables_match, | 90 | tables_match = tables_match, |
| 74 | dump_error_stack = dump_error_stack | 91 | dump_error_stack = dump_error_stack, |
| 92 | yield_one_by_one = yield_one_by_one | ||
| 75 | } | 93 | } |
