Skip to content

Commit

Permalink
Add test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
yiquintero committed Nov 22, 2023
1 parent 602f079 commit b55184e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
32 changes: 20 additions & 12 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ FetchContent_Declare(
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# Get LAMMPS
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/")
endif()


#Enable testing in CMake
enable_testing()

Expand All @@ -33,6 +49,9 @@ add_executable(
testoctp.cpp
)

# Add a preprocessor definition with the path to LAMMPS
add_compile_definitions(LAMMPS_PATH=${LAMMPS_SOURCE_DIR})

# link the googletest library to the tests
target_link_libraries(
testoctp
Expand All @@ -45,18 +64,7 @@ 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/")
if (NOT TEST_IN_GITHUB_ACTIONS)
# copy octp files to lammps dir
file(GLOB filesToCopy "${CMAKE_SOURCE_DIR}/../src/*")
file(COPY ${filesToCopy} DESTINATION ${LAMMPS_SOURCE_DIR})
Expand Down
30 changes: 29 additions & 1 deletion tests/testoctp.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
#include <gtest/gtest.h>
#include <iostream>

#define XSTR(x) STR(x)
#define STR(x) #x

class OctpTest : public testing::Test
{
public:
OctpTest() {}
};

class TestEnvironment : public ::testing::Environment {
public:
virtual void SetUp() {
std::cout << XSTR(LAMMPS_PATH) << std::endl;
}
};

class OctpTest : public testing::Test {};

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

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


int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
// gtest takes ownership of the TestEnvironment ptr - we don't delete it.
::testing::AddGlobalTestEnvironment(new TestEnvironment);
return RUN_ALL_TESTS();
}

0 comments on commit b55184e

Please sign in to comment.