Skip to content

Commit

Permalink
STYLE: Prefer using ITK_TRY_EXPECT_NO_EXCEPTION macro in tests
Browse files Browse the repository at this point in the history
Use the `ITK_TRY_EXPECT_NO_EXCEPTION` macro in tests in lieu of
`try/catch` blocks for the sake of readability and compactness, and to
save typing/avoid boilerplate code.
  • Loading branch information
jhlegarreta authored and hjmjohnson committed Mar 22, 2022
1 parent 1c3c7ba commit e484b4f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 38 deletions.
12 changes: 2 additions & 10 deletions Modules/Core/Mesh/test/itkBinaryMask3DMeshSourceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>

#include "itkBinaryMask3DMeshSource.h"
#include "itkTestingMacros.h"

// Define the dimension of the images
constexpr unsigned int Dimension = 3;
Expand Down Expand Up @@ -111,16 +112,7 @@ itkBinaryMask3DMeshSourceTest(int argc, char * argv[])
}
}

try
{
meshSource->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Exception thrown during Update() " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(meshSource->Update());

std::cout << meshSource->GetNameOfClass() << std::endl;
std::cout << meshSource->GetNumberOfNodes() << std::endl;
Expand Down
11 changes: 2 additions & 9 deletions Modules/Core/Mesh/test/itkRegularSphereMeshSourceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/

#include "itkRegularSphereMeshSource.h"
#include "itkTestingMacros.h"

#include <iostream>

Expand Down Expand Up @@ -48,15 +49,7 @@ itkRegularSphereMeshSourceTest(int, char *[])

mySphereMeshSource->Modified();

try
{
mySphereMeshSource->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error during Update() " << std::endl;
std::cerr << excp << std::endl;
}
ITK_TRY_EXPECT_NO_EXCEPTION(mySphereMeshSource->Update());

std::cout << "mySphereMeshSource: " << mySphereMeshSource;

Expand Down
12 changes: 2 additions & 10 deletions Modules/Core/Mesh/test/itkVTKPolyDataReaderTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,8 @@ itkVTKPolyDataReaderTest(int argc, char * argv[])

polyDataReader->SetFileName(argv[1]);

try
{
polyDataReader->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error during Update() " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(polyDataReader->Update());


std::cout << "polyDataReader:" << std::endl;
std::cout << polyDataReader << std::endl;
Expand Down
11 changes: 2 additions & 9 deletions Modules/Core/Mesh/test/itkVTKPolyDataWriterTest02.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,8 @@ itkVTKPolyDataWriterTest02(int argc, char * argv[])

mySphereMeshSource->Modified();

try
{
mySphereMeshSource->Update();
}
catch (const itk::ExceptionObject & excp)
{
std::cerr << "Error during Update() " << std::endl;
std::cerr << excp << std::endl;
}
ITK_TRY_EXPECT_NO_EXCEPTION(mySphereMeshSource->Update());


std::cout << "mySphereMeshSource: " << mySphereMeshSource;

Expand Down

0 comments on commit e484b4f

Please sign in to comment.