added tests

This commit is contained in:
Erik Frojdh 2024-03-07 14:46:56 +01:00
parent 5690a61284
commit 44d6ff6d2e
6 changed files with 55 additions and 3 deletions

View File

@ -15,12 +15,24 @@ include(GNUInstallDirs)
include(FetchContent)
option(USE_SANITIZER "Sanitizers for debugging" ON)
option(DISABLE_WARNINGS "Disbale compilation warnings" OFF)
option(USE_PYTHON "Build python bindings" ON)
option(AARE_BUILD_TESTS "Build tests" OFF)
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(json)
if(AARE_BUILD_TESTS)
add_subdirectory(tests)
endif()
find_package(fmt 6 REQUIRED)
@ -33,9 +45,7 @@ else()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(USE_SANITIZER "Sanitizers for debugging" ON)
option(DISABLE_WARNINGS "Disbale compilation warnings" OFF)
option(USE_PYTHON "Build python bindings" ON)
set(OPTIONAL_FLAGS "")
@ -71,6 +81,7 @@ target_link_libraries(aare INTERFACE common core file_io)
add_subdirectory(examples)
target_link_libraries(example PUBLIC aare)
if(USE_PYTHON)
find_package (Python 3.11 COMPONENTS Interpreter Development)
find_package(pybind11 2.11 REQUIRED)

View File

@ -4,6 +4,7 @@
#include <vector>
#include <sys/types.h>
#include <string_view>
#include <string>
#include <stdexcept>
#include <fmt/format.h>
#include <variant>

View File

@ -3,3 +3,14 @@ add_library(common "${CMAKE_CURRENT_SOURCE_DIR}/defs.cpp")
target_link_libraries(common PUBLIC fmt::fmt)
if(AARE_BUILD_TESTS)
set(TestSources
${CMAKE_CURRENT_SOURCE_DIR}/defs.test.cpp
)
target_sources(tests PRIVATE ${TestSources} )
#Work around to remove, this is not the way to do it =)
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common)
target_link_libraries(tests PRIVATE common)
endif()

8
src/common/defs.test.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <catch2/catch_test_macros.hpp>
#include <string>
#include "defs.hpp"
TEST_CASE("Enum to string conversion"){
//By the way I don't think the enum string conversions should be in the defs.hpp file
//but let's use this to show a test
REQUIRE(toString(DetectorType::Jungfrau) == "Jungfrau");
}

20
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
FetchContent_Declare(
Catch2
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.3
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
set_target_properties(tests PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_NAME run_tests
)
include(CTest)
include(Catch)
catch_discover_tests(tests)

1
tests/test.cpp Normal file
View File

@ -0,0 +1 @@
//Empty file to satisfy CMake when no other tests are added