File tree Expand file tree Collapse file tree 6 files changed +41
-21
lines changed Expand file tree Collapse file tree 6 files changed +41
-21
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,27 @@ function(cpp_library)
3333 target_compile_features (${arg_cpp_lib_NAME} INTERFACE cxx_std_20)
3434 add_library (${arg_cpp_lib_NAMESPACE} ::${arg_cpp_lib_NAME} ALIAS ${arg_cpp_lib_NAME} )
3535endfunction ()
36+
37+ # Adds unit test source files and dependencies to global lists for compilation at the end.
38+ #
39+ # @param SRCS
40+ # @param DEPS
41+ function (cpp_test)
42+ set (options "" )
43+ set (oneValueArgs "" )
44+ set (multiValueArgs
45+ SRCS
46+ DEPS
47+ )
48+ cmake_parse_arguments (arg_cpp_test "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
49+
50+ file (RELATIVE_PATH SRC_DIR "${PROJECT_SOURCE_DIR} " "${CMAKE_CURRENT_LIST_DIR} " )
51+
52+ foreach (SRC_FILE IN LISTS arg_cpp_test_SRCS)
53+ list (APPEND SOURCE_FILES_unitTest ${SRC_DIR} /${SRC_FILE} )
54+ endforeach ()
55+ set (SOURCE_FILES_unitTest "${SOURCE_FILES_unitTest} " CACHE INTERNAL "" )
56+
57+ list (APPEND LIB_DEPS_unitTest "${arg_cpp_test_DEPS} " )
58+ set (LIB_DEPS_unitTest "${LIB_DEPS_unitTest} " CACHE INTERNAL "" )
59+ endfunction ()
Original file line number Diff line number Diff line change @@ -15,10 +15,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
1515list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} /CMake)
1616include (ystdlib-cpp-helpers)
1717
18+ # Initiate unit test global variable lists
19+ set (SOURCE_FILES_unitTest "tests/test-main.cpp" CACHE INTERNAL "" )
20+ set (LIB_DEPS_unitTest "" CACHE INTERNAL "" )
21+
1822add_subdirectory (src/ystdlib)
1923
20- # Test dummy project
21- add_executable (dummy)
22- target_sources (dummy PRIVATE src/main.cpp)
23- target_link_libraries (dummy PRIVATE ystdlib::testlib)
24- target_compile_features (dummy PRIVATE cxx_std_20)
24+ add_executable (unitTest ${SOURCE_FILES_unitTest} )
25+ target_include_directories (unitTest PRIVATE "${CMAKE_CURRENT_LIST_DIR} /submodules" )
26+ target_link_libraries (unitTest PRIVATE ${LIB_DEPS_unitTest} )
27+ target_compile_features (unitTest PRIVATE cxx_std_20)
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11cpp_library(NAME testlib NAMESPACE ystdlib)
2+ cpp_test(SRCS test -hello.cpp DEPS ystdlib::testlib)
Original file line number Diff line number Diff line change 1+ #include < Catch2/single_include/catch2/catch.hpp>
2+ #include < ystdlib/testlib/hello.hpp>
3+
4+ TEST_CASE (" dummy" , " [ystdlib::testlib]" ) {
5+ REQUIRE ((13 == ystdlib::testlib::hello ().size ()));
6+ }
Original file line number Diff line number Diff line change 1+ #define CATCH_CONFIG_MAIN
2+ #include < Catch2/single_include/catch2/catch.hpp>
You can’t perform that action at this time.
0 commit comments