From fcbba59630c3951932a5d619eee8b1345c165686 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Wed, 9 Sep 2015 23:27:40 -0400 Subject: [PATCH] Enable tests in CMake build and fix relative path problems. As reported in #46, tests were not being built with CMake due to a typo. But they were also broken, because the relative path to the dynamic library used in the link commands for the test Python modules wasn't appropriate for running the tests from the source directory. Instead, we now copy the Python test scripts to the build directory and run them there. --- CMakeLists.txt | 2 +- libs/numpy/test/CMakeLists.txt | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98f6a770..d3daaa0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.3) project( boost.numpy ) -set(BUILD_TEST ON CACHE BOOL "Build Boost.NumPy Tests") +set(BUILD_TESTS ON CACHE BOOL "Build Boost.NumPy Tests") set(BUILD_EXAMPLES ON CACHE BOOL "Build Boost.NumPy Examples") # put our local cmake find scripts at the beginning of the cmake diff --git a/libs/numpy/test/CMakeLists.txt b/libs/numpy/test/CMakeLists.txt index 0075f927..6d0e5c6e 100644 --- a/libs/numpy/test/CMakeLists.txt +++ b/libs/numpy/test/CMakeLists.txt @@ -16,11 +16,19 @@ set( TestCommand ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${runCmakeTest} ) # custom macro with most of the redundant code for making a python test macro( addPythonTest _name _srcpy ) + ADD_CUSTOM_TARGET( + ${_srcpy} ALL + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_srcpy} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/${_srcpy} + ${CMAKE_CURRENT_BINARY_DIR}/${_srcpy} + ) + # make the pyd library link against boost_numpy python and boost TARGET_LINK_LIBRARIES(${_name} boost_numpy) - + # make a test of the module using the python source file in the test directory - ADD_TEST(${_name} ${TestCommand} ${TEST_SOURCE_DIR}/${_srcpy}) + ADD_TEST(${_name} ${TestCommand} ${CMAKE_CURRENT_BINARY_DIR}/${_srcpy}) # set the regex to use to recognize a failure since `python testfoo.py` # does not seem to return non-zero with a test failure