From 98013a1528ab55d9209eff6de4d604574d7bd57e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 15:32:50 -0500 Subject: [PATCH] add draft version of unit test (will have to be improved for MacOS) --- unittest/commands/CMakeLists.txt | 19 +++++++++++++++++++ unittest/commands/test_simple_commands.cpp | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 7a804820cb..0fb0c8088e 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -1,5 +1,24 @@ +# build LAMMPS plugins, but not on Windows +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + ExternalProject_Add(plugins + SOURCE_DIR "${LAMMPS_DIR}/examples/plugins" + BINARY_DIR "${CMAKE_BINARY_DIR}/plugins" + CMAKE_ARGS ${CMAKE_REQUEST_PIC} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + BUILD_BYPRODUCTS /morse2plugin${CMAKE_STATIC_LIBRARY_SUFFIX} + /nve2plugin${CMAKE_STATIC_LIBRARY_SUFFIX} + /helloplugin${CMAKE_STATIC_LIBRARY_SUFFIX} + INSTALL_COMMAND "" + TEST_COMMAND "") +endif() + add_executable(test_simple_commands test_simple_commands.cpp) +add_dependencies(test_simple_commands plugins) target_link_libraries(test_simple_commands PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 4fce58c668..09f81b8f71 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -344,6 +344,15 @@ TEST_F(SimpleCommandsTest, Units) TEST_FAILURE(".*ERROR: Illegal units command.*", lmp->input->one("units unknown");); } +TEST_F(SimpleCommandsTest, Plugin) +{ + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin load plugins/helloplugin.so"); + auto text = ::testing::internal::GetCapturedStdout(); + + ASSERT_THAT(text, MatchesRegex(".*Loading plugin: Hello world command.*")); +} + TEST_F(SimpleCommandsTest, Shell) { if (!verbose) ::testing::internal::CaptureStdout();