Skip to content

Commit

Permalink
Merge pull request #21 from bernedom/feature/disable-testing-option
Browse files Browse the repository at this point in the history
Feature/disable testing option
  • Loading branch information
bernedom authored Mar 31, 2020
2 parents cc9ac45 + 451be3e commit 699d3d3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changelog

## 0.0.8

* Add cmake option `BERTRAND_BUILD_TESTING` (default `ON`) to disable bertrand tests if used with `add_subdirectory`

## 0.0.7

* Removing double underscores
* Unit-Tests work in release mode as well
* Unit-tests work in release mode as well

## 0.0.6

Expand Down
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ cmake_minimum_required(VERSION 3.12)

project(
"bertrand"
VERSION 0.0.7
VERSION 0.0.8
DESCRIPTION
"A header only c++ library providing functionality for design by contract"
HOMEPAGE_URL "https://github.com/bernedom/bertrand")

include(GNUInstallDirs)
include(CTest)
option(BERTRAND_BUILD_TESTING "enable testing for bertrand; Requires global BUILD_TESTING to be set" ON)

add_library(${PROJECT_NAME} INTERFACE)
# add alias so the project can be uses with add_subdirectory
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

include(GNUInstallDirs)
include(CTest)

# Adding the install interface generator expression makes sure that the include
# files are installed to the proper location (provided by GNUInstallDirs)
Expand All @@ -23,7 +25,7 @@ target_include_directories(

target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)

if(BUILD_TESTING)
if(BUILD_TESTING AND BERTRAND_BUILD_TESTING)
add_subdirectory(test)
endif()

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ float divide(float dividend, float divisor) {

```
The contract related keywords `Require`, `Ensure` and `Invariant` are implemented. A failing contract results in immediate programm termination by an `abort`. The contract message is printed to stderr.
The contract related keywords `Require`, `Ensure` and `Invariant` are implemented. A failing contract results in immediate program termination by an `abort`. The contract message is printed to stderr.
By default contracts are enabled unless the `NDEBUG` compiler flag is set. Contracts can be force enabled or disabled by passing the compiler flag `BERTRAND_ENABLE_CONTRACTS` or `BERTRAND_DISABLE_CONTRACTS` passing both will lead to a compiler error.
Expand All @@ -37,6 +37,16 @@ mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=${HOME}/local-install
cmake --build . --target install
```
### cmake sub-directory

bertrand can be included using `add_subdirectory` if it cannot be installed into a system.

If bertrand is included and the `EXCLUDE_FROM_ALL` flag is set, bertrand test can be disabled by setting the `BERTRAND_BUILD_TESTING` option
```cmake
set(BERTRAND_BUILD_TESTING OFF)
add_subdirectory(${bertrand_SOURCE_DIR} ${bertrand_BINARY_DIR}
EXCLUDE_FROM_ALL)
```

### conan.io

Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class bertrandConan(ConanFile):
name = "bertrand"
version = "0.0.7"
version = "0.0.8"
license = "LGPLv3"
author = "Dominik Berner <dominik.berner+bertrand-conan@gmail.com"
url = "https://github.com/bernedom/bertrand"
Expand Down
2 changes: 1 addition & 1 deletion include/bertrand/bertrand.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file is part of "bertrand" version 0.0.7
* This file is part of "bertrand" version 0.0.8
* https://github.com/bernedom/bertrand
* A minimalistic, header only implementation of design by contract for C++
*
Expand Down
33 changes: 33 additions & 0 deletions test/installation-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ testConanInstallation()
conan remove -f *@bertrand/testing
}

testDisablingOfBertrandBuildingTests()
{
cmake "${ROOT_DIR}" -B"${BERTRAND_BUILD_DIR}" -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PATH}" -DBUILD_TESTING=on -DBERTRAND_BUILD_TESTING=off -G Ninja
cmake --build "${BERTRAND_BUILD_DIR}" --config Release
CURRENT_DIR=$(pwd)
cd "${BERTRAND_BUILD_DIR}"
NUMBER_OF_TESTS=$(ctest -N -o | grep -E '^Total Tests: [0-9]+')
cd "${CURRENT_DIR}"
assertEquals "No tests found" "Total Tests: 0" "${NUMBER_OF_TESTS}"
}

testGlobalDisablingOfTests()
{
cmake "${ROOT_DIR}" -B"${BERTRAND_BUILD_DIR}" -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PATH}" -DBUILD_TESTING=off -DBERTRAND_BUILD_TESTING=on -G Ninja
cmake --build "${BERTRAND_BUILD_DIR}" --config Release
CURRENT_DIR=$(pwd)
cd "${BERTRAND_BUILD_DIR}"
NUMBER_OF_TESTS=$(ctest -N -o | grep -E '^Total Tests: [0-9]+')
cd "${CURRENT_DIR}"
assertEquals "No tests found" "Total Tests: 0" "${NUMBER_OF_TESTS}"
}


testAllTestsEnabled()
{
cmake "${ROOT_DIR}" -B"${BERTRAND_BUILD_DIR}" -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PATH}" -DBUILD_TESTING=on -DBERTRAND_BUILD_TESTING=on -G Ninja
cmake --build "${BERTRAND_BUILD_DIR}" --config Release
CURRENT_DIR=$(pwd)
cd "${BERTRAND_BUILD_DIR}"
NUMBER_OF_TESTS=$(ctest -N -o | grep -E '^Total Tests: [0-9]+')
cd "${CURRENT_DIR}"
assertNotEquals "Tests found" "Total Tests: 0" "${NUMBER_OF_TESTS}"
}

# Load shUnit2.
. shunit2

0 comments on commit 699d3d3

Please sign in to comment.