aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2011-02-05 18:57:29 -0500
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2011-02-05 18:57:29 -0500
commit9b13e9aeceffd56fb1560a8aef51079ae65f13c4 (patch)
tree15ae653c7db613570d8e3b9c40b2737cb04d70fd
parent8aee724274ea4d70f926c544cf57e706c61a3e82 (diff)
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.
-rw-r--r--CMakeLists.txt6
-rw-r--r--cmake/EigenTesting.cmake47
-rw-r--r--failtest/CMakeLists.txt17
-rw-r--r--failtest/block_nonconst_ctor_on_const_xpr_0.cpp15
-rw-r--r--failtest/block_nonconst_ctor_on_const_xpr_1.cpp15
-rw-r--r--failtest/block_nonconst_ctor_on_const_xpr_2.cpp16
-rw-r--r--failtest/diagonal_nonconst_ctor_on_const_xpr.cpp15
-rw-r--r--failtest/failtest_sanity_check.cpp5
-rw-r--r--failtest/transpose_nonconst_ctor_on_const_xpr.cpp15
9 files changed, 149 insertions, 2 deletions
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<Matrix3d,3,3> 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<Matrix3d> 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<Matrix3d,3,1> 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<Matrix3d> 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<Matrix3d> t(m);
+}
+
+int main() {}