Support for fish_tests

This adds a basic Tests.cmake that can build and run fish_tests.
It also adds a 'test' target.
This commit is contained in:
ridiculousfish 2017-09-01 00:31:51 -07:00
parent fe37a1646d
commit af6bbbf83e
2 changed files with 34 additions and 4 deletions

31
CMakeFiles/Tests.cmake Normal file
View File

@ -0,0 +1,31 @@
# Define fish_tests.
ADD_EXECUTABLE(fish_tests src/fish_tests.cpp ${FISH_SRCS})
FISH_LINK_DEPS(fish_tests)
# Define the directory where the test tree will go.
SET(TESTS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/test/root/)
# Add a rule to symlink the tests directory.
ADD_CUSTOM_COMMAND(OUTPUT tests
COMMAND ln -s ${CMAKE_CURRENT_SOURCE_DIR}/tests
${CMAKE_CURRENT_BINARY_DIR}/tests
COMMENT "Linking tests directory..."
VERBATIM)
ADD_CUSTOM_TARGET(tests_dir DEPENDS tests)
ADD_DEPENDENCIES(fish_tests tests_dir)
# Create the 'test' target.
# Set a policy so CMake stops complaining about the name 'test'.
CMAKE_POLICY(PUSH)
IF(POLICY CMP0037)
CMAKE_POLICY(SET CMP0037 OLD)
ENDIF()
ADD_CUSTOM_TARGET(test COMMAND fish_tests)
CMAKE_POLICY(POP)
# Make the directory in which to run tests.
ADD_CUSTOM_TARGET(tests_root_target
COMMAND ${CMAKE_COMMAND} -E make_directory ${TESTS_INSTALL_DIR}
COMMAND DESTDIR=${CMAKE_BINARY_DIR}/tests_root ${CMAKE_COMMAND}
--build ${CMAKE_BINARY_DIR} --target install)
ADD_DEPENDENCIES(test tests_root_target)

View File

@ -67,8 +67,7 @@ ENDFUNCTION(FISH_LINK_DEPS)
# Define fish.
ADD_EXECUTABLE(fish src/fish.cpp ${FISH_SRCS})
TARGET_LINK_LIBRARIES(fish ${CURSES_LIBRARIES})
FISH_LINK_DEPS(fish)
# Link PCRE and muparser.
SET(PCRE2_WIDTH ${WCHAR_T_BITS})
TARGET_LINK_LIBRARIES(fish pcre2-${PCRE2_WIDTH} muparser)
# Set up tests.
INCLUDE(CMakeFiles/Tests.cmake)