From d32000239be9cbc18748dc71829cca9a138c8c5d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 6 Jul 2020 14:12:50 -0400 Subject: [PATCH] refactor tester --- unittest/formats/test_potential_file_reader.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 0533d547c2..8a6db0197c 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -39,6 +39,13 @@ using namespace LAMMPS_NS; using ::testing::MatchesRegex; using utils::split_words; +#define TEST_FAILURE(...) \ + if (Info::has_exceptions()) { \ + ASSERT_ANY_THROW({__VA_ARGS__}); \ + } else { \ + ASSERT_DEATH({__VA_ARGS__}, ""); \ + } + // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; @@ -108,15 +115,9 @@ TEST_F(PotentialFileReaderTest, Sw_noconv) if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("units real"); if (!verbose) ::testing::internal::GetCapturedStdout(); + ::testing::internal::CaptureStdout(); - if (Info::has_exceptions()) { - ASSERT_ANY_THROW( - PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber", utils::REAL2METAL);); - } else { - ASSERT_DEATH( - { PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber", utils::REAL2METAL); }, - ""); - } + TEST_FAILURE(PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber", utils::REAL2METAL);); std::string mesg = ::testing::internal::GetCapturedStdout(); ASSERT_THAT(mesg, MatchesRegex(".*ERROR on proc.*potential.*requires metal units but real.*")); }