From bfbaaa89f7fb354443ff6302204696449ef7a4e4 Mon Sep 17 00:00:00 2001 From: Tobias Leibner <tobias.leibner@googlemail.com> Date: Tue, 8 Sep 2020 12:21:51 +0200 Subject: [PATCH] [test] fix tests in release mode --- dune/xt/test/common/crtp.cc | 3 +++ dune/xt/test/common/fmatrix.cc | 5 +++-- dune/xt/test/common/fvector.cc | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dune/xt/test/common/crtp.cc b/dune/xt/test/common/crtp.cc index 3415a3cd6..db1b73294 100644 --- a/dune/xt/test/common/crtp.cc +++ b/dune/xt/test/common/crtp.cc @@ -75,6 +75,8 @@ struct TestImp : public TestInterface<ImpTraits> } }; +// If NDEBUG is defined, the CHECK_CRTP macro does nothing, so the code below will not throw +#ifndef NDEBUG GTEST_TEST(crtp, fail) { TestInterface<FailTraits> test_iface; @@ -85,6 +87,7 @@ GTEST_TEST(crtp, fail) }, Dune::XT::Common::Exceptions::CRTP_check_failed); } +#endif // NDEBUG GTEST_TEST(crtp, success) { diff --git a/dune/xt/test/common/fmatrix.cc b/dune/xt/test/common/fmatrix.cc index 6655cca70..1cc2f65ed 100644 --- a/dune/xt/test/common/fmatrix.cc +++ b/dune/xt/test/common/fmatrix.cc @@ -31,14 +31,15 @@ GTEST_TEST(dune_xt_common_field_matrix, creation_and_calculations) ScalarMatrixType one(1.); ScalarMatrixType one2{1.}; MatrixType mat({{0., 1., 2.}, {3., 4., 5.}}); +// If NDEBUG is defined, the input is not checked in the constructor +#ifndef NDEBUG EXPECT_ANY_THROW(MatrixType({{0., 2.}, {3., 4., 5.}})); EXPECT_ANY_THROW(MatrixType({{0., 1., 2.}, {4., 5.}})); EXPECT_ANY_THROW(MatrixType({{0., 2.}, {4., 5.}})); EXPECT_ANY_THROW(ScalarMatrixType({{0., 2.}, {4., 5.}})); -#ifdef NDEBUG EXPECT_ANY_THROW(MatrixType(rows + 1, cols - 1, 1.)); EXPECT_ANY_THROW(ScalarMatrixType(2, 3, 1.)); -#endif +#endif // NDEBUG EXPECT_EQ(zero[0][0], 0.); EXPECT_EQ(one[0][0], 1.); EXPECT_EQ(one2[0][0], 1.); diff --git a/dune/xt/test/common/fvector.cc b/dune/xt/test/common/fvector.cc index 80e471642..dc4829dfc 100644 --- a/dune/xt/test/common/fvector.cc +++ b/dune/xt/test/common/fvector.cc @@ -34,7 +34,10 @@ GTEST_TEST(dune_xt_common_field_vector, creation_and_calculations) VectorType test_vec{0, 1, 2, 3}; for (size_t ii = 0; ii < 4; ++ii) EXPECT_EQ(test_vec[ii], ii); +// If NDEBUG is defined, the input is not checked in the constructor +#ifndef NDEBUG EXPECT_ANY_THROW(VectorType({1, 2, 3})); +#endif VectorType copy_assigned = test_vec; check(copy_assigned, test_vec); VectorType copy_constructed(test_vec); @@ -45,8 +48,11 @@ GTEST_TEST(dune_xt_common_field_vector, creation_and_calculations) std::vector<double> std_vec2 = test_vec; for (size_t ii = 0; ii < 4; ++ii) EXPECT_EQ(std_vec2[ii], ii); +// If NDEBUG is defined, the input is not checked in the constructor +#ifndef NDEBUG std_vec.resize(2); EXPECT_ANY_THROW(VectorType{std_vec}); +#endif BaseVectorType base_vec{0, 1, 2, 3}; VectorType constructed_from_base(base_vec); check(constructed_from_base, test_vec); -- GitLab