From f061dabbada3f658e69d7dc7c990044a5dc08f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 28 Aug 2018 09:44:47 +0200 Subject: [PATCH] Add ExtraTests infrastructure This means * a new cmake option, `CATCH_BUILD_EXTRA_TESTS`, that conditionally includes the ExtraTests subfolder * building and running them on some of the Travis build images * An example configuration test In the future these should be extended to cover most of the configuration options in Catch2, but this is a start. --- .travis.yml | 8 ++--- CMakeLists.txt | 4 +++ projects/ExtraTests/CMakeLists.txt | 29 +++++++++++++++++++ projects/ExtraTests/ToDo.txt | 12 ++++++++ .../ExtraTests/X10-FallbackStringifier.cpp | 23 +++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 projects/ExtraTests/CMakeLists.txt create mode 100644 projects/ExtraTests/ToDo.txt create mode 100644 projects/ExtraTests/X10-FallbackStringifier.cpp diff --git a/.travis.yml b/.travis.yml index 14595f78..a34146c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -219,7 +219,7 @@ matrix: apt: sources: *all_sources packages: ['lcov', 'g++-7'] - env: COMPILER='g++-7' CPP14=1 EXAMPLES=1 COVERAGE=1 + env: COMPILER='g++-7' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1 - os: linux compiler: clang @@ -229,7 +229,7 @@ matrix: sources: - ubuntu-toolchain-r-test - llvm-toolchain-trusty - env: COMPILER='clang++-3.8' EXAMPLES=1 COVERAGE=1 + env: COMPILER='clang++-3.8' EXAMPLES=1 COVERAGE=1 EXTRAS=1 - os: linux compiler: gcc @@ -242,7 +242,7 @@ matrix: - os: osx osx_image: xcode9.1 compiler: clang - env: COMPILER='clang++' CPP14=1 EXAMPLES=1 COVERAGE=1 + env: COMPILER='clang++' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1 install: - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" @@ -263,7 +263,7 @@ before_script: - python scripts/generateSingleHeader.py # Use Debug builds for running Valgrind and building examples - - cmake -H. -BBuild-Debug -DCMAKE_BUILD_TYPE=Debug -Wdev -DUSE_CPP14=${CPP14} -DCATCH_USE_VALGRIND=${VALGRIND} -DCATCH_BUILD_EXAMPLES=${EXAMPLES} -DCATCH_ENABLE_COVERAGE=${COVERAGE} + - cmake -H. -BBuild-Debug -DCMAKE_BUILD_TYPE=Debug -Wdev -DUSE_CPP14=${CPP14} -DCATCH_USE_VALGRIND=${VALGRIND} -DCATCH_BUILD_EXAMPLES=${EXAMPLES} -DCATCH_ENABLE_COVERAGE=${COVERAGE} -DCATCH_BUILD_EXTRA_TESTS=${EXTRAS} # Don't bother with release build for coverage build - cmake -H. -BBuild-Release -DCMAKE_BUILD_TYPE=Release -Wdev -DUSE_CPP14=${CPP14} diff --git a/CMakeLists.txt b/CMakeLists.txt index 56d55298..78b1fe22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ include(CTest) option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF) option(CATCH_BUILD_TESTING "Build SelfTest project" ON) option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF) +option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF) option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF) option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON) option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON) @@ -48,6 +49,9 @@ if(CATCH_BUILD_EXAMPLES) add_subdirectory(examples) endif() +if(CATCH_BUILD_EXTRA_TESTS) + add_subdirectory(projects/ExtraTests) +endif() # add catch as a 'linkable' target add_library(Catch2 INTERFACE) diff --git a/projects/ExtraTests/CMakeLists.txt b/projects/ExtraTests/CMakeLists.txt new file mode 100644 index 00000000..e78a4d49 --- /dev/null +++ b/projects/ExtraTests/CMakeLists.txt @@ -0,0 +1,29 @@ +# +# Build extra tests. +# +# Requires CATCH_BUILD_EXTRA_TESTS to be defined 'true', see ../CMakeLists.txt. +# + +cmake_minimum_required( VERSION 3.5 ) + +project( Catch2ExtraTests LANGUAGES CXX ) + +message( STATUS "Extra tests included" ) + +# define folders used: + +set( TESTS_DIR ${CATCH_DIR}/projects/ExtraTests ) +set( SINGLE_INCLUDE_PATH ${CATCH_DIR}/single_include ) + + +add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp) +add_test(NAME FallbackStringifier COMMAND FallbackStringifier -r compact -s) +set_tests_properties(FallbackStringifier PROPERTIES PASS_REGULAR_EXPRESSION "foo{} for: { !!! }") + + +set_property( TARGET FallbackStringifier PROPERTY CXX_STANDARD 11 ) +set_property( TARGET FallbackStringifier PROPERTY CXX_STANDARD_REQUIRED ON ) +set_property( TARGET FallbackStringifier PROPERTY CXX_EXTENSIONS OFF ) + +target_include_directories( FallbackStringifier PRIVATE ${SINGLE_INCLUDE_PATH} ) +target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier ) diff --git a/projects/ExtraTests/ToDo.txt b/projects/ExtraTests/ToDo.txt new file mode 100644 index 00000000..0f878bd1 --- /dev/null +++ b/projects/ExtraTests/ToDo.txt @@ -0,0 +1,12 @@ +Configuration options that are left default and thus are not properly tested +yet: + + CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases + CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows + CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed + CATCH_CONFIG_DISABLE_MATCHERS // Do not compile Matchers in this compilation unit + CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals + CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap + CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression + CATCH_CONFIG_DISABLE // Disables assertions and test case registration + CATCH_CONFIG_DEFAULT_REPORTER diff --git a/projects/ExtraTests/X10-FallbackStringifier.cpp b/projects/ExtraTests/X10-FallbackStringifier.cpp new file mode 100644 index 00000000..0522d1af --- /dev/null +++ b/projects/ExtraTests/X10-FallbackStringifier.cpp @@ -0,0 +1,23 @@ +// X10-FallbackStringifier.cpp +// Test that defining fallbackStringifier compiles + +#include + +// A catch-all stringifier +template +std::string fallbackStringifier(T const&) { + return "{ !!! }"; +} + +#define CATCH_CONFIG_MAIN +#include + +struct foo { + explicit operator bool() const { + return true; + } +}; + +TEST_CASE("aa") { + REQUIRE(foo{}); +}