aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-12-12 15:48:36 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-12-12 15:48:36 +0100
commit72c0bbe2bd1c49c75b6efdb81d0558f8b62578d1 (patch)
tree0085849ac123593d69b5d53e6c11abcbee8f024b /cmake
parent37c91e18368e77a333afd2f5a1fd52026014fca5 (diff)
Simplify handling of tests that must fail to compile.
Each test is now a normal ctest target, and build properties (compiler+flags) are preserved (instead of starting a new build-dir from scratch).
Diffstat (limited to 'cmake')
-rw-r--r--cmake/EigenTesting.cmake45
1 files changed, 20 insertions, 25 deletions
diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake
index 35deed509..8cb2d5492 100644
--- a/cmake/EigenTesting.cmake
+++ b/cmake/EigenTesting.cmake
@@ -334,37 +334,32 @@ endmacro(ei_add_test_sycl)
# note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON
# so here we're just running CMake commands immediately, we're not adding any targets.
macro(ei_add_failtest testname)
- get_property(EIGEN_FAILTEST_FAILURE_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT)
- get_property(EIGEN_FAILTEST_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_COUNT)
- message(STATUS "Checking failtest: ${testname}")
- set(filename "${testname}.cpp")
- file(READ "${filename}" test_source)
+ set(test_target_ok ${testname}_ok)
+ set(test_target_ko ${testname}_ko)
- try_compile(succeeds_when_it_should_fail
- "${CMAKE_CURRENT_BINARY_DIR}"
- "${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
- COMPILE_DEFINITIONS "-DEIGEN_SHOULD_FAIL_TO_BUILD")
- if (succeeds_when_it_should_fail)
- message(STATUS "FAILED: ${testname} build succeeded when it should have failed")
- endif()
+ # Add executables
+ add_executable(${test_target_ok} ${testname}.cpp)
+ add_executable(${test_target_ko} ${testname}.cpp)
- try_compile(succeeds_when_it_should_succeed
- "${CMAKE_CURRENT_BINARY_DIR}"
- "${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
- COMPILE_DEFINITIONS)
- if (NOT succeeds_when_it_should_succeed)
- message(STATUS "FAILED: ${testname} build failed when it should have succeeded")
- endif()
+ # Remove them from the normal build process
+ set_target_properties(${test_target_ok} ${test_target_ko} PROPERTIES
+ EXCLUDE_FROM_ALL TRUE
+ EXCLUDE_FROM_DEFAULT_BUILD TRUE)
- if (succeeds_when_it_should_fail OR NOT succeeds_when_it_should_succeed)
- math(EXPR EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}+1)
- endif()
+ # Configure the failing test
+ target_compile_definitions(${test_target_ko} PRIVATE EIGEN_SHOULD_FAIL_TO_BUILD)
- math(EXPR EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}+1)
+ # Add the tests to ctest.
+ add_test(NAME ${test_target_ok}
+ COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ok} --config $<CONFIGURATION>
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
+ add_test(NAME ${test_target_ko}
+ COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ko} --config $<CONFIGURATION>
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
- set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT})
- set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT})
+ # Expect the second test to fail
+ set_tests_properties(${test_target_ko} PROPERTIES WILL_FAIL TRUE)
endmacro(ei_add_failtest)
# print a summary of the different options