On Windows the Regex matcher for '.' does not match '\n'

Thus we have to use ContainsRegex instead of MatchesRegex
This commit is contained in:
Axel Kohlmeyer
2022-01-29 16:35:30 -05:00
parent d62e25decc
commit 845ab2dd71
13 changed files with 52 additions and 57 deletions

View File

@ -34,7 +34,6 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::ExitedWithCode; using ::testing::ExitedWithCode;
using ::testing::MatchesRegex;
using ::testing::StrEq; using ::testing::StrEq;
class GroupTest : public LAMMPSTest { class GroupTest : public LAMMPSTest {

View File

@ -33,7 +33,6 @@ bool verbose = false;
using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::MatchesRegex;
using ::testing::StrEq; using ::testing::StrEq;
class KimCommandsTest : public LAMMPSTest { class KimCommandsTest : public LAMMPSTest {

View File

@ -36,7 +36,7 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::ExitedWithCode; using ::testing::ExitedWithCode;
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
using ::testing::StrEq; using ::testing::StrEq;
class LatticeRegionTest : public LAMMPSTest { class LatticeRegionTest : public LAMMPSTest {
@ -82,7 +82,7 @@ TEST_F(LatticeRegionTest, lattice_sc)
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("lattice sc 1.0 spacing 1.5 2.0 3.0"); command("lattice sc 1.0 spacing 1.5 2.0 3.0");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 1.5.* 2.* 3.*")); ASSERT_THAT(output, ContainsRegex(".*Lattice spacing in x,y,z = 1.5.* 2.* 3.*"));
auto lattice = lmp->domain->lattice; auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->xlattice, 1.5); ASSERT_EQ(lattice->xlattice, 1.5);
@ -92,7 +92,7 @@ TEST_F(LatticeRegionTest, lattice_sc)
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("lattice sc 2.0"); command("lattice sc 2.0");
output = END_CAPTURE_OUTPUT(); output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 2.* 2.* 2.*")); ASSERT_THAT(output, ContainsRegex(".*Lattice spacing in x,y,z = 2.* 2.* 2.*"));
lattice = lmp->domain->lattice; lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::SC); ASSERT_EQ(lattice->style, Lattice::SC);

View File

@ -32,7 +32,6 @@ bool verbose = false;
using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::MatchesRegex;
#define GETIDX(i) lmp->atom->map(i) #define GETIDX(i) lmp->atom->map(i)

View File

@ -40,7 +40,7 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::ExitedWithCode; using ::testing::ExitedWithCode;
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
using ::testing::StrEq; using ::testing::StrEq;
class SimpleCommandsTest : public LAMMPSTest { class SimpleCommandsTest : public LAMMPSTest {
@ -394,62 +394,62 @@ TEST_F(SimpleCommandsTest, Plugin)
lmp->input->one(fmt::format(loadfmt, "hello")); lmp->input->one(fmt::format(loadfmt, "hello"));
auto text = ::testing::internal::GetCapturedStdout(); auto text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Loading plugin: Hello world command.*")); ASSERT_THAT(text, ContainsRegex(".*Loading plugin: Hello world command.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one(fmt::format(loadfmt, "xxx")); lmp->input->one(fmt::format(loadfmt, "xxx"));
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Open of file .*xxx.* failed.*")); ASSERT_THAT(text, ContainsRegex(".*Open of file .*xxx.* failed.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one(fmt::format(loadfmt, "nve2")); lmp->input->one(fmt::format(loadfmt, "nve2"));
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Loading plugin: NVE2 variant fix style.*")); ASSERT_THAT(text, ContainsRegex(".*Loading plugin: NVE2 variant fix style.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one("plugin list"); lmp->input->one("plugin list");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*1: command style plugin hello" ASSERT_THAT(text, ContainsRegex(".*1: command style plugin hello"
".*2: fix style plugin nve2.*")); ".*2: fix style plugin nve2.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one(fmt::format(loadfmt, "hello")); lmp->input->one(fmt::format(loadfmt, "hello"));
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Ignoring load of command style hello: " ASSERT_THAT(text, ContainsRegex(".*Ignoring load of command style hello: "
"must unload existing hello plugin.*")); "must unload existing hello plugin.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one("plugin unload command hello"); lmp->input->one("plugin unload command hello");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Unloading command style hello.*")); ASSERT_THAT(text, ContainsRegex(".*Unloading command style hello.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one("plugin unload pair nve2"); lmp->input->one("plugin unload pair nve2");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Ignoring unload of pair style nve2: not from a plugin.*")); ASSERT_THAT(text, ContainsRegex(".*Ignoring unload of pair style nve2: not from a plugin.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one("plugin unload fix nve2"); lmp->input->one("plugin unload fix nve2");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Unloading fix style nve2.*")); ASSERT_THAT(text, ContainsRegex(".*Unloading fix style nve2.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one("plugin unload fix nve"); lmp->input->one("plugin unload fix nve");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Ignoring unload of fix style nve: not from a plugin.*")); ASSERT_THAT(text, ContainsRegex(".*Ignoring unload of fix style nve: not from a plugin.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp->input->one("plugin list"); lmp->input->one("plugin list");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*Currently loaded plugins.*")); ASSERT_THAT(text, ContainsRegex(".*Currently loaded plugins.*"));
} }
#endif #endif
@ -495,8 +495,8 @@ TEST_F(SimpleCommandsTest, CiteMe)
std::string text = END_CAPTURE_OUTPUT(); std::string text = END_CAPTURE_OUTPUT();
// find the two unique citations, but not the third // find the two unique citations, but not the third
ASSERT_THAT(text, MatchesRegex(".*one.*two.*")); ASSERT_THAT(text, ContainsRegex(".*one.*two.*"));
ASSERT_THAT(text, Not(MatchesRegex(".*one.*two.*one.*"))); ASSERT_THAT(text, Not(ContainsRegex(".*one.*two.*one.*")));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
lmp->citeme->add("test citation one:\n 0\n"); lmp->citeme->add("test citation one:\n 0\n");
@ -507,8 +507,8 @@ TEST_F(SimpleCommandsTest, CiteMe)
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
// find the forth (only differs in long citation) and sixth added citation // find the forth (only differs in long citation) and sixth added citation
ASSERT_THAT(text, MatchesRegex(".*one.*three.*")); ASSERT_THAT(text, ContainsRegex(".*one.*three.*"));
ASSERT_THAT(text, Not(MatchesRegex(".*two.*"))); ASSERT_THAT(text, Not(ContainsRegex(".*two.*")));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
lmp->citeme->add("test citation one:\n 1\n"); lmp->citeme->add("test citation one:\n 1\n");
@ -521,7 +521,7 @@ TEST_F(SimpleCommandsTest, CiteMe)
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
// no new citation. no CITE-CITE-CITE- lines // no new citation. no CITE-CITE-CITE- lines
ASSERT_THAT(text, Not(MatchesRegex(".*CITE-CITE-CITE-CITE.*"))); ASSERT_THAT(text, Not(ContainsRegex(".*CITE-CITE-CITE-CITE.*")));
} }
} // namespace LAMMPS_NS } // namespace LAMMPS_NS

