From 5866ee0ad907dfd7a44b0fdf5e7495bd3836adf1 Mon Sep 17 00:00:00 2001 From: Roy Kid Date: Fri, 14 Jun 2024 12:16:59 +0200 Subject: [PATCH] [build] introduce catch2, update cmake --- CMakeLists.txt | 1 + include/molcore/space.hpp | 39 ++++++++++++++++++++++++++++++++++++ source/space.cpp | 12 +++++++++++ test/CMakeLists.txt | 16 ++++++++++++--- test/source/molcore_test.cpp | 10 --------- test/source/test_export.cpp | 12 +++++++++++ test/source/test_space.cpp | 14 +++++++++++++ 7 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 include/molcore/space.hpp create mode 100644 source/space.cpp delete mode 100644 test/source/molcore_test.cpp create mode 100644 test/source/test_export.cpp create mode 100644 test/source/test_space.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 427dd9f..bdb608d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/molcore/space.hpp b/include/molcore/space.hpp new file mode 100644 index 0000000..dae0996 --- /dev/null +++ b/include/molcore/space.hpp @@ -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 \ No newline at end of file diff --git a/source/space.cpp b/source/space.cpp new file mode 100644 index 0000000..2614cff --- /dev/null +++ b/source/space.cpp @@ -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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 668d690..970a134 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 ---- diff --git a/test/source/molcore_test.cpp b/test/source/molcore_test.cpp deleted file mode 100644 index 9f57cc9..0000000 --- a/test/source/molcore_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#include "molcore/molcore.hpp" - -auto main() -> int -{ - auto const exported = exported_class {}; - - return std::string("molcore") == exported.name() ? 0 : 1; -} diff --git a/test/source/test_export.cpp b/test/source/test_export.cpp new file mode 100644 index 0000000..4a08a73 --- /dev/null +++ b/test/source/test_export.cpp @@ -0,0 +1,12 @@ +#include + +#include + +#include "molcore/molcore.hpp" + +TEST_CASE("Exported Class", "[exported]") +{ + auto const exported = exported_class {}; + + CHECK(std::string("molcore") == exported.name()); +} diff --git a/test/source/test_space.cpp b/test/source/test_space.cpp new file mode 100644 index 0000000..3a78963 --- /dev/null +++ b/test/source/test_space.cpp @@ -0,0 +1,14 @@ +#include + +#include "molcore/space.hpp" + +namespace molcore +{ + +TEST_CASE("Test Space", "[Box]") +{ + auto box = Box(); + CHECK(box.isin(1, 2, 3)); +} + +} // namespace molcore \ No newline at end of file