forked from lijiext/lammps
rather than replicate code, expand format to string and call original function
This commit is contained in:
parent
a0b0681cc8
commit
60c2d8ea5b
|
@ -134,8 +134,11 @@ void utils::logmesg(LAMMPS *lmp, const std::string &mesg)
|
|||
void utils::fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format,
|
||||
fmt::format_args args)
|
||||
{
|
||||
if (lmp->screen) fmt::vprint(lmp->screen, format, args);
|
||||
if (lmp->logfile) fmt::vprint(lmp->logfile, format, args);
|
||||
try {
|
||||
logmesg(lmp, fmt::vformat(format, args));
|
||||
} catch (fmt::format_error &e) {
|
||||
logmesg(lmp, std::string(e.what())+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* define this here, so we won't have to include the headers
|
||||
|
|
|
@ -126,7 +126,7 @@ TEST_F(FileOperationsTest, safe_fread)
|
|||
|
||||
TEST_F(FileOperationsTest, logmesg)
|
||||
{
|
||||
char buf[16];
|
||||
char buf[64];
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("echo none");
|
||||
END_HIDE_OUTPUT();
|
||||
|
@ -135,14 +135,16 @@ TEST_F(FileOperationsTest, logmesg)
|
|||
command("log test_logmesg.log");
|
||||
utils::logmesg(lmp, "two\n");
|
||||
utils::logmesg(lmp, "three={}\n",3);
|
||||
utils::logmesg(lmp, "four {}\n");
|
||||
utils::logmesg(lmp, "five\n",5);
|
||||
command("log none");
|
||||
std::string out = END_CAPTURE_OUTPUT();
|
||||
memset(buf, 0, 16);
|
||||
memset(buf, 0, 64);
|
||||
FILE *fp = fopen("test_logmesg.log", "r");
|
||||
fread(buf, 1, 16, fp);
|
||||
fread(buf, 1, 64, fp);
|
||||
fclose(fp);
|
||||
ASSERT_THAT(out, StrEq("one\ntwo\nthree=3\n"));
|
||||
ASSERT_THAT(buf, StrEq("two\nthree=3\n"));
|
||||
ASSERT_THAT(out, StrEq("one\ntwo\nthree=3\nargument not found\nfive\n"));
|
||||
ASSERT_THAT(buf, StrEq("two\nthree=3\nargument not found\nfive\n"));
|
||||
remove("test_logmesg.log");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue