Skip to content

Commit

Permalink
Add CMakeLists file for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yiquintero committed Nov 22, 2023
1 parent 8558408 commit 602f079
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
83 changes: 83 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.14)

# Suppress warning msgs
cmake_policy(SET CMP0135 NEW)

project(octptests)

# TRUE if tests are run as part of GitHub Actions workflow, FALSE otherwise
set (TEST_IN_GITHUB_ACTIONS FALSE)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

# Fetch and download Google Test
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/b796f7d44681514f58a683a3a71ff17c94edb0c1.zip
)
# Windows: Prevent overriding the parent project's compiler/linker settings
# Currently no parent CMake project, but good to keep for the future
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

#Enable testing in CMake
enable_testing()

# Create an executable for the tests
add_executable(
testoctp
testoctp.cpp
)

# link the googletest library to the tests
target_link_libraries(
testoctp
GTest::gtest_main
)

# Enable CMake’s test runner to discover the tests included in the binary,
# using the GoogleTest CMake module.
include(GoogleTest)
gtest_discover_tests(testoctp)


if (TEST_IN_GITHUB_ACTIONS)
# lammps was previously downloaded and built as part of the workflow
set (LAMMPS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../../lammps/src/")
else()
message(STATUS "Downloading LAMMPS")
# download lammps
FetchContent_Declare(
lammps
URL https://github.com/lammps/lammps/archive/refs/tags/stable_23Jun2022_update4.zip
)
FetchContent_Populate(lammps)
set (LAMMPS_SOURCE_DIR "${lammps_SOURCE_DIR}/src/")
# copy octp files to lammps dir
file(GLOB filesToCopy "${CMAKE_SOURCE_DIR}/../src/*")
file(COPY ${filesToCopy} DESTINATION ${LAMMPS_SOURCE_DIR})
# build lammps+octp as a post-build event of the testoctp
add_custom_command(
TARGET testoctp POST_BUILD
COMMAND cd ${LAMMPS_SOURCE_DIR} &&
make yes-asphere &&
make yes-body &&
make yes-class2 &&
make yes-dipole &&
make yes-granular &&
make yes-kspace &&
make yes-manybody &&
make yes-molecule &&
make yes-rigid &&
make yes-shock &&
make -j 8 mpi
WORKING_DIRECTORY ${lammps_SOURCE_DIR}
VERBATIM
COMMENT "Build LAMMPS with OCTP plugin"
)
endif()

7 changes: 7 additions & 0 deletions tests/testoctp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gtest/gtest.h>

class OctpTest : public testing::Test {};

TEST_F(OctpTest, DummyTest) {
EXPECT_TRUE(true);
}

0 comments on commit 602f079

Please sign in to comment.