From 9b13e9aeceffd56fb1560a8aef51079ae65f13c4 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sat, 5 Feb 2011 18:57:29 -0500 Subject: 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. --- CMakeLists.txt | 6 ++- cmake/EigenTesting.cmake | 47 ++++++++++++++++++++++- failtest/CMakeLists.txt | 17 ++++++++ failtest/block_nonconst_ctor_on_const_xpr_0.cpp | 15 ++++++++ failtest/block_nonconst_ctor_on_const_xpr_1.cpp | 15 ++++++++ failtest/block_nonconst_ctor_on_const_xpr_2.cpp | 16 ++++++++ failtest/diagonal_nonconst_ctor_on_const_xpr.cpp | 15 ++++++++ failtest/failtest_sanity_check.cpp | 5 +++ failtest/transpose_nonconst_ctor_on_const_xpr.cpp | 15 ++++++++ 9 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 failtest/CMakeLists.txt create mode 100644 failtest/block_nonconst_ctor_on_const_xpr_0.cpp create mode 100644 failtest/block_nonconst_ctor_on_const_xpr_1.cpp create mode 100644 failtest/block_nonconst_ctor_on_const_xpr_2.cpp create mode 100644 failtest/diagonal_nonconst_ctor_on_const_xpr.cpp create mode 100644 failtest/failtest_sanity_check.cpp create mode 100644 failtest/transpose_nonconst_ctor_on_const_xpr.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2361e26cf..86013403a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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:") diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake index 63e11f2c1..4c8039315 100644 --- a/cmake/EigenTesting.cmake +++ b/cmake/EigenTesting.cmake @@ -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) diff --git a/failtest/CMakeLists.txt b/failtest/CMakeLists.txt new file mode 100644 index 000000000..424ce1795 --- /dev/null +++ b/failtest/CMakeLists.txt @@ -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() diff --git a/failtest/block_nonconst_ctor_on_const_xpr_0.cpp b/failtest/block_nonconst_ctor_on_const_xpr_0.cpp new file mode 100644 index 000000000..40b82014f --- /dev/null +++ b/failtest/block_nonconst_ctor_on_const_xpr_0.cpp @@ -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 b(m,0,0); +} + +int main() {} diff --git a/failtest/block_nonconst_ctor_on_const_xpr_1.cpp b/failtest/block_nonconst_ctor_on_const_xpr_1.cpp new file mode 100644 index 000000000..ef6d53702 --- /dev/null +++ b/failtest/block_nonconst_ctor_on_const_xpr_1.cpp @@ -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 b(m,0,0,3,3); +} + +int main() {} diff --git a/failtest/block_nonconst_ctor_on_const_xpr_2.cpp b/failtest/block_nonconst_ctor_on_const_xpr_2.cpp new file mode 100644 index 000000000..43f18aecf --- /dev/null +++ b/failtest/block_nonconst_ctor_on_const_xpr_2.cpp @@ -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 b(m,0); +} + +int main() {} diff --git a/failtest/diagonal_nonconst_ctor_on_const_xpr.cpp b/failtest/diagonal_nonconst_ctor_on_const_xpr.cpp new file mode 100644 index 000000000..76398a2c2 --- /dev/null +++ b/failtest/diagonal_nonconst_ctor_on_const_xpr.cpp @@ -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 d(m); +} + +int main() {} diff --git a/failtest/failtest_sanity_check.cpp b/failtest/failtest_sanity_check.cpp new file mode 100644 index 000000000..769fa942d --- /dev/null +++ b/failtest/failtest_sanity_check.cpp @@ -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 diff --git a/failtest/transpose_nonconst_ctor_on_const_xpr.cpp b/failtest/transpose_nonconst_ctor_on_const_xpr.cpp new file mode 100644 index 000000000..4223e7fd7 --- /dev/null +++ b/failtest/transpose_nonconst_ctor_on_const_xpr.cpp @@ -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 t(m); +} + +int main() {} -- cgit v1.2.3