From 8f84d5273fd2f8f071672793b3dbe15d68db060a Mon Sep 17 00:00:00 2001 From: Carlos Roig Date: Wed, 30 Aug 2023 17:07:24 +0200 Subject: [PATCH] Fixing throw for only debug --- .../tests/cpp_tests/test_mapper_utilities.cpp | 8 ++++---- kratos/includes/expect.h | 6 ++++++ .../tests/cpp_tests/geometries/test_coupling_geometry.cpp | 2 +- kratos/tests/cpp_tests/sources/test_dof.cpp | 4 ++-- kratos/tests/cpp_tests/sources/test_kratos_components.cpp | 4 ++-- .../tests/cpp_tests/utilities/test_search_utilities.cpp | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/applications/MappingApplication/tests/cpp_tests/test_mapper_utilities.cpp b/applications/MappingApplication/tests/cpp_tests/test_mapper_utilities.cpp index 0b9fc5c0d676..94c8adbfb30d 100644 --- a/applications/MappingApplication/tests/cpp_tests/test_mapper_utilities.cpp +++ b/applications/MappingApplication/tests/cpp_tests/test_mapper_utilities.cpp @@ -141,7 +141,7 @@ KRATOS_TEST_CASE_IN_SUITE(MapperUtilities_FillBufferBeforeLocalSearch, KratosMap // xmax, xmin, ymax, ymin, zmax, zmin const std::vector missized_bounding_boxes {10.5, -2.8, 3.89}; - KRATOS_EXPECT_EXCEPTION_IS_THROWN(MapperUtilities::FillBufferBeforeLocalSearch( + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(MapperUtilities::FillBufferBeforeLocalSearch( local_systems, missized_bounding_boxes, buffer_size_estimate, @@ -287,7 +287,7 @@ KRATOS_TEST_CASE_IN_SUITE(MapperUtilities_CreateMapperInterfaceInfosFromBuffer, MapperInterfaceInfoUniquePointerType p_ref_interface_info(Kratos::make_unique()); // throws bcs "interface_info_container" has the wrong size - KRATOS_EXPECT_EXCEPTION_IS_THROWN(MapperUtilities::CreateMapperInterfaceInfosFromBuffer( + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(MapperUtilities::CreateMapperInterfaceInfosFromBuffer( recv_buffer, p_ref_interface_info, comm_rank, @@ -296,14 +296,14 @@ KRATOS_TEST_CASE_IN_SUITE(MapperUtilities_CreateMapperInterfaceInfosFromBuffer, interface_info_container.resize(comm_size); - KRATOS_EXPECT_EXCEPTION_IS_THROWN(MapperUtilities::CreateMapperInterfaceInfosFromBuffer( + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(MapperUtilities::CreateMapperInterfaceInfosFromBuffer( recv_buffer_wrong, p_ref_interface_info, comm_rank, interface_info_container), "Error: Rank 16 received a wrong buffer-size from rank 3!"); - KRATOS_EXPECT_EXCEPTION_IS_THROWN(MapperUtilities::CreateMapperInterfaceInfosFromBuffer( + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(MapperUtilities::CreateMapperInterfaceInfosFromBuffer( recv_buffer_wrong_2, p_ref_interface_info, comm_rank, diff --git a/kratos/includes/expect.h b/kratos/includes/expect.h index fa3c5cc90d8d..20e3e82c1aac 100644 --- a/kratos/includes/expect.h +++ b/kratos/includes/expect.h @@ -181,5 +181,11 @@ try { KRATOS_ERROR << "Missing Degree of Freedom for " << TheVariable.Name() \ << " in node " << TheNode.Id() << "." << std::endl; +#ifdef KRATOS_DEBUG +#define KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) KRATOS_EXPECT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) +#else +#define KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) if(false) KRATOS_EXPECT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) +#endif + ///@} ///@} addtogroup block diff --git a/kratos/tests/cpp_tests/geometries/test_coupling_geometry.cpp b/kratos/tests/cpp_tests/geometries/test_coupling_geometry.cpp index a8bbce3f0312..b1a727d8d35e 100644 --- a/kratos/tests/cpp_tests/geometries/test_coupling_geometry.cpp +++ b/kratos/tests/cpp_tests/geometries/test_coupling_geometry.cpp @@ -95,7 +95,7 @@ namespace Kratos { // Check if geometry 2 can be found. KRATOS_EXPECT_EQ(p_coupling_geometry->GetGeometryPart(CouplingGeometry::Slave).LocalSpaceDimension(), 2); - KRATOS_EXPECT_EXCEPTION_IS_THROWN( + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN( p_coupling_geometry->GetGeometryPart(2), "Index 2 out of range. CouplingGeometry #1 has 2 geometries.") diff --git a/kratos/tests/cpp_tests/sources/test_dof.cpp b/kratos/tests/cpp_tests/sources/test_dof.cpp index 326ee4d71f36..d7dbf18544fe 100644 --- a/kratos/tests/cpp_tests/sources/test_dof.cpp +++ b/kratos/tests/cpp_tests/sources/test_dof.cpp @@ -32,7 +32,7 @@ KRATOS_TEST_CASE_IN_SUITE(DofConstructorWtihoutVariableInVariablesList, KratosCo auto p_node = model_part.CreateNewNode(1, 0.0, 0.0, 0.0); - KRATOS_EXPECT_EXCEPTION_IS_THROWN(p_node->AddDof(VELOCITY_Y), + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(p_node->AddDof(VELOCITY_Y), "Error: The Dof-Variable VELOCITY_Y is not in the list of variables"); } @@ -47,7 +47,7 @@ KRATOS_TEST_CASE_IN_SUITE(DofConstructorWtihoutReactionInVariablesList, KratosCo auto p_node = model_part.CreateNewNode(1, 0.0, 0.0, 0.0); - KRATOS_EXPECT_EXCEPTION_IS_THROWN(p_node->AddDof(VELOCITY_Y, REACTION_Y), + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(p_node->AddDof(VELOCITY_Y, REACTION_Y), "Error: The Reaction-Variable REACTION_Y is not in the list of variables"); } diff --git a/kratos/tests/cpp_tests/sources/test_kratos_components.cpp b/kratos/tests/cpp_tests/sources/test_kratos_components.cpp index e2f62d81973d..dd6b2009d52e 100644 --- a/kratos/tests/cpp_tests/sources/test_kratos_components.cpp +++ b/kratos/tests/cpp_tests/sources/test_kratos_components.cpp @@ -38,7 +38,7 @@ KRATOS_TEST_CASE_IN_SUITE(KratosComponentsGetNonExistingElement, KratosCoreFastS KRATOS_EXPECT_TRUE(KratosComponents::Has("Element2D2N")); KRATOS_EXPECT_FALSE(KratosComponents::Has("NonExisting2D2N")); - KRATOS_EXPECT_EXCEPTION_IS_THROWN(KratosComponents::Get("NonExisting2D2N"), "Error: The component \"NonExisting2D2N\" is not registered!\nMaybe you need to import the application where it is defined?\nThe following components of this type are registered:"); + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(KratosComponents::Get("NonExisting2D2N"), "Error: The component \"NonExisting2D2N\" is not registered!\nMaybe you need to import the application where it is defined?\nThe following components of this type are registered:"); } KRATOS_TEST_CASE_IN_SUITE(KratosComponentsGetNonExistingVariable, KratosCoreFastSuite) @@ -46,7 +46,7 @@ KRATOS_TEST_CASE_IN_SUITE(KratosComponentsGetNonExistingVariable, KratosCoreFast KRATOS_EXPECT_TRUE(KratosComponents>::Has("TIME")); KRATOS_EXPECT_FALSE(KratosComponents>::Has("NON_EXISTING_VARIABLE_NAME")); - KRATOS_EXPECT_EXCEPTION_IS_THROWN(KratosComponents>::Get("NON_EXISTING_VARIABLE_NAME"), "Error: The component \"NON_EXISTING_VARIABLE_NAME\" is not registered!\nMaybe you need to import the application where it is defined?\nThe following components of this type are registered:"); + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(KratosComponents>::Get("NON_EXISTING_VARIABLE_NAME"), "Error: The component \"NON_EXISTING_VARIABLE_NAME\" is not registered!\nMaybe you need to import the application where it is defined?\nThe following components of this type are registered:"); } KRATOS_TEST_CASE_IN_SUITE(KratosComponentsAddDifferentObjectsSameName, KratosCoreFastSuite) diff --git a/kratos/tests/cpp_tests/utilities/test_search_utilities.cpp b/kratos/tests/cpp_tests/utilities/test_search_utilities.cpp index 7a332f78b073..4564ccf778aa 100644 --- a/kratos/tests/cpp_tests/utilities/test_search_utilities.cpp +++ b/kratos/tests/cpp_tests/utilities/test_search_utilities.cpp @@ -50,7 +50,7 @@ KRATOS_TEST_CASE_IN_SUITE(SearchUtilitiesComputeBoundingBoxesWithTolerance, Krat std::vector bboxes_wrong_size(5); std::vector bboxes_with_tol; - KRATOS_EXPECT_EXCEPTION_IS_THROWN(SearchUtilities::ComputeBoundingBoxesWithTolerance(bboxes_wrong_size, 1.235, bboxes_with_tol), + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(SearchUtilities::ComputeBoundingBoxesWithTolerance(bboxes_wrong_size, 1.235, bboxes_with_tol), "Error: Bounding Boxes size has to be a multiple of 6!"); // Cretae a vector containing the fake bboxes @@ -81,7 +81,7 @@ KRATOS_TEST_CASE_IN_SUITE(SearchUtilitiesComputeBoundingBoxesWithToleranceChecki std::vector bboxes_wrong_size(5); std::vector bboxes_with_tol; - KRATOS_EXPECT_EXCEPTION_IS_THROWN(SearchUtilities::ComputeBoundingBoxesWithToleranceCheckingNullBB(bboxes_wrong_size, 1.235, bboxes_with_tol), + KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(SearchUtilities::ComputeBoundingBoxesWithToleranceCheckingNullBB(bboxes_wrong_size, 1.235, bboxes_with_tol), "Error: Bounding Boxes size has to be a multiple of 6!"); // Cretae a vector containing the fake bboxes