View File

@ -37,7 +37,7 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::ExitedWithCode; using ::testing::ExitedWithCode;
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
using ::testing::StrEq; using ::testing::StrEq;
class VariableTest : public LAMMPSTest { class VariableTest : public LAMMPSTest {
@ -394,58 +394,58 @@ TEST_F(VariableTest, IfCommand)
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if 1>0 then 'print \"bingo!\"'"); command("if 1>0 then 'print \"bingo!\"'");
auto text = END_CAPTURE_OUTPUT(); auto text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'"); command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); ASSERT_THAT(text, ContainsRegex(".*nope\?.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'"); command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); ASSERT_THAT(text, ContainsRegex(".*nope\?.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'"); command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'"); command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'"); command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'"); command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'"); command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if !(a==b) then 'print \"bingo!\"'"); command("if !(a==b) then 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if x==x|^1==0 then 'print \"bingo!\"'"); command("if x==x|^1==0 then 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("if x!=x|^a!=b then 'print \"bingo!\"'"); command("if x!=x|^a!=b then 'print \"bingo!\"'");
text = END_CAPTURE_OUTPUT(); text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, ContainsRegex(".*bingo!.*"));
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if () then 'print \"bingo!\"'");); command("if () then 'print \"bingo!\"'"););

View File

@ -17,7 +17,7 @@ bool verbose = false;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
using utils::split_words; using utils::split_words;
class Error_class : public LAMMPSTest { class Error_class : public LAMMPSTest {
@ -39,7 +39,7 @@ TEST_F(Error_class, message)
auto output = CAPTURE_OUTPUT([&] { auto output = CAPTURE_OUTPUT([&] {
error->message(FLERR, "one message"); error->message(FLERR, "one message");
}); });
ASSERT_THAT(output, MatchesRegex("one message .*test_error_class.cpp:.*")); ASSERT_THAT(output, ContainsRegex("one message .*test_error_class.cpp:.*"));
}; };
TEST_F(Error_class, warning) TEST_F(Error_class, warning)
@ -48,7 +48,7 @@ TEST_F(Error_class, warning)
auto output = CAPTURE_OUTPUT([&] { auto output = CAPTURE_OUTPUT([&] {
error->warning(FLERR, "one warning"); error->warning(FLERR, "one warning");
}); });
ASSERT_THAT(output, MatchesRegex("WARNING: one warning .*test_error_class.cpp:.*")); ASSERT_THAT(output, ContainsRegex("WARNING: one warning .*test_error_class.cpp:.*"));
ASSERT_THAT(error->get_maxwarn(), 100); ASSERT_THAT(error->get_maxwarn(), 100);
// warnings disabled // warnings disabled
@ -72,7 +72,7 @@ TEST_F(Error_class, warning)
output = CAPTURE_OUTPUT([&] { output = CAPTURE_OUTPUT([&] {
thermo->lost_check(); thermo->lost_check();
}); });
ASSERT_THAT(output, MatchesRegex("WARNING: Too many warnings: 5 vs 2. All future.*")); ASSERT_THAT(output, ContainsRegex("WARNING: Too many warnings: 5 vs 2. All future.*"));
output = CAPTURE_OUTPUT([&] { output = CAPTURE_OUTPUT([&] {
error->warning(FLERR, "one warning"); error->warning(FLERR, "one warning");
@ -91,7 +91,7 @@ TEST_F(Error_class, warning)
output = CAPTURE_OUTPUT([&] { output = CAPTURE_OUTPUT([&] {
error->warning(FLERR, "one warning"); error->warning(FLERR, "one warning");
}); });
ASSERT_THAT(output, MatchesRegex("WARNING: one warning.*")); ASSERT_THAT(output, ContainsRegex("WARNING: one warning.*"));
BEGIN_HIDE_OUTPUT(); BEGIN_HIDE_OUTPUT();
command("thermo_modify warn default"); command("thermo_modify warn default");

View File

@ -11,7 +11,7 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
using ::testing::StartsWith; using ::testing::StartsWith;
namespace LAMMPS_NS { namespace LAMMPS_NS {
@ -339,7 +339,7 @@ TEST(LAMMPS_init, OpenMP)
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, MatchesRegex(".*using 2 OpenMP thread.*per MPI task.*")); EXPECT_THAT(output, ContainsRegex(".*using 2 OpenMP thread.*per MPI task.*"));
if (LAMMPS_NS::Info::has_accelerator_feature("OPENMP", "api", "openmp")) if (LAMMPS_NS::Info::has_accelerator_feature("OPENMP", "api", "openmp"))
EXPECT_EQ(lmp->comm->nthreads, 2); EXPECT_EQ(lmp->comm->nthreads, 2);
@ -373,7 +373,7 @@ TEST(LAMMPS_init, NoOpenMP)
LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, EXPECT_THAT(output,
MatchesRegex(".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); ContainsRegex(".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*"));
EXPECT_EQ(lmp->comm->nthreads, 1); EXPECT_EQ(lmp->comm->nthreads, 1);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
delete lmp; delete lmp;

View File

@ -29,7 +29,6 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using testing::MatchesRegex;
using testing::StrEq; using testing::StrEq;
using utils::read_lines_from_file; using utils::read_lines_from_file;

View File

@ -26,7 +26,7 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using testing::MatchesRegex; using testing::ContainsRegex;
using testing::StrEq; using testing::StrEq;
using utils::split_words; using utils::split_words;
@ -173,7 +173,7 @@ TEST_F(MoleculeFileTest, minimal)
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*"));
} }
TEST_F(MoleculeFileTest, notype) TEST_F(MoleculeFileTest, notype)
@ -184,7 +184,7 @@ TEST_F(MoleculeFileTest, notype)
command("create_box 1 box"); command("create_box 1 box");
run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*"));
TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*", TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*",
command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465");); command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465"););
} }
@ -199,7 +199,7 @@ TEST_F(MoleculeFileTest, extramass)
" Types\n\n 1 1\n Masses\n\n 1 1.0\n"); " Types\n\n 1 1\n Masses\n\n 1 1.0\n");
command("create_atoms 0 single 0.0 0.0 0.0 mol extramass 73546"); command("create_atoms 0 single 0.0 0.0 0.0 mol extramass 73546");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*WARNING: Molecule attributes do not match " ASSERT_THAT(output, ContainsRegex(".*WARNING: Molecule attributes do not match "
"system attributes.*")); "system attributes.*"));
} }
@ -211,7 +211,7 @@ TEST_F(MoleculeFileTest, twomols)
" Coords\n\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n" " Coords\n\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n"
" Molecules\n\n 1 1\n 2 2\n\n Types\n\n 1 1\n 2 2\n\n"); " Molecules\n\n 1 1\n 2 2\n\n Types\n\n 1 1\n 2 2\n\n");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*2 molecules.*2 atoms " ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*2 molecules.*2 atoms "
"with max type 2.*0 bonds.*")); "with max type 2.*0 bonds.*"));
} }
@ -220,7 +220,7 @@ TEST_F(MoleculeFileTest, twofiles)
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("molecule twomols moltest.h2o.mol moltest.co2.mol offset 2 1 1 0 0"); command("molecule twomols moltest.h2o.mol moltest.co2.mol offset 2 1 1 0 0");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms " ASSERT_THAT(output, ContainsRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms "
"with max type 2.*2 bonds with max type 1.*" "with max type 2.*2 bonds with max type 1.*"
"1 angles with max type 1.*0 dihedrals.*" "1 angles with max type 1.*0 dihedrals.*"
".*Read molecule template twomols:.*1 molecules.*3 atoms " ".*Read molecule template twomols:.*1 molecules.*3 atoms "
@ -254,14 +254,14 @@ TEST_F(MoleculeFileTest, bonds)
" 1 1 1 2\n" " 1 1 1 2\n"
" 2 2 1 3\n\n"); " 2 2 1 3\n\n");
auto output = END_CAPTURE_OUTPUT(); auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*4 atoms.*type.*2.*" ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*4 atoms.*type.*2.*"
"2 bonds.*type.*2.*0 angles.*")); "2 bonds.*type.*2.*0 angles.*"));
BEGIN_CAPTURE_OUTPUT(); BEGIN_CAPTURE_OUTPUT();
command("mass * 2.0"); command("mass * 2.0");
command("create_atoms 0 single 0.5 0.5 0.5 mol bonds 67235"); command("create_atoms 0 single 0.5 0.5 0.5 mol bonds 67235");
output = END_CAPTURE_OUTPUT(); output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Created 4 atoms.*")); ASSERT_THAT(output, ContainsRegex(".*Created 4 atoms.*"));
BEGIN_HIDE_OUTPUT(); BEGIN_HIDE_OUTPUT();
Molecule *mol = lmp->atom->molecules[0]; Molecule *mol = lmp->atom->molecules[0];

