From 6ad03498c324e4852eac6b488426e65ec62998e5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 21 Oct 2021 19:22:01 -0400 Subject: [PATCH] make finding plugins for testing multi-config compatible --- unittest/commands/CMakeLists.txt | 14 ++------------ unittest/commands/test_simple_commands.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 10c113d781..6116bf8422 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -10,18 +10,8 @@ endif() target_link_libraries(test_simple_commands PRIVATE lammps gmock) add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -if(BUILD_IS_MULTI_CONFIG) - set(LAMMPS_PLUGIN_BIN_DIR ${CMAKE_BINARY_DIR}/build-plugins/$) -else() - set(LAMMPS_PLUGIN_BIN_DIR ${CMAKE_BINARY_DIR}/build-plugins) -endif() -if(APPLE) - set_tests_properties(SimpleCommands PROPERTIES - ENVIRONMENT "DYLD_LIBRARY_PATH=${LAMMPS_PLUGIN_BIN_DIR}/:${DYLD_LIBRARY_PATH}") -else() - set_tests_properties(SimpleCommands PROPERTIES - ENVIRONMENT "LD_LIBRARY_PATH=${LAMMPS_PLUGIN_BIN_DIR}/:${LD_LIBRARY_PATH}") -endif() +set_tests_properties(SimpleCommands PROPERTIES + ENVIRONMENT "LAMMPS_PLUGIN_BIN_DIR=${CMAKE_BINARY_DIR}/build-plugins") add_executable(test_lattice_region test_lattice_region.cpp) target_link_libraries(test_lattice_region PRIVATE lammps gmock) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 0ad47f4e96..4d68b54c21 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -384,7 +384,12 @@ TEST_F(SimpleCommandsTest, Units) #if defined(LMP_PLUGIN) TEST_F(SimpleCommandsTest, Plugin) { - std::string loadfmt("plugin load {}plugin.so"); + const char *bindir = getenv("LAMMPS_PLUGIN_BIN_DIR"); + const char *config = getenv("CMAKE_CONFIG_TYPE"); + if (!bindir) GTEST_SKIP(); + std::string loadfmt = platform::path_join("plugin load ", bindir); + if (config) loadfmt = platform::path_join(loadfmt, config); + loadfmt = platform::path_join(loadfmt, "{}plugin.so"); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "hello")); auto text = ::testing::internal::GetCapturedStdout(); @@ -395,7 +400,7 @@ TEST_F(SimpleCommandsTest, Plugin) lmp->input->one(fmt::format(loadfmt, "xxx")); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Open of file xxx.* failed.*")); + ASSERT_THAT(text, MatchesRegex(".*Open of file .*xxx.* failed.*")); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "nve2"));