failtest: a new cmake-based test suite for testing stuff that should fail to build. This first batch imports some const correctness checks from bug #54.
This commit is contained in:
		
							parent
							
								
									8aee724274
								
							
						
					
					
						commit
						9b13e9aece
					
				| @ -5,7 +5,7 @@ cmake_minimum_required(VERSION 2.6.2) | ||||
| # guard against in-source builds | ||||
| 
 | ||||
| if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) | ||||
|   message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. (you may need to remove CMakeCache.txt ") | ||||
|   message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ") | ||||
| endif() | ||||
| 
 | ||||
| # guard against bad build-type strings | ||||
| @ -316,6 +316,10 @@ message(STATUS "") | ||||
| message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}") | ||||
| message(STATUS "") | ||||
| 
 | ||||
| if(EIGEN_FAILTEST) | ||||
|   add_subdirectory(failtest) | ||||
| endif() | ||||
| 
 | ||||
| string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower) | ||||
| if(cmake_generator_tolower MATCHES "makefile") | ||||
|   message(STATUS "Some things you can do now:") | ||||
|  | ||||
| @ -1,6 +1,8 @@ | ||||
| option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF) | ||||
| option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF) | ||||
| 
 | ||||
| include(CheckCXXSourceCompiles) | ||||
| 
 | ||||
| macro(ei_add_property prop value) | ||||
|   get_property(previous GLOBAL PROPERTY ${prop}) | ||||
|   set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}") | ||||
| @ -69,7 +71,6 @@ macro(ei_add_test_internal testname testname_with_suffix) | ||||
| 
 | ||||
| endmacro(ei_add_test_internal) | ||||
| 
 | ||||
| 
 | ||||
| # Macro to add a test | ||||
| # | ||||
| # the unique mandatory parameter testname must correspond to a file | ||||
| @ -140,6 +141,44 @@ macro(ei_add_test testname) | ||||
|   endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes) | ||||
| endmacro(ei_add_test) | ||||
| 
 | ||||
| 
 | ||||
| # adds a failtest, i.e. a test that succeed if the program fails to compile | ||||
| # 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) | ||||
| 
 | ||||
|   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() | ||||
| 
 | ||||
|   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() | ||||
| 
 | ||||
|   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() | ||||
| 
 | ||||
|   math(EXPR EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}+1) | ||||
| 
 | ||||
|   set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}) | ||||
|   set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}) | ||||
| endmacro(ei_add_failtest) | ||||
| 
 | ||||
| # print a summary of the different options | ||||
| macro(ei_testing_print_summary) | ||||
| 
 | ||||
| @ -226,6 +265,12 @@ macro(ei_init_testing) | ||||
|   set_property(GLOBAL PROPERTY EIGEN_MISSING_BACKENDS "") | ||||
|   set_property(GLOBAL PROPERTY EIGEN_TESTING_SUMMARY "") | ||||
|   set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "") | ||||
| 
 | ||||
|   define_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT BRIEF_DOCS " " FULL_DOCS " ") | ||||
|   define_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT BRIEF_DOCS " " FULL_DOCS " ") | ||||
| 
 | ||||
|   set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT "0") | ||||
|   set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT "0") | ||||
| endmacro(ei_init_testing) | ||||
| 
 | ||||
| if(CMAKE_COMPILER_IS_GNUCXX) | ||||
|  | ||||
							
								
								
									
										17
									
								
								failtest/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								failtest/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| message(STATUS "Running the failtests") | ||||
| 
 | ||||
| ei_add_failtest("failtest_sanity_check") | ||||
| ei_add_failtest("block_nonconst_ctor_on_const_xpr_0") | ||||
| ei_add_failtest("block_nonconst_ctor_on_const_xpr_1") | ||||
| ei_add_failtest("block_nonconst_ctor_on_const_xpr_2") | ||||
| ei_add_failtest("transpose_nonconst_ctor_on_const_xpr") | ||||
| ei_add_failtest("diagonal_nonconst_ctor_on_const_xpr") | ||||
| 
 | ||||
