Follow ctest and BUILD_TESTING best practices (#131)

This commit is contained in:
Qix 2018-10-06 06:30:07 -06:00 committed by Michele Caini
parent c4864f1a5b
commit acfa05a326
4 changed files with 7 additions and 17 deletions

View File

@ -54,5 +54,5 @@ install:
script:
- mkdir -p build && cd build
- cmake .. && make -j4
- CTEST_OUTPUT_ON_FAILURE=1 make test
- cmake .. -DBUILD_TESTING=ON && make -j4
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j4 -R uvw

View File

@ -49,12 +49,6 @@ set(PROJECT_SRC_DIR ${uvw_SOURCE_DIR}/src)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
#
# Enable test support using ctest-like interface
#
option(BUILD_TESTING "Enable testing with ctest." ON)
#
# Referenced packages
#
@ -81,9 +75,6 @@ if(BUILD_TESTING)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${PROJECT_DEPS_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${PROJECT_DEPS_DIR})
# Disable testing for dependencies
set(BUILD_TESTING OFF)
# gtest, gtest_main, gmock and gmock_main targets are available from now on
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${GOOGLETEST_DEPS_DIR})
@ -92,9 +83,6 @@ if(BUILD_TESTING)
add_subdirectory(${LIBUV_DEPS_DIR})
include_directories(${LIBUV_DEPS_DIR}/include)
# Enable testing for uvw
set(BUILD_TESTING ON)
add_subdirectory(test)
endif()

View File

@ -147,9 +147,11 @@ To compile and run the tests, `uvw` requires *libuv* and *googletest*.<br/>
To build the tests:
* `$ cd build`
* `$ cmake ..`
* `$ cmake .. -DBUILD_TESTING=ON`
* `$ make`
* `$ make test`
* `$ ctest -j4 -R uvw`
Omit `-R uvw` if you also want to test `libuv` and other dependencies.
# Crash Course

View File

@ -26,7 +26,7 @@ macro(ADD_UVW_TEST TEST_NAME TEST_SOURCE)
add_executable(${TEST_NAME} $<TARGET_OBJECTS:odr> ${TEST_SOURCE})
target_include_directories(${TEST_NAME} PRIVATE ${UVW_SRC_DIR})
target_link_libraries(${TEST_NAME} PRIVATE ${COMMON_LINK_LIBS})
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
add_test(NAME uvw_${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>)
endmacro()
macro(ADD_UVW_DIR_TEST TEST_NAME TEST_SOURCE)