aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/lane_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/lane_tests.cpp')
-rw-r--r--unit_tests/lane_tests.cpp60
1 files changed, 29 insertions, 31 deletions
diff --git a/unit_tests/lane_tests.cpp b/unit_tests/lane_tests.cpp
index 7f5f112..498c96e 100644
--- a/unit_tests/lane_tests.cpp
+++ b/unit_tests/lane_tests.cpp
@@ -89,35 +89,6 @@ TEST_CASE("lanes.gen")
89 89
90 // --------------------------------------------------------------------------------------------- 90 // ---------------------------------------------------------------------------------------------
91 91
92 SECTION("lanes.finally") // TODO: move this section somewhere else, in a dedicated finally TEST_CASE
93 {
94 // prepare a callback for lanes.finally()
95 static bool _wasCalled{};
96 static bool _allLanesTerminated{};
97 auto _finallyCB{ +[](lua_State* const L_) { _wasCalled = true; _allLanesTerminated = lua_toboolean(L_, 1); return 0; } };
98 lua_pushcfunction(S, _finallyCB);
99 lua_setglobal(S, "finallyCB");
100 // start a lane that lasts a long time
101 std::string_view const _script{
102 " lanes.finally(finallyCB)"
103 " g = lanes.gen('*',"
104 " {name = 'auto'},"
105 " function()"
106 " for i = 1,1e37 do end" // no cooperative cancellation checks here!
107 " end)"
108 " g()"
109 };
110 S.requireSuccess(_script);
111 // close the state before the lane ends.
112 // since we don't wait at all, it is possible that the OS thread for the lane hasn't even started at that point
113 S.close();
114 // the finally handler should have been called, and told all lanes are stopped
115 REQUIRE(_wasCalled);
116 REQUIRE(_allLanesTerminated);
117 }
118
119 // ---------------------------------------------------------------------------------------------
120
121 SECTION("default thread name is '<unnamed>'") 92 SECTION("default thread name is '<unnamed>'")
122 { 93 {
123 std::string_view const _script{ 94 std::string_view const _script{
@@ -172,7 +143,7 @@ TEST_CASE("lanes.gen")
172// ################################################################################################# 143// #################################################################################################
173// ################################################################################################# 144// #################################################################################################
174 145
175TEST_CASE("lane:cancel") 146TEST_CASE("lane.cancel")
176{ 147{
177 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } }; 148 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } };
178 149
@@ -252,7 +223,33 @@ TEST_CASE("lane:cancel")
252// ################################################################################################# 223// #################################################################################################
253// ################################################################################################# 224// #################################################################################################
254 225
255TEST_CASE("lane scripted tests") 226// unfortunately, VS Test adapter does not list individual sections,
227// so let's create a separate test case for each file with an ugly macro...
228
229#define MAKE_TEST_CASE(DIR, FILE, CONDITION)\
230TEST_CASE("scripted tests." #DIR "." #FILE) \
231{ \
232 FileRunner _runner(R"(.\lanes\unit_tests\scripts)"); \
233 _runner.performTest(FileRunnerParam{ #DIR "/" #FILE, TestType::CONDITION }); \
234}
235
236#if LUAJIT_FLAVOR() == 0
237MAKE_TEST_CASE(lane, cooperative_shutdown, AssertNoLuaError)
238#endif // LUAJIT_FLAVOR
239MAKE_TEST_CASE(lane, uncooperative_shutdown, AssertThrows)
240MAKE_TEST_CASE(lane, tasking_basic, AssertNoLuaError)
241MAKE_TEST_CASE(lane, tasking_cancelling, AssertNoLuaError)
242MAKE_TEST_CASE(lane, tasking_comms_criss_cross, AssertNoLuaError)
243MAKE_TEST_CASE(lane, tasking_communications, AssertNoLuaError)
244MAKE_TEST_CASE(lane, tasking_error, AssertNoLuaError)
245MAKE_TEST_CASE(lane, tasking_join_test, AssertNoLuaError)
246MAKE_TEST_CASE(lane, tasking_send_receive_code, AssertNoLuaError)
247MAKE_TEST_CASE(lane, stdlib_naming, AssertNoLuaError)
248MAKE_TEST_CASE(coro, basics, AssertNoLuaError)
249MAKE_TEST_CASE(coro, error_handling, AssertNoLuaError)
250
251/*
252TEST_CASE("lanes.scripted tests")
256{ 253{
257 auto const& _testParam = GENERATE( 254 auto const& _testParam = GENERATE(
258 FileRunnerParam{ PUC_LUA_ONLY("lane/cooperative_shutdown"), TestType::AssertNoLuaError }, // 0 255 FileRunnerParam{ PUC_LUA_ONLY("lane/cooperative_shutdown"), TestType::AssertNoLuaError }, // 0
@@ -272,3 +269,4 @@ TEST_CASE("lane scripted tests")
272 FileRunner _runner(R"(.\lanes\unit_tests\scripts)"); 269 FileRunner _runner(R"(.\lanes\unit_tests\scripts)");
273 _runner.performTest(_testParam); 270 _runner.performTest(_testParam);
274} 271}
272*/