Use HasSubstr since output order is dependent on buffering

This commit is contained in:
Richard Berger
2021-03-23 20:13:39 -04:00
parent 359a369573
commit 23c8d8ccfb

View File

@ -34,6 +34,7 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::MatchesRegex; using ::testing::MatchesRegex;
using ::testing::StrEq; using ::testing::StrEq;
using ::testing::HasSubstr;
class PythonPackageTest : public ::testing::Test { class PythonPackageTest : public ::testing::Test {
protected: protected:
@ -86,7 +87,7 @@ TEST_F(PythonPackageTest, python_invoke)
command("python printnum invoke"); command("python printnum invoke");
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); ASSERT_THAT(output, HasSubstr("2.25\n"));
// execute another python function from same file // execute another python function from same file
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -96,7 +97,7 @@ TEST_F(PythonPackageTest, python_invoke)
command("python printtxt invoke"); command("python printtxt invoke");
output = ::testing::internal::GetCapturedStdout(); output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
ASSERT_THAT(output, MatchesRegex("python.*sometext.*")); ASSERT_THAT(output, HasSubstr("sometext\n"));
// execute python function that uses the LAMMPS python module // execute python function that uses the LAMMPS python module
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
@ -107,7 +108,7 @@ TEST_F(PythonPackageTest, python_invoke)
command("python getidxvar invoke"); command("python getidxvar invoke");
output = ::testing::internal::GetCapturedStdout(); output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); ASSERT_THAT(output, HasSubstr("2.25\n"));
} }
TEST_F(PythonPackageTest, python_variable) TEST_F(PythonPackageTest, python_variable)