add a macro to simplify adding unit tests

This commit is contained in:
derselbst 2018-04-06 22:07:21 +02:00
parent 2fbcd84238
commit 42a6a2153a
3 changed files with 14 additions and 4 deletions

View file

@ -508,7 +508,6 @@ configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake
add_subdirectory ( src )
add_subdirectory ( doc )
ENABLE_TESTING()
add_subdirectory ( test )
# pkg-config support

View file

@ -0,0 +1,9 @@
macro ( ADD_FLUID_TEST _test )
ADD_EXECUTABLE(${_test} ${_test}.c)
TARGET_LINK_LIBRARIES(${_test} libfluidsynth)
# use the local include path to look for fluidsynth.h, as we cannot be sure fluidsynth is already installed
target_include_directories(${_test} PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
ADD_TEST(NAME ${_test} COMMAND ${_test})
endmacro ( ADD_FLUID_TEST )

View file

@ -1,10 +1,12 @@
project(fluidsynth-test)
ENABLE_TESTING()
include ( FluidUnitTest )
ADD_FLUID_TEST(test_sfont_cache)
ADD_EXECUTABLE(test_sfont_cache test_sfont_cache.cpp)
TARGET_LINK_LIBRARIES(test_sfont_cache libfluidsynth)
ADD_TEST(NAME test_sfont_cache COMMAND test_sfont_cache)
# make test only runs tests, but doesnt build them
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_sfont_cache)