Skip to content

Commit

Permalink
[build] introduce catch2, update cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy-Kid committed Jun 14, 2024
1 parent 8b04eb7 commit 5866ee0
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 13 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include(cmake/variables.cmake)
add_library(
molcore_molcore
source/molcore.cpp
source/space.cpp
)
add_library(molcore::molcore ALIAS molcore_molcore)

Expand Down
39 changes: 39 additions & 0 deletions include/molcore/space.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


namespace molcore {

class Region {

public:

virtual bool isin(const double x, const double y, const double z) const = 0;

virtual ~Region() = default;

private:


};

class Boundary {

public:

virtual ~Boundary() = default;

private:

};

class Box : public Region, public Boundary {

public:

Box();

auto isin(const double x, const double y, const double z) const -> bool override;

private:

};
} // namespace molcore
12 changes: 12 additions & 0 deletions source/space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "molcore/space.hpp"

namespace molcore
{

Box::Box() {}

bool Box::isin(const double x, const double y, const double z) const
{
return true;
}
} // namespace molcore
16 changes: 13 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ include(../cmake/project-is-top-level.cmake)
include(../cmake/folders.cmake)

# ---- Dependencies ----

if(PROJECT_IS_TOP_LEVEL)
find_package(molcore REQUIRED)
enable_testing()
elseif()

endif()

find_package(Catch2 3 REQUIRED)
# ---- Tests ----

add_executable(molcore_test source/molcore_test.cpp)
# TODO: auto find tests starts with "test_"
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS "source/*.cpp")
message(STATUS "find test sources: ${TEST_SOURCES}")

add_executable(molcore_test ${TEST_SOURCES})
target_link_libraries(molcore_test PRIVATE molcore::molcore)
target_link_libraries(molcore_test PRIVATE Catch2::Catch2WithMain)
target_compile_features(molcore_test PRIVATE cxx_std_20)

add_test(NAME molcore_test COMMAND molcore_test)
include(Catch)
catch_discover_tests(molcore_test)

# add_test(NAME molcore_test COMMAND molcore_test)

# ---- End-of-file commands ----

Expand Down
10 changes: 0 additions & 10 deletions test/source/molcore_test.cpp

This file was deleted.

12 changes: 12 additions & 0 deletions test/source/test_export.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <string>

#include <catch2/catch_test_macros.hpp>

#include "molcore/molcore.hpp"

TEST_CASE("Exported Class", "[exported]")
{
auto const exported = exported_class {};

CHECK(std::string("molcore") == exported.name());
}
14 changes: 14 additions & 0 deletions test/source/test_space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <catch2/catch_test_macros.hpp>

#include "molcore/space.hpp"

namespace molcore
{

TEST_CASE("Test Space", "[Box]")
{
auto box = Box();
CHECK(box.isin(1, 2, 3));
}

} // namespace molcore

0 comments on commit 5866ee0

Please sign in to comment.