View File

@ -37,7 +37,6 @@
#include <vector> #include <vector>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using ::testing::MatchesRegex;
using utils::split_words; using utils::split_words;
// whether to print verbose output (i.e. not capturing LAMMPS screen output). // whether to print verbose output (i.e. not capturing LAMMPS screen output).

View File

@ -45,7 +45,7 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::Eq; using ::testing::Eq;
using ::testing::HasSubstr; using ::testing::HasSubstr;
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
using ::testing::StrEq; using ::testing::StrEq;
class PythonPackageTest : public LAMMPSTest { class PythonPackageTest : public LAMMPSTest {
@ -238,7 +238,7 @@ TEST_F(PythonPackageTest, python_variable)
std::string output = CAPTURE_OUTPUT([&] { std::string output = CAPTURE_OUTPUT([&] {
command("print \"${sq}\""); command("print \"${sq}\"");
}); });
ASSERT_THAT(output, MatchesRegex("print.*2.25.*")); ASSERT_THAT(output, ContainsRegex("print.*2.25.*"));
} }
TEST_F(PythonPackageTest, InlineFunction) TEST_F(PythonPackageTest, InlineFunction)

View File

@ -28,20 +28,20 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using ::testing::MatchesRegex; using ::testing::ContainsRegex;
#define TEST_FAILURE(errmsg, ...) \ #define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \ if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \ ::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \ ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \ auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ ASSERT_THAT(mesg, ContainsRegex(errmsg)); \
} else { \ } else { \
if (platform::mpi_vendor() != "Open MPI") { \ if (platform::mpi_vendor() != "Open MPI") { \
::testing::internal::CaptureStdout(); \ ::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \ ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \ auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ ASSERT_THAT(mesg, ContainsRegex(errmsg)); \
} else { \ } else { \
std::cerr << "[ ] [ INFO ] Skipping death test (no exception support) \n"; \ std::cerr << "[ ] [ INFO ] Skipping death test (no exception support) \n"; \
} \ } \