Skip to content

Commit

Permalink
test: add enum for test status and type, make each test a variable, a…
Browse files Browse the repository at this point in the history
…dd coro tests
  • Loading branch information
Mishura4 committed Aug 21, 2023
1 parent d18fb48 commit 54eaffa
Show file tree
Hide file tree
Showing 6 changed files with 1,156 additions and 562 deletions.
24 changes: 11 additions & 13 deletions include/dpp/coro/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ struct job {};

namespace detail {

template <typename... Args>
inline constexpr bool coroutine_has_ref_params_v = (std::is_reference_v<Args> || ... || false);

template <typename T, typename... Args>
inline constexpr bool coroutine_has_ref_params_v<T, Args...> = (std::is_reference_v<Args> || ... || (std::is_reference_v<T> && !std::is_invocable_v<T, Args...>));

#ifdef DPP_CORO_TEST
struct job_promise_base{};
#endif

/**
* @brief Coroutine promise type for a job
*/
template <bool has_reference_params>
template <typename... Args>
struct job_promise {

#ifdef DPP_CORO_TEST
Expand Down Expand Up @@ -118,7 +124,7 @@ struct job_promise {
* If you must pass a reference, pass it as a pointer or with std::ref, but you must fully understand the reason behind this warning, and what to avoid.
* If you prefer a safer type, use `coroutine` for synchronous execution, or `task` for parallel tasks, and co_await them.
*/
static_assert(!has_reference_params, "co_await is disabled in dpp::job when taking parameters by reference. read comment above this line for more info");
static_assert(!coroutine_has_ref_params_v<Args...>, "co_await is disabled in dpp::job when taking parameters by reference. read comment above this line for more info");

return std::forward<T>(expr);
}
Expand All @@ -128,26 +134,18 @@ struct job_promise {

} // namespace dpp

template <>
struct dpp::detail::std_coroutine::coroutine_traits<dpp::job> {
/**
* @brief Promise type for this coroutine signature.
*/
using promise_type = dpp::detail::job_promise<false>;
};

/**
* @brief Specialization of std::coroutine_traits, helps the standard library figure out a promise type from a coroutine function.
*/
template<typename T, typename... Args>
struct dpp::detail::std_coroutine::coroutine_traits<dpp::job, T, Args...> {
template<typename... Args>
struct dpp::detail::std_coroutine::coroutine_traits<dpp::job, Args...> {
/**
* @brief Promise type for this coroutine signature.
*
* When the coroutine is created from a lambda, that lambda is passed as a first parameter.
* Not ideal but we'll allow any callable that takes the rest of the arguments passed
*/
using promise_type = dpp::detail::job_promise<(std::is_reference_v<Args> || ... || (std::is_reference_v<T> && !std::is_invocable_v<T, Args...>))>;
using promise_type = dpp::detail::job_promise<Args...>;
};

#endif /* DPP_CORO */
49 changes: 28 additions & 21 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,27 +271,6 @@ target_compile_features(dpp PRIVATE cxx_thread_local)
target_compile_features(dpp PRIVATE cxx_variadic_templates)
target_compile_features(dpp PRIVATE cxx_attribute_deprecated)

if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}/..)
file(GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*")
foreach (fulltestname ${testnamelist})
get_filename_component(testname ${fulltestname} NAME)
if (NOT "${testname}" STREQUAL "dpp")
message("-- Configuring test: ${Green}${testname}${ColourReset} with source: ${modules_dir}/${testname}/*.cpp")
set (testsrc "")
file(GLOB testsrc "${modules_dir}/${testname}/*.cpp")
add_executable(${testname} ${testsrc})
target_compile_features(${testname} PRIVATE cxx_std_17)
target_link_libraries(${testname} PUBLIC ${modname})
endif()
endforeach()
add_test(
NAME unittests
COMMAND library/unittest
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/library
)
endif()

if(HAVE_PRCTL)
target_compile_definitions(dpp PRIVATE HAVE_PRCTL)
endif()
Expand Down Expand Up @@ -351,6 +330,34 @@ if(DPP_CORO)
execute_process(WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
COMMAND php buildtools/make_struct.php "\\Dpp\\Generator\\CoroGenerator")
endif()

if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}/..)
file(GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*")
foreach (fulltestname ${testnamelist})
get_filename_component(testname ${fulltestname} NAME)
if (NOT "${testname}" STREQUAL "dpp")
message("-- Configuring test: ${Green}${testname}${ColourReset} with source: ${modules_dir}/${testname}/*.cpp")
set (testsrc "")
file(GLOB testsrc "${modules_dir}/${testname}/*.cpp")
add_executable(${testname} ${testsrc})
if (DPP_CORO)
target_compile_features(${testname} PRIVATE cxx_std_20)
else()
target_compile_features(${testname} PRIVATE cxx_std_17)
endif()
if (MSVC)
target_compile_options(${testname} PRIVATE /utf-8)
endif()
target_link_libraries(${testname} PUBLIC ${modname})
endif()
endforeach()
add_test(
NAME unittests
COMMAND library/unittest
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/library
)
endif()

if(WIN32 AND NOT MINGW)
if (NOT WINDOWS_32_BIT)
Expand Down
Loading

0 comments on commit 54eaffa

Please sign in to comment.