simplify tests for failures with a varyadic macro

This commit is contained in:
Axel Kohlmeyer
2020-07-05 12:48:52 -04:00
parent cfaa3be898
commit ca24cd5006
2 changed files with 31 additions and 17 deletions

View File

@ -11,6 +11,7 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "info.h"
#include "input.h"
#include "lammps.h"
#include "utils.h"
@ -30,6 +31,14 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
using ::testing::Eq;
using ::testing::MatchesRegex;
#define TEST_FAILURE(...) \
if (Info::has_exceptions()) { \
ASSERT_ANY_THROW({__VA_ARGS__}); \
} else { \
ASSERT_DEATH({__VA_ARGS__}, ""); \
}
class SimpleCommandsTest : public ::testing::Test {
protected:
@ -81,6 +90,16 @@ TEST_F(SimpleCommandsTest, Echo)
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_EQ(lmp->input->echo_screen, 0);
ASSERT_EQ(lmp->input->echo_log, 1);
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("echo"););
auto mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex("^ERROR: Illegal echo command.*"));
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("echo xxx"););
mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex("^ERROR: Illegal echo command.*"));
}
TEST_F(SimpleCommandsTest, Log)