make compatible with more strict consteval format requirements of C++20
This commit is contained in:
@ -415,19 +415,19 @@ TEST_F(SimpleCommandsTest, Plugin)
|
|||||||
if (!bindir) GTEST_SKIP() << "LAMMPS_PLUGIN_DIR not set";
|
if (!bindir) GTEST_SKIP() << "LAMMPS_PLUGIN_DIR not set";
|
||||||
std::string loadfmt = "plugin load {}/{}plugin.so";
|
std::string loadfmt = "plugin load {}/{}plugin.so";
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lmp->input->one(fmt::format(loadfmt, bindir, "hello"));
|
lmp->input->one(fmt::format(fmt::runtime(loadfmt), bindir, "hello"));
|
||||||
auto text = ::testing::internal::GetCapturedStdout();
|
auto text = ::testing::internal::GetCapturedStdout();
|
||||||
if (verbose) std::cout << text;
|
if (verbose) std::cout << text;
|
||||||
ASSERT_THAT(text, ContainsRegex(".*\n.*Loading plugin: Hello world command.*"));
|
ASSERT_THAT(text, ContainsRegex(".*\n.*Loading plugin: Hello world command.*"));
|
||||||
|
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lmp->input->one(fmt::format(loadfmt, bindir, "xxx"));
|
lmp->input->one(fmt::format(fmt::runtime(loadfmt), bindir, "xxx"));
|
||||||
text = ::testing::internal::GetCapturedStdout();
|
text = ::testing::internal::GetCapturedStdout();
|
||||||
if (verbose) std::cout << text;
|
if (verbose) std::cout << text;
|
||||||
ASSERT_THAT(text, ContainsRegex(".*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, bindir, "nve2"));
|
lmp->input->one(fmt::format(fmt::runtime(loadfmt), bindir, "nve2"));
|
||||||
text = ::testing::internal::GetCapturedStdout();
|
text = ::testing::internal::GetCapturedStdout();
|
||||||
if (verbose) std::cout << text;
|
if (verbose) std::cout << text;
|
||||||
ASSERT_THAT(text, ContainsRegex(".*Loading plugin: NVE2 variant fix style.*"));
|
ASSERT_THAT(text, ContainsRegex(".*Loading plugin: NVE2 variant fix style.*"));
|
||||||
@ -438,7 +438,7 @@ TEST_F(SimpleCommandsTest, Plugin)
|
|||||||
ASSERT_THAT(text, ContainsRegex(".*1: command style plugin hello\n.*2: fix style plugin nve2.*"));
|
ASSERT_THAT(text, ContainsRegex(".*1: command style plugin hello\n.*2: fix style plugin nve2.*"));
|
||||||
|
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lmp->input->one(fmt::format(loadfmt, bindir, "hello"));
|
lmp->input->one(fmt::format(fmt::runtime(loadfmt), bindir, "hello"));
|
||||||
text = ::testing::internal::GetCapturedStdout();
|
text = ::testing::internal::GetCapturedStdout();
|
||||||
if (verbose) std::cout << text;
|
if (verbose) std::cout << text;
|
||||||
ASSERT_THAT(text, ContainsRegex(".*Ignoring load of command style hello: "
|
ASSERT_THAT(text, ContainsRegex(".*Ignoring load of command style hello: "
|
||||||
|
|||||||
@ -24,21 +24,21 @@ using ::testing::Eq;
|
|||||||
|
|
||||||
TEST(FmtLib, insert_string)
|
TEST(FmtLib, insert_string)
|
||||||
{
|
{
|
||||||
const char val[] = "word";
|
constexpr char val[] = "word";
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word word"));
|
ASSERT_THAT(text, Eq("word word"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FmtLib, insert_int)
|
TEST(FmtLib, insert_int)
|
||||||
{
|
{
|
||||||
const int val = 333;
|
constexpr int val = 333;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word 333"));
|
ASSERT_THAT(text, Eq("word 333"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FmtLib, insert_neg_int)
|
TEST(FmtLib, insert_neg_int)
|
||||||
{
|
{
|
||||||
const int val = -333;
|
constexpr int val = -333;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word -333"));
|
ASSERT_THAT(text, Eq("word -333"));
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ TEST(FmtLib, insert_neg_int)
|
|||||||
TEST(FmtLib, insert_bigint)
|
TEST(FmtLib, insert_bigint)
|
||||||
{
|
{
|
||||||
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
|
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
|
||||||
const bigint val = 9945234592L;
|
constexpr bigint val = 9945234592L;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word 9945234592"));
|
ASSERT_THAT(text, Eq("word 9945234592"));
|
||||||
#else
|
#else
|
||||||
@ -57,7 +57,7 @@ TEST(FmtLib, insert_bigint)
|
|||||||
TEST(FmtLib, insert_neg_bigint)
|
TEST(FmtLib, insert_neg_bigint)
|
||||||
{
|
{
|
||||||
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
|
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
|
||||||
const bigint val = -9945234592L;
|
constexpr bigint val = -9945234592L;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word -9945234592"));
|
ASSERT_THAT(text, Eq("word -9945234592"));
|
||||||
#else
|
#else
|
||||||
@ -68,7 +68,7 @@ TEST(FmtLib, insert_neg_bigint)
|
|||||||
TEST(FmtLib, insert_tagint)
|
TEST(FmtLib, insert_tagint)
|
||||||
{
|
{
|
||||||
#if defined(LAMMPS_BIGBIG)
|
#if defined(LAMMPS_BIGBIG)
|
||||||
const tagint val = 9945234592L;
|
constexpr tagint val = 9945234592L;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word 9945234592"));
|
ASSERT_THAT(text, Eq("word 9945234592"));
|
||||||
#else
|
#else
|
||||||
@ -79,7 +79,7 @@ TEST(FmtLib, insert_tagint)
|
|||||||
TEST(FmtLib, insert_neg_tagint)
|
TEST(FmtLib, insert_neg_tagint)
|
||||||
{
|
{
|
||||||
#if defined(LAMMPS_BIGBIG)
|
#if defined(LAMMPS_BIGBIG)
|
||||||
const tagint val = -9945234592L;
|
constexpr tagint val = -9945234592L;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word -9945234592"));
|
ASSERT_THAT(text, Eq("word -9945234592"));
|
||||||
#else
|
#else
|
||||||
@ -90,7 +90,7 @@ TEST(FmtLib, insert_neg_tagint)
|
|||||||
TEST(FmtLib, insert_imageint)
|
TEST(FmtLib, insert_imageint)
|
||||||
{
|
{
|
||||||
#if defined(LAMMPS_BIGBIG)
|
#if defined(LAMMPS_BIGBIG)
|
||||||
const imageint val = 9945234592L;
|
constexpr imageint val = 9945234592L;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word 9945234592"));
|
ASSERT_THAT(text, Eq("word 9945234592"));
|
||||||
#else
|
#else
|
||||||
@ -101,7 +101,7 @@ TEST(FmtLib, insert_imageint)
|
|||||||
TEST(FmtLib, insert_neg_imageint)
|
TEST(FmtLib, insert_neg_imageint)
|
||||||
{
|
{
|
||||||
#if defined(LAMMPS_BIGBIG)
|
#if defined(LAMMPS_BIGBIG)
|
||||||
const imageint val = -9945234592L;
|
constexpr imageint val = -9945234592L;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word -9945234592"));
|
ASSERT_THAT(text, Eq("word -9945234592"));
|
||||||
#else
|
#else
|
||||||
@ -111,14 +111,14 @@ TEST(FmtLib, insert_neg_imageint)
|
|||||||
|
|
||||||
TEST(FmtLib, insert_double)
|
TEST(FmtLib, insert_double)
|
||||||
{
|
{
|
||||||
const double val = 1.5;
|
constexpr double val = 1.5;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word 1.5"));
|
ASSERT_THAT(text, Eq("word 1.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FmtLib, insert_neg_double)
|
TEST(FmtLib, insert_neg_double)
|
||||||
{
|
{
|
||||||
const double val = -1.5;
|
constexpr double val = -1.5;
|
||||||
auto text = fmt::format("word {}", val);
|
auto text = fmt::format("word {}", val);
|
||||||
ASSERT_THAT(text, Eq("word -1.5"));
|
ASSERT_THAT(text, Eq("word -1.5"));
|
||||||
}
|
}
|
||||||
@ -126,11 +126,23 @@ TEST(FmtLib, insert_neg_double)
|
|||||||
TEST(FmtLib, int_for_double)
|
TEST(FmtLib, int_for_double)
|
||||||
{
|
{
|
||||||
const double val = -1.5;
|
const double val = -1.5;
|
||||||
ASSERT_THROW(auto text = fmt::format("word {:d}", val), std::exception);
|
ASSERT_THROW(auto text = fmt::format(fmt::runtime("word {:d}"), val), std::exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FmtLib, double_for_int)
|
TEST(FmtLib, double_for_int)
|
||||||
{
|
{
|
||||||
const int val = 15;
|
const int val = 15;
|
||||||
ASSERT_THROW(auto text = fmt::format("word {:g}", val), std::exception);
|
ASSERT_THROW(auto text = fmt::format(fmt::runtime("word {:g}"), val), std::exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(FmtLib, double_for_string)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(auto text = fmt::format(fmt::runtime("word {:g}"), "I am not a number"),
|
||||||
|
std::exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(FmtLib, int_for_string)
|
||||||
|
{
|
||||||
|
ASSERT_THROW(auto text = fmt::format(fmt::runtime("word {:d}"), "I am not a number"),
|
||||||
|
std::exception);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user