From bb6ea422b707baddc397fe7a3a91038b1b550cd0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 28 Aug 2022 17:22:26 -0400 Subject: [PATCH] avoid global namespace import in header, more consistency --- unittest/commands/test_compute_global.cpp | 7 ++----- unittest/commands/test_delete_atoms.cpp | 7 ++----- unittest/commands/test_groups.cpp | 4 ++-- unittest/commands/test_kim_commands.cpp | 4 ++-- unittest/commands/test_lattice_region.cpp | 6 ++---- unittest/commands/test_regions.cpp | 6 ++---- unittest/commands/test_reset_ids.cpp | 7 ++----- unittest/commands/test_set_property.cpp | 9 +++------ unittest/commands/test_simple_commands.cpp | 6 ++---- unittest/commands/test_variables.cpp | 8 +++----- unittest/cplusplus/test_advanced_utils.cpp | 6 ++---- unittest/cplusplus/test_error_class.cpp | 7 ++----- unittest/formats/compressed_dump_test_main.cpp | 2 +- unittest/formats/test_dump_atom.cpp | 5 ++++- unittest/formats/test_dump_cfg.cpp | 4 +++- unittest/formats/test_dump_custom.cpp | 5 +++-- unittest/formats/test_dump_local.cpp | 4 +++- unittest/formats/test_dump_netcdf.cpp | 4 +++- unittest/testing/core.h | 12 +++++++----- 19 files changed, 50 insertions(+), 63 deletions(-) diff --git a/unittest/commands/test_compute_global.cpp b/unittest/commands/test_compute_global.cpp index 83acab08d4..95164d4a09 100644 --- a/unittest/commands/test_compute_global.cpp +++ b/unittest/commands/test_compute_global.cpp @@ -26,8 +26,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { #define STRINGIFY(val) XSTR(val) @@ -296,7 +294,6 @@ TEST_F(ComputeGlobalTest, Reduction) EXPECT_DOUBLE_EQ(rep[2], 26); EXPECT_DOUBLE_EQ(rep[3], max[0]); } - } // namespace LAMMPS_NS int main(int argc, char **argv) @@ -304,12 +301,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_delete_atoms.cpp b/unittest/commands/test_delete_atoms.cpp index 20d546e69e..2a7cab4718 100644 --- a/unittest/commands/test_delete_atoms.cpp +++ b/unittest/commands/test_delete_atoms.cpp @@ -31,9 +31,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::MathConst::MY_PI; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { using ::testing::ContainsRegex; using ::testing::ExitedWithCode; @@ -164,12 +161,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index 1918f67cbf..8247675b82 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -316,12 +316,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 2d9c1cd7d4..1bb070ad6c 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -683,12 +683,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index a1ac9bd675..257fe6a596 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -32,8 +32,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { using ::testing::ContainsRegex; using ::testing::ExitedWithCode; @@ -634,12 +632,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_regions.cpp b/unittest/commands/test_regions.cpp index 4c70385918..2ced0c45f5 100644 --- a/unittest/commands/test_regions.cpp +++ b/unittest/commands/test_regions.cpp @@ -30,8 +30,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { using ::testing::ExitedWithCode; using ::testing::StrEq; @@ -279,12 +277,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 3d577ad24d..cd311616aa 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -29,8 +29,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { #define GETIDX(i) lmp->atom->map(i) @@ -677,7 +675,6 @@ TEST_F(ResetMolIDsTest, FailOnlyMolecular) END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", command("reset_mol_ids all");); } - } // namespace LAMMPS_NS int main(int argc, char **argv) @@ -685,12 +682,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_set_property.cpp b/unittest/commands/test_set_property.cpp index 7803c99d5f..0bd58cb53b 100644 --- a/unittest/commands/test_set_property.cpp +++ b/unittest/commands/test_set_property.cpp @@ -25,14 +25,11 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::MathConst::MY_PI; -using LAMMPS_NS::utils::split_words; - -namespace LAMMPS_NS { using ::testing::ContainsRegex; using ::testing::ExitedWithCode; using ::testing::StrEq; +namespace LAMMPS_NS { class SetTest : public LAMMPSTest { protected: Atom *atom; @@ -172,12 +169,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index ccec6321b3..5889f09eb0 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -36,8 +36,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { using ::testing::ContainsRegex; using ::testing::ExitedWithCode; @@ -552,12 +550,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index bf3f0cc5e9..848331abe2 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -32,13 +32,11 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -using LAMMPS_NS::MathConst::MY_PI; -using LAMMPS_NS::utils::split_words; - namespace LAMMPS_NS { using ::testing::ContainsRegex; using ::testing::ExitedWithCode; using ::testing::StrEq; +using MathConst::MY_PI; class VariableTest : public LAMMPSTest { protected: @@ -585,12 +583,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/cplusplus/test_advanced_utils.cpp b/unittest/cplusplus/test_advanced_utils.cpp index 63c029c068..6b71c9ea34 100644 --- a/unittest/cplusplus/test_advanced_utils.cpp +++ b/unittest/cplusplus/test_advanced_utils.cpp @@ -16,7 +16,6 @@ bool verbose = false; namespace LAMMPS_NS { - class Advanced_utils : public LAMMPSTest { protected: Error *error; @@ -218,7 +217,6 @@ TEST_F(Advanced_utils, expand_args) delete[] args[i]; delete[] args; } - } // namespace LAMMPS_NS int main(int argc, char **argv) @@ -226,12 +224,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/cplusplus/test_error_class.cpp b/unittest/cplusplus/test_error_class.cpp index ba3187cd61..779cbfbba6 100644 --- a/unittest/cplusplus/test_error_class.cpp +++ b/unittest/cplusplus/test_error_class.cpp @@ -16,9 +16,7 @@ bool verbose = false; namespace LAMMPS_NS { - using ::testing::ContainsRegex; -using utils::split_words; class Error_class : public LAMMPSTest { protected: @@ -120,7 +118,6 @@ TEST_F(Error_class, all) { TEST_FAILURE("ERROR: one error.*test_error_class.cpp:.*", error->all(FLERR, "one error");); }; - } // namespace LAMMPS_NS int main(int argc, char **argv) @@ -128,12 +125,12 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) + if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/formats/compressed_dump_test_main.cpp b/unittest/formats/compressed_dump_test_main.cpp index c96682d8b7..5f775a8843 100644 --- a/unittest/formats/compressed_dump_test_main.cpp +++ b/unittest/formats/compressed_dump_test_main.cpp @@ -50,7 +50,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 762a01e648..12dd8bee8a 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -28,6 +28,8 @@ using ::testing::Eq; char *BINARY2TXT_EXECUTABLE = nullptr; bool verbose = false; +namespace LAMMPS_NS { + class DumpAtomTest : public MeltTest { std::string dump_style = "atom"; @@ -678,6 +680,7 @@ TEST_F(DumpAtomTest, binary_write_dump) delete_file(reference); delete_file(dump_file); } +} int main(int argc, char **argv) { @@ -686,7 +689,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index e51da8331a..acd839282d 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -23,6 +23,7 @@ using ::testing::Eq; bool verbose = false; +namespace LAMMPS_NS { class DumpCfgTest : public MeltTest { std::string dump_style = "cfg"; @@ -143,6 +144,7 @@ TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0) ASSERT_THAT(lines[0], Eq("Number of particles = 32")); delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg"); } +} int main(int argc, char **argv) { @@ -151,7 +153,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index 72b4adcc87..d1bae9d28f 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -26,6 +26,7 @@ using ::testing::Eq; char *BINARY2TXT_EXECUTABLE = nullptr; bool verbose = false; +namespace LAMMPS_NS { class DumpCustomTest : public MeltTest { std::string dump_style = "custom"; @@ -383,7 +384,7 @@ TEST_F(DumpCustomTest, rerun_bin) ASSERT_NEAR(pe_2, pe_rerun, 1.0e-14); delete_file(dump_file); } - +} int main(int argc, char **argv) { MPI_Init(&argc, &argv); @@ -391,7 +392,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/formats/test_dump_local.cpp b/unittest/formats/test_dump_local.cpp index ead071743c..5735f4dc7c 100644 --- a/unittest/formats/test_dump_local.cpp +++ b/unittest/formats/test_dump_local.cpp @@ -28,6 +28,7 @@ using ::testing::Eq; char *BINARY2TXT_EXECUTABLE = nullptr; bool verbose = false; +namespace LAMMPS_NS { class DumpLocalTest : public MeltTest { std::string dump_style = "local"; @@ -237,6 +238,7 @@ TEST_F(DumpLocalTest, triclinic_run0) ASSERT_EQ(utils::split_words(lines[7]).size(), 3); delete_file(dump_file); } +} int main(int argc, char **argv) { @@ -245,7 +247,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/formats/test_dump_netcdf.cpp b/unittest/formats/test_dump_netcdf.cpp index 6d377369ee..0b016d0efb 100644 --- a/unittest/formats/test_dump_netcdf.cpp +++ b/unittest/formats/test_dump_netcdf.cpp @@ -31,6 +31,7 @@ using ::testing::Eq; char *NCDUMP_EXECUTABLE = nullptr; bool verbose = false; +namespace LAMMPS_NS { class DumpNetCDFTest : public MeltTest { std::string dump_style = "netcdf"; @@ -386,6 +387,7 @@ TEST_F(DumpNetCDFTest, run0_mpi) } delete_file(dump_file); } +} int main(int argc, char **argv) { @@ -394,7 +396,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); + std::vector env = LAMMPS_NS::utils::split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 81a7112934..5b2aba6fd3 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -26,7 +26,9 @@ #include #include -using namespace LAMMPS_NS; +using LAMMPS_NS::Info; +using LAMMPS_NS::LAMMPS; +using LAMMPS_NS::LAMMPSException; using ::testing::ContainsRegex; @@ -37,7 +39,7 @@ using ::testing::ContainsRegex; auto mesg = ::testing::internal::GetCapturedStdout(); \ ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ } else { \ - if (platform::mpi_vendor() != "Open MPI") { \ + if (LAMMPS_NS::platform::mpi_vendor() != "Open MPI") { \ ::testing::internal::CaptureStdout(); \ ASSERT_DEATH({__VA_ARGS__}, ""); \ auto mesg = ::testing::internal::GetCapturedStdout(); \ @@ -101,7 +103,7 @@ public: double get_variable_value(const std::string &name) { - char *str = utils::strdup(fmt::format("v_{}", name)); + char *str = LAMMPS_NS::utils::strdup(fmt::format("v_{}", name)); double value = lmp->input->variable->compute_equal(str); delete[] str; return value; @@ -122,9 +124,9 @@ protected: { int argc = args.size() + 1; char **argv = new char *[argc]; - argv[0] = utils::strdup(testbinary); + argv[0] = LAMMPS_NS::utils::strdup(testbinary); for (int i = 1; i < argc; i++) { - argv[i] = utils::strdup(args[i - 1]); + argv[i] = LAMMPS_NS::utils::strdup(args[i - 1]); } HIDE_OUTPUT([&] {