diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-06-24 08:53:36 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-06-24 08:53:36 +0200 |
| commit | 41dcaf101368350a49e756abc41f3e9c3c22ec66 (patch) | |
| tree | ff3e072f027f56feb6e2187c800abfa3386a5431 | |
| parent | b9f17d8a10c8508a893b0e86000128e0dbf2a146 (diff) | |
| download | lanes-41dcaf101368350a49e756abc41f3e9c3c22ec66.tar.gz lanes-41dcaf101368350a49e756abc41f3e9c3c22ec66.tar.bz2 lanes-41dcaf101368350a49e756abc41f3e9c3c22ec66.zip | |
Move some tests to a separate script
| -rw-r--r-- | unit_tests/UnitTests.vcxproj | 1 | ||||
| -rw-r--r-- | unit_tests/UnitTests.vcxproj.filters | 3 | ||||
| -rw-r--r-- | unit_tests/lane_tests.cpp | 1 | ||||
| -rw-r--r-- | unit_tests/scripts/lane/body_is_a_c_function.lua | 28 | ||||
| -rw-r--r-- | unit_tests/scripts/lane/tasking_basic.lua | 27 |
5 files changed, 33 insertions, 27 deletions
diff --git a/unit_tests/UnitTests.vcxproj b/unit_tests/UnitTests.vcxproj index 21abfae..79361c5 100644 --- a/unit_tests/UnitTests.vcxproj +++ b/unit_tests/UnitTests.vcxproj | |||
| @@ -967,6 +967,7 @@ | |||
| 967 | </ItemGroup> | 967 | </ItemGroup> |
| 968 | <ItemGroup> | 968 | <ItemGroup> |
| 969 | <None Include="..\.runsettings" /> | 969 | <None Include="..\.runsettings" /> |
| 970 | <None Include="scripts\lane\body_is_a_c_function.lua" /> | ||
| 970 | <None Include="scripts\lane\tasking_cancelling_with_hook.lua" /> | 971 | <None Include="scripts\lane\tasking_cancelling_with_hook.lua" /> |
| 971 | <None Include="scripts\linda\wake_period.lua" /> | 972 | <None Include="scripts\linda\wake_period.lua" /> |
| 972 | <None Include="UnitTests.makefile" /> | 973 | <None Include="UnitTests.makefile" /> |
diff --git a/unit_tests/UnitTests.vcxproj.filters b/unit_tests/UnitTests.vcxproj.filters index ce8cb58..dfa642b 100644 --- a/unit_tests/UnitTests.vcxproj.filters +++ b/unit_tests/UnitTests.vcxproj.filters | |||
| @@ -119,5 +119,8 @@ | |||
| 119 | <None Include="scripts\linda\wake_period.lua"> | 119 | <None Include="scripts\linda\wake_period.lua"> |
| 120 | <Filter>Scripts\linda</Filter> | 120 | <Filter>Scripts\linda</Filter> |
| 121 | </None> | 121 | </None> |
| 122 | <None Include="scripts\lane\body_is_a_c_function.lua"> | ||
| 123 | <Filter>Scripts\lane</Filter> | ||
| 124 | </None> | ||
| 122 | </ItemGroup> | 125 | </ItemGroup> |
| 123 | </Project> \ No newline at end of file | 126 | </Project> \ No newline at end of file |
diff --git a/unit_tests/lane_tests.cpp b/unit_tests/lane_tests.cpp index 3e5da2b..82ca1ad 100644 --- a/unit_tests/lane_tests.cpp +++ b/unit_tests/lane_tests.cpp | |||
| @@ -419,6 +419,7 @@ TEST_CASE("scripted_tests." #DIR "." #FILE) \ | |||
| 419 | _runner.performTest(FileRunnerParam{ #DIR "/" #FILE, TestType::CONDITION }); \ | 419 | _runner.performTest(FileRunnerParam{ #DIR "/" #FILE, TestType::CONDITION }); \ |
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | MAKE_TEST_CASE(lane, body_is_a_c_function, AssertNoLuaError) | ||
| 422 | MAKE_TEST_CASE(lane, cooperative_shutdown, AssertNoLuaError) | 423 | MAKE_TEST_CASE(lane, cooperative_shutdown, AssertNoLuaError) |
| 423 | #if LUA_VERSION_NUM >= 504 // // warnings are a Lua 5.4 feature | 424 | #if LUA_VERSION_NUM >= 504 // // warnings are a Lua 5.4 feature |
| 424 | // NOTE: when this test ends, there are resource leaks and a dangling thread | 425 | // NOTE: when this test ends, there are resource leaks and a dangling thread |
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 @@ | |||
| 1 | local lanes = require "lanes".configure() | ||
| 2 | |||
| 3 | -- ################################################################################################## | ||
| 4 | -- ################################################################################################## | ||
| 5 | -- ################################################################################################## | ||
| 6 | |||
| 7 | -- we can create a generator where the lane body is a C function | ||
| 8 | do | ||
| 9 | local b, g = pcall(lanes.gen, "*", print) | ||
| 10 | assert(b == true and type(g) == "function") | ||
| 11 | -- we can start the lane | ||
| 12 | local b, h = pcall(g, "hello") | ||
| 13 | -- the lane runs normally | ||
| 14 | h:join() | ||
| 15 | assert(h.status == "done") | ||
| 16 | end | ||
| 17 | |||
| 18 | -- we can create a generator where the lane body is a C function that raises an error | ||
| 19 | do | ||
| 20 | local b, g = pcall(lanes.gen, "*", error) | ||
| 21 | assert(b == true and type(g) == "function") | ||
| 22 | -- we can start the lane | ||
| 23 | local b, h = pcall(g, "this is an error") | ||
| 24 | -- this provides the error that occurred in the lane | ||
| 25 | local s, e, t = h:join() | ||
| 26 | assert(h.status == "error") | ||
| 27 | assert(s == nil and e == "this is an error" and t == nil) | ||
| 28 | 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) | |||
| 15 | -- ################################################################################################## | 15 | -- ################################################################################################## |
| 16 | -- ################################################################################################## | 16 | -- ################################################################################################## |
| 17 | 17 | ||
| 18 | -- we can create a generator where the lane body is a C function | ||
| 19 | do | ||
| 20 | local b, g = pcall(lanes.gen, "*", print) | ||
| 21 | assert(b == true and type(g) == "function") | ||
| 22 | -- we can start the lane | ||
| 23 | local b, h = pcall(g, "hello") | ||
| 24 | -- the lane runs normally | ||
| 25 | h:join() | ||
| 26 | assert(h.status == "done") | ||
| 27 | end | ||
| 28 | |||
| 29 | -- we can create a generator where the lane body is a C function that raises an error | ||
| 30 | do | ||
| 31 | local b, g = pcall(lanes.gen, "*", error) | ||
| 32 | assert(b == true and type(g) == "function") | ||
| 33 | -- we can start the lane | ||
| 34 | local b, h = pcall(g, "this is an error") | ||
| 35 | -- this provides the error that occurred in the lane | ||
| 36 | local s, e, t = h:join() | ||
| 37 | assert(h.status == "error") | ||
| 38 | assert(s == nil and e == "this is an error" and t == nil) | ||
| 39 | end | ||
| 40 | |||
| 41 | -- ################################################################################################## | ||
| 42 | -- ################################################################################################## | ||
| 43 | -- ################################################################################################## | ||
| 44 | |||
| 45 | local function task(a, b, c) | 18 | local function task(a, b, c) |
| 46 | local new_name = "task("..a..","..b..","..c..")" | 19 | local new_name = "task("..a..","..b..","..c..")" |
| 47 | -- test lane naming change | 20 | -- test lane naming change |
