Skip to content

Commit

Permalink
Fixing throw for only debug
Browse files Browse the repository at this point in the history
  • Loading branch information
roigcarlo committed Aug 30, 2023
1 parent f5b57bf commit 8f84d52
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ KRATOS_TEST_CASE_IN_SUITE(MapperUtilities_FillBufferBeforeLocalSearch, KratosMap
// xmax, xmin, ymax, ymin, zmax, zmin
const std::vector<double> 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,
Expand Down Expand Up @@ -287,7 +287,7 @@ KRATOS_TEST_CASE_IN_SUITE(MapperUtilities_CreateMapperInterfaceInfosFromBuffer,
MapperInterfaceInfoUniquePointerType p_ref_interface_info(Kratos::make_unique<NearestNeighborInterfaceInfo>());

// 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,
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions kratos/includes/expect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace Kratos {
// Check if geometry 2 can be found.
KRATOS_EXPECT_EQ(p_coupling_geometry->GetGeometryPart(CouplingGeometry<Node>::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.")

Expand Down
4 changes: 2 additions & 2 deletions kratos/tests/cpp_tests/sources/test_dof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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");
}

Expand Down
4 changes: 2 additions & 2 deletions kratos/tests/cpp_tests/sources/test_kratos_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ KRATOS_TEST_CASE_IN_SUITE(KratosComponentsGetNonExistingElement, KratosCoreFastS
KRATOS_EXPECT_TRUE(KratosComponents<Element>::Has("Element2D2N"));
KRATOS_EXPECT_FALSE(KratosComponents<Element>::Has("NonExisting2D2N"));

KRATOS_EXPECT_EXCEPTION_IS_THROWN(KratosComponents<Element>::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<Element>::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)
{
KRATOS_EXPECT_TRUE(KratosComponents<Variable<double>>::Has("TIME"));
KRATOS_EXPECT_FALSE(KratosComponents<Variable<double>>::Has("NON_EXISTING_VARIABLE_NAME"));

KRATOS_EXPECT_EXCEPTION_IS_THROWN(KratosComponents<Variable<double>>::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<Variable<double>>::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)
Expand Down
4 changes: 2 additions & 2 deletions kratos/tests/cpp_tests/utilities/test_search_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ KRATOS_TEST_CASE_IN_SUITE(SearchUtilitiesComputeBoundingBoxesWithTolerance, Krat
std::vector<double> bboxes_wrong_size(5);
std::vector<double> 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
Expand Down Expand Up @@ -81,7 +81,7 @@ KRATOS_TEST_CASE_IN_SUITE(SearchUtilitiesComputeBoundingBoxesWithToleranceChecki
std::vector<double> bboxes_wrong_size(5);
std::vector<double> 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
Expand Down

0 comments on commit 8f84d52

Please sign in to comment.