add tests for unknown commands, quit, and reset_timestep

This commit is contained in:
Axel Kohlmeyer 2020-07-06 10:26:04 -04:00
parent f1abfe2411
commit 9ec72d1406
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 61 additions and 0 deletions

View File

@ -33,6 +33,7 @@ bool verbose = false;
using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
using ::testing::ExitedWithCode;
using ::testing::MatchesRegex;
using ::testing::StrEq;
@ -65,6 +66,14 @@ protected:
}
};
TEST_F(SimpleCommandsTest, UnknownCommand)
{
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("XXX one two three"););
auto mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Unknown command.*"));
}
TEST_F(SimpleCommandsTest, Echo)
{
ASSERT_EQ(lmp->input->echo_screen, 1);
@ -144,6 +153,58 @@ TEST_F(SimpleCommandsTest, Log)
ASSERT_THAT(text, StrEq("test2"));
in.close();
remove("simple_command_test.log");
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("log"););
auto mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Illegal log command.*"));
}
TEST_F(SimpleCommandsTest, Quit)
{
::testing::internal::CaptureStdout();
lmp->input->one("echo none");
TEST_FAILURE(lmp->input->one("quit xxx"););
auto mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Expected integer .*"));
ASSERT_EXIT(lmp->input->one("quit"), ExitedWithCode(0), "");
ASSERT_EXIT(lmp->input->one("quit 9"), ExitedWithCode(9), "");
}
TEST_F(SimpleCommandsTest, ResetTimestep)
{
ASSERT_EQ(lmp->update->ntimestep, 0);
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("reset_timestep 10");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_EQ(lmp->update->ntimestep, 10);
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("reset_timestep 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_EQ(lmp->update->ntimestep, 0);
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("reset_timestep -10"););
auto mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Timestep must be >= 0.*"));
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("reset_timestep"););
mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Illegal reset_timestep .*"));
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("reset_timestep 10 10"););
mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Illegal reset_timestep .*"));
::testing::internal::CaptureStdout();
TEST_FAILURE(lmp->input->one("reset_timestep xxx"););
mesg = ::testing::internal::GetCapturedStdout();
ASSERT_THAT(mesg, MatchesRegex(".*ERROR: Expected integer .*"));
}
TEST_F(SimpleCommandsTest, Suffix)