| if (EIGEN_FAILTEST_FAILURE_COUNT) | ||||
|   message(FATAL_ERROR "${EIGEN_FAILTEST_FAILURE_COUNT} out of ${EIGEN_FAILTEST_COUNT} failtests FAILED. " | ||||
|                       "Failtests succeed when they generate build errors. " | ||||
|                       "To debug these failures, manually compile these programs in ${CMAKE_CURRENT_SOURCE_DIR}.") | ||||
| else() | ||||
|   message(STATUS "Failtest SUCCESS: all ${EIGEN_FAILTEST_COUNT} failtests passed.") | ||||
|   message(STATUS "") | ||||
| endif() | ||||
							
								
								
									
										15
									
								
								failtest/block_nonconst_ctor_on_const_xpr_0.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								failtest/block_nonconst_ctor_on_const_xpr_0.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #include "../Eigen/Core" | ||||
| 
 | ||||
| #ifdef EIGEN_SHOULD_FAIL_TO_BUILD | ||||
| #define CV_QUALIFIER const | ||||
| #else | ||||
| #define CV_QUALIFIER | ||||
| #endif | ||||
| 
 | ||||
| using namespace Eigen; | ||||
| 
 | ||||
| void foo(CV_QUALIFIER Matrix3d &m){ | ||||
|     Block<Matrix3d,3,3> b(m,0,0); | ||||
| } | ||||
| 
 | ||||
| int main() {} | ||||
							
								
								
									
										15
									
								
								failtest/block_nonconst_ctor_on_const_xpr_1.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								failtest/block_nonconst_ctor_on_const_xpr_1.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #include "../Eigen/Core" | ||||
| 
 | ||||
| #ifdef EIGEN_SHOULD_FAIL_TO_BUILD | ||||
| #define CV_QUALIFIER const | ||||
| #else | ||||
| #define CV_QUALIFIER | ||||
| #endif | ||||
| 
 | ||||
| using namespace Eigen; | ||||
| 
 | ||||
| void foo(CV_QUALIFIER Matrix3d &m){ | ||||
|     Block<Matrix3d> b(m,0,0,3,3); | ||||
| } | ||||
| 
 | ||||
| int main() {} | ||||
							
								
								
									
										16
									
								
								failtest/block_nonconst_ctor_on_const_xpr_2.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								failtest/block_nonconst_ctor_on_const_xpr_2.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| #include "../Eigen/Core" | ||||
| 
 | ||||
| #ifdef EIGEN_SHOULD_FAIL_TO_BUILD | ||||
| #define CV_QUALIFIER const | ||||
| #else | ||||
| #define CV_QUALIFIER | ||||
| #endif | ||||
| 
 | ||||
| using namespace Eigen; | ||||
| 
 | ||||
| void foo(CV_QUALIFIER Matrix3d &m){ | ||||
|     // row/column constructor
 | ||||
|     Block<Matrix3d,3,1> b(m,0); | ||||
| } | ||||
| 
 | ||||
| int main() {} | ||||
							
								
								
									
										15
									
								
								failtest/diagonal_nonconst_ctor_on_const_xpr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								failtest/diagonal_nonconst_ctor_on_const_xpr.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #include "../Eigen/Core" | ||||
| 
 | ||||
| #ifdef EIGEN_SHOULD_FAIL_TO_BUILD | ||||
| #define CV_QUALIFIER const | ||||
| #else | ||||
| #define CV_QUALIFIER | ||||
| #endif | ||||
| 
 | ||||
| using namespace Eigen; | ||||
| 
 | ||||
| void foo(CV_QUALIFIER Matrix3d &m){ | ||||
|     Diagonal<Matrix3d> d(m); | ||||
| } | ||||
| 
 | ||||
| int main() {} | ||||
							
								
								
									
										5
									
								
								failtest/failtest_sanity_check.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								failtest/failtest_sanity_check.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| #ifdef EIGEN_SHOULD_FAIL_TO_BUILD | ||||
| This is just some text that won't compile as a C++ file, as a basic sanity check for failtest. | ||||
| #else | ||||
| int main() {} | ||||
| #endif | ||||
							
								
								
									
										15
									
								
								failtest/transpose_nonconst_ctor_on_const_xpr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								failtest/transpose_nonconst_ctor_on_const_xpr.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #include "../Eigen/Core" | ||||
| 
 | ||||
| #ifdef EIGEN_SHOULD_FAIL_TO_BUILD | ||||
| #define CV_QUALIFIER const | ||||
| #else | ||||
| #define CV_QUALIFIER | ||||
| #endif | ||||
| 
 | ||||
| using namespace Eigen; | ||||
| 
 | ||||
| void foo(CV_QUALIFIER Matrix3d &m){ | ||||
|     Transpose<Matrix3d> t(m); | ||||
| } | ||||
| 
 | ||||
| int main() {} | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Benoit Jacob
						Benoit Jacob