Refactor and add fix python/invoke tests
This commit is contained in:
@ -16,9 +16,12 @@
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
#include "lammps.h"
|
||||
#include "variable.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
using ::testing::MatchesRegex;
|
||||
@ -45,29 +48,58 @@ class LAMMPSTest : public ::testing::Test {
|
||||
public:
|
||||
void command(const std::string &line) { lmp->input->one(line.c_str()); }
|
||||
|
||||
void HIDE_OUTPUT(std::function<void()> f) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
f();
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string CAPTURE_OUTPUT(std::function<void()> f) {
|
||||
::testing::internal::CaptureStdout();
|
||||
f();
|
||||
auto output = ::testing::internal::GetCapturedStdout();
|
||||
if (verbose) std::cout << output;
|
||||
return output;
|
||||
}
|
||||
|
||||
double get_variable_value(const std::string & name) {
|
||||
char * str = utils::strdup(fmt::format("v_{}", name));
|
||||
double value = lmp->input->variable->compute_equal(str);
|
||||
delete [] str;
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string get_variable_string(const std::string & name) {
|
||||
return lmp->input->variable->retrieve(name.c_str());
|
||||
}
|
||||
|
||||
protected:
|
||||
const char *testbinary = "LAMMPSTest";
|
||||
LAMMPS *lmp;
|
||||
Info *info;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args) / sizeof(char *);
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
HIDE_OUTPUT([&] {
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
info = new Info(lmp);
|
||||
});
|
||||
InitSystem();
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
virtual void InitSystem() {}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
delete lmp;
|
||||
lmp = nullptr;
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
HIDE_OUTPUT([&] {
|
||||
delete info;
|
||||
delete lmp;
|
||||
info = nullptr;
|
||||
lmp = nullptr;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -19,23 +19,25 @@ class MeltTest : public LAMMPSTest {
|
||||
protected:
|
||||
virtual void InitSystem() override
|
||||
{
|
||||
command("units lj");
|
||||
command("atom_style atomic");
|
||||
command("atom_modify map yes");
|
||||
HIDE_OUTPUT([&] {
|
||||
command("units lj");
|
||||
command("atom_style atomic");
|
||||
command("atom_modify map yes");
|
||||
|
||||
command("lattice fcc 0.8442");
|
||||
command("region box block 0 2 0 2 0 2");
|
||||
command("create_box 1 box");
|
||||
command("create_atoms 1 box");
|
||||
command("mass 1 1.0");
|
||||
command("lattice fcc 0.8442");
|
||||
command("region box block 0 2 0 2 0 2");
|
||||
command("create_box 1 box");
|
||||
command("create_atoms 1 box");
|
||||
command("mass 1 1.0");
|
||||
|
||||
command("velocity all create 3.0 87287");
|
||||
command("velocity all create 3.0 87287");
|
||||
|
||||
command("pair_style lj/cut 2.5");
|
||||
command("pair_coeff 1 1 1.0 1.0 2.5");
|
||||
command("pair_style lj/cut 2.5");
|
||||
command("pair_coeff 1 1 1.0 1.0 2.5");
|
||||
|
||||
command("neighbor 0.3 bin");
|
||||
command("neigh_modify every 20 delay 0 check no");
|
||||
command("neighbor 0.3 bin");
|
||||
command("neigh_modify every 20 delay 0 check no");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user