File tree Expand file tree Collapse file tree 3 files changed +40
-12
lines changed Expand file tree Collapse file tree 3 files changed +40
-12
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ SET(CMAKECONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}")
1515
1616find_package (Lua REQUIRED)
1717
18+ # BUILD_TEST could be: True/False constant like ON/OFF, or UNIT/PERF
1819option (BUILD_TEST "Build test." OFF )
1920option (NEED_VOLATILE "Support calling members by volatile objects." OFF )
2021
@@ -32,8 +33,12 @@ target_link_libraries(${PROJECT_NAME} INTERFACE ${LUA_LIBRARIES})
3233
3334if (BUILD_TEST)
3435 enable_testing ()
35- add_subdirectory (test /unit_test)
36- add_subdirectory (test /perf_test)
36+ if (${BUILD_TEST} OR (${BUILD_TEST} STREQUAL "UNIT" ))
37+ add_subdirectory (test /unit_test)
38+ endif ()
39+ if (${BUILD_TEST} OR (${BUILD_TEST} STREQUAL "PERF" ))
40+ add_subdirectory (test /perf_test)
41+ endif ()
3742endif ()
3843
3944configure_file ("${PROJECT_NAME} Config.cmake.in" "${PROJECT_NAME} Config.cmake"
Original file line number Diff line number Diff line change 1515
1616cd $( dirname " $0 " ) || exit
1717
18+ TEST=ON
19+ MYOSTREAM=OFF
20+ SEPARATE=OFF
21+ NEED_VOLATILE=OFF
22+ UTONLY=" "
23+
1824RUN_UNIT_TEST=0
1925RUN_PERFORMANCE_TEST=0
20- MYOSTREAM=OFF
2126REBUILD=0
2227CLEAR=0
23- SEPARATE=OFF
24- NEED_VOLATILE=OFF
28+
2529while [ " $# " -gt 0 ]; do
2630 case $1 in
31+ -t)
32+ TEST=$2
33+ shift
34+ shift
35+ ;;
2736 -ru)
2837 RUN_UNIT_TEST=1
2938 shift
@@ -57,8 +66,14 @@ while [ "$#" -gt 0 ]; do
5766 NEED_VOLATILE=ON
5867 shift
5968 ;;
69+ -utonly)
70+ UTONLY=$2
71+ shift
72+ shift
73+ ;;
6074 -h)
61- echo " run_test.sh [-o] [-r|-ru|-rp] [--rebuild] [--clear] [--separate] [--volatile]"
75+ echo " run_test.sh [-t UNIT/PERF] [-o] [-r|-ru|-rp] [--rebuild] [--clear]" \
76+ " [--separate] [--volatile] [-utonly <file>]"
6277 exit 0
6378 ;;
6479 * )
@@ -74,16 +89,21 @@ if [ ${REBUILD} -eq 1 ]; then
7489fi
7590mkdir -p build
7691cd build
77- cmake .. -DBUILD_TEST=TRUE \
92+ cmake .. -DBUILD_TEST=${TEST} \
7893 -DENABLE_MYOSTREAM_WATCH=${MYOSTREAM} \
7994 -DUNIT_TEST_SEPARATE=${SEPARATE} \
80- -DNEED_VOLATILE=${NEED_VOLATILE}
95+ -DNEED_VOLATILE=${NEED_VOLATILE} \
96+ -DUTONLY=${UTONLY}
8197make
8298
8399if [ $? -eq 0 ]; then
84100 ctest --output-on-failure
85101 if [ ${RUN_UNIT_TEST} -eq 1 ]; then
86- ./test/unit_test/unit_test
102+ if [ -n " ${UTONLY} " ]; then
103+ ./test/unit_test/${UTONLY}
104+ else
105+ ./test/unit_test/unit_test
106+ fi
87107 fi
88108 if [ ${RUN_PERFORMANCE_TEST} -eq 1 ]; then
89109 ./test/perf_test/perf_test
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ find_package(GTest REQUIRED)
1212
1313option (ENABLE_MYOSTREAM_WATCH "Use lib myostream to print variables to console." OFF )
1414option (UNIT_TEST_SEPARATE "Whether build unit tests separately." OFF )
15+ option (UTONLY "Only build one unit test file." "" )
1516
1617if (ENABLE_MYOSTREAM_WATCH)
1718 find_package (MyOStream REQUIRED)
@@ -25,7 +26,7 @@ function(build_target TARGET)
2526 ${LUA_INCLUDE_DIR}
2627 ${MyOStream_INCLUDE_DIR} )
2728 target_link_libraries (${TARGET} PUBLIC ${GTEST_LIBRARIES} ${LUA_LIBRARIES} )
28- add_test (NAME ${TARGET} COMMAND ${TARGET} )
29+ # add_test(NAME ${TARGET} COMMAND ${TARGET})
2930 include (GoogleTest)
3031 gtest_discover_tests(${TARGET} )
3132endfunction ()
@@ -34,8 +35,10 @@ file(GLOB SOURCE_FILES "*.cpp")
3435
3536if (UNIT_TEST_SEPARATE)
3637 foreach (FILE ${SOURCE_FILES} )
37- get_filename_component (NAME ${FILE} NAME_WE )
38- SET (TARGET ${NAME} )
38+ get_filename_component (TARGET ${FILE} NAME_WE )
39+ if (NOT ${UTONLY} STREQUAL "" AND NOT ${TARGET} STREQUAL ${UTONLY} )
40+ continue ()
41+ endif ()
3942 add_executable (${TARGET} ${FILE} "main.cpp" )
4043 build_target(${TARGET} )
4144 endforeach ()
You can’t perform that action at this time.
0 commit comments