build: add option for running tests

cmake configuration for running tests is now in the
tests folder.

Add option in main cmake file that has to be set to
ON and only build the tests in that case.

Update appveyor and travis ci configurations accordingly.
This commit is contained in:
Petra Baranski
2023-07-23 06:04:29 +02:00
parent 6dd47f5de5
commit 87ec259c28
7 changed files with 44 additions and 34 deletions

View File

@@ -27,6 +27,6 @@ before_install:
script: script:
- mkdir tmp - mkdir tmp
- cd tmp - cd tmp
- cmake .. - cmake -DMADDY_ENABLED_TESTS=ON ..
- make -j4 - make -j4
- ../build/MaddyTests - ../build/MaddyTests

View File

@@ -18,6 +18,7 @@ maddy uses [semver versioning](https://semver.org/).
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) updated cmake minimum required version to 3.25 * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) updated cmake minimum required version to 3.25
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) gtest is now loaded via cmake and not a git submodule any longer - updated gtest version to 1.13.0 * ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) gtest is now loaded via cmake and not a git submodule any longer - updated gtest version to 1.13.0
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_ENABLED_TESTS` is on, moved test cmake code to the `tests` subfolder
* ? * ?
## version 1.1.2 2020-10-04 ## version 1.1.2 2020-10-04

View File

@@ -5,8 +5,6 @@ cmake_minimum_required(VERSION 3.25)
project(maddy) project(maddy)
enable_testing()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
set(MADDY_CPP_VERSION 14) set(MADDY_CPP_VERSION 14)
@@ -20,8 +18,15 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
option(MADDY_ENABLED_TESTS "enable building tests" OFF)
if(${MADDY_ENABLED_TESTS})
enable_testing()
endif()
# ------------------------------------------------------------------------------
set(MADDY_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) set(MADDY_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/maddy/*.cpp)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@@ -54,10 +59,6 @@ endif()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
add_subdirectory(libs)
# ------------------------------------------------------------------------------
add_library(maddy INTERFACE) add_library(maddy INTERFACE)
target_include_directories(maddy INTERFACE target_include_directories(maddy INTERFACE
${MADDY_INCLUDE_DIR} ${MADDY_INCLUDE_DIR}
@@ -65,14 +66,6 @@ target_include_directories(maddy INTERFACE
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
add_executable( if(${MADDY_ENABLED_TESTS})
MaddyTests add_subdirectory(tests)
${MADDY_TESTS_FILES} endif()
${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
)
target_include_directories(MaddyTests PUBLIC
${LIBS_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_link_libraries(MaddyTests maddy gmock_main)
add_test(MaddyTests ${CMAKE_CURRENT_SOURCE_DIR}/build/MaddyTests)

View File

@@ -15,7 +15,7 @@ It is tested to work on:
* Linux (gcc) * Linux (gcc)
* OSX (clang) * OSX (clang)
* Windows (Visual Studio 2017) * Windows (Visual Studio 2017, mingw)
## Dependencies ## Dependencies
@@ -63,10 +63,9 @@ Open your preferred terminal and type:
```shell ```shell
git clone https://github.com/progsource/maddy.git git clone https://github.com/progsource/maddy.git
cd maddy cd maddy
git submodule update --init --recursive
mkdir tmp mkdir tmp
cd tmp cd tmp
cmake .. cmake -DMADDY_ENABLED_TESTS=ON ..
make make
make test # or run the executable in ../build/MaddyTests make test # or run the executable in ../build/MaddyTests
``` ```

View File

@@ -6,7 +6,7 @@ install:
before_build: before_build:
- cmd: mkdir tmp - cmd: mkdir tmp
- cmd: cd tmp - cmd: cd tmp
- cmd: cmake -G "Visual Studio 15 Win64" .. - cmd: cmake -G "Visual Studio 15 Win64" -DMADDY_ENABLED_TESTS=ON ..
build: build:
project: $(APPVEYOR_BUILD_FOLDER)\tmp\$(APPVEYOR_PROJECT_NAME).sln project: $(APPVEYOR_BUILD_FOLDER)\tmp\$(APPVEYOR_PROJECT_NAME).sln

View File

@@ -1,11 +0,0 @@
# This project is licensed under the MIT license. For more information see the
# LICENSE file.
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG b796f7d44681514f58a683a3a71ff17c94edb0c1 # v1.13.0
)
FetchContent_MakeAvailable(googletest)

28
tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
# This project is licensed under the MIT license. For more information see the
# LICENSE file.
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG b796f7d44681514f58a683a3a71ff17c94edb0c1 # v1.13.0
)
FetchContent_MakeAvailable(googletest)
# ------------------------------------------------------------------------------
file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/maddy/*.cpp)
# ------------------------------------------------------------------------------
add_executable(
MaddyTests
${MADDY_TESTS_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)
target_include_directories(MaddyTests PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(MaddyTests maddy gmock_main)
add_test(MaddyTests MaddyTests)