From e986d49ed65b18d1c68b6dfc60b0d9aeaccb8dcb Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 4 Jun 2020 23:15:00 +0700 Subject: [PATCH] initial commit --- .appveyor.yml | 45 ++++++++++ .codecov.yml | 4 + .gitignore | 3 + .travis.yml | 159 ++++++++++++++++++++++++++++++++++ CMakeLists.txt | 20 +++++ LICENSE.md | 21 +++++ README.md | 51 +++++++++++ headers/defer.hpp/defer.hpp | 150 ++++++++++++++++++++++++++++++++ scripts/build_all.bat | 12 +++ scripts/build_all.sh | 5 ++ scripts/build_clear.bat | 9 ++ scripts/build_clear.sh | 4 + scripts/build_debug.sh | 9 ++ scripts/build_debug_x64.bat | 14 +++ scripts/build_debug_x86.bat | 14 +++ scripts/build_release.sh | 9 ++ scripts/build_release_x64.bat | 14 +++ scripts/build_release_x86.bat | 14 +++ scripts/upload_coverage.sh | 17 ++++ untests/CMakeLists.txt | 50 +++++++++++ untests/catch_main.cpp | 9 ++ untests/defer_examples.cpp | 17 ++++ untests/defer_tests.cpp | 17 ++++ 23 files changed, 667 insertions(+) create mode 100644 .appveyor.yml create mode 100644 .codecov.yml create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 CMakeLists.txt create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 headers/defer.hpp/defer.hpp create mode 100644 scripts/build_all.bat create mode 100755 scripts/build_all.sh create mode 100644 scripts/build_clear.bat create mode 100755 scripts/build_clear.sh create mode 100755 scripts/build_debug.sh create mode 100644 scripts/build_debug_x64.bat create mode 100644 scripts/build_debug_x86.bat create mode 100755 scripts/build_release.sh create mode 100644 scripts/build_release_x64.bat create mode 100644 scripts/build_release_x86.bat create mode 100755 scripts/upload_coverage.sh create mode 100644 untests/CMakeLists.txt create mode 100644 untests/catch_main.cpp create mode 100644 untests/defer_examples.cpp create mode 100644 untests/defer_tests.cpp diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..b3272fe --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,45 @@ +image: + - Visual Studio 2017 + - Visual Studio 2019 + +platform: + - x86 + - x64 + +configuration: + - Debug + - Release + +for: + +- + matrix: + only: + - platform: x86 + configuration: Debug + build_script: + - scripts\build_debug_x86.bat + +- + matrix: + only: + - platform: x64 + configuration: Debug + build_script: + - scripts\build_debug_x64.bat + +- + matrix: + only: + - platform: x86 + configuration: Release + build_script: + - scripts\build_release_x86.bat + +- + matrix: + only: + - platform: x64 + configuration: Release + build_script: + - scripts\build_release_x64.bat diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..69ebbfa --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,4 @@ +ignore: + - "catch.hpp" + - "catch_main.hpp" + - "*_tests.cpp" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb695eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/* +.vscode/* +CMakeLists.txt.user diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d26d34a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,159 @@ +language: cpp + +matrix: + include: + + # + # windows (MSVC 2017) + # + + - os: windows + stage: windows + name: debug, MSVC 2017, x86 + script: ./scripts/build_debug_x86.bat + + - os: windows + stage: windows + name: release, MSVC 2017, x86 + script: ./scripts/build_release_x86.bat + + - os: windows + stage: windows + name: debug, MSVC 2017, x64 + script: ./scripts/build_debug_x64.bat + + - os: windows + stage: windows + name: release, MSVC 2017, x64 + script: ./scripts/build_release_x64.bat + + # + # linux (g++-7) + # + + - os: linux + dist: xenial + stage: linux + name: debug, g++-7 + addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7"] } } + env: CC=gcc-7 CXX=g++-7 + script: ./scripts/build_debug.sh + + - os: linux + dist: xenial + stage: linux + name: release, g++-7 + addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7"] } } + env: CC=gcc-7 CXX=g++-7 + script: ./scripts/build_release.sh + + # + # linux (g++-8) + # + + - os: linux + dist: xenial + stage: linux + name: debug, g++-8 + addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-8"] } } + env: CC=gcc-8 CXX=g++-8 + script: ./scripts/build_debug.sh + + - os: linux + dist: xenial + stage: linux + name: release, g++-8 + addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-8"] } } + env: CC=gcc-8 CXX=g++-8 + script: ./scripts/build_release.sh + + # + # linux (clang++-5.0) + # + + - os: linux + dist: xenial + stage: linux + name: debug, clang++-5.0 + addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-5.0"], packages: ["g++-7", "clang-5.0"] } } + env: CC=clang-5.0 CXX=clang++-5.0 + script: ./scripts/build_debug.sh + + - os: linux + dist: xenial + stage: linux + name: release, clang++-5.0 + addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-5.0"], packages: ["g++-7", "clang-5.0"] } } + env: CC=clang-5.0 CXX=clang++-5.0 + script: ./scripts/build_release.sh + + # + # linux (clang++-6.0) + # + + - os: linux + dist: xenial + stage: linux + name: debug, clang++-6.0 + addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"], packages: ["g++-7", "clang-6.0"] } } + env: CC=clang-6.0 CXX=clang++-6.0 + script: ./scripts/build_debug.sh + + - os: linux + dist: xenial + stage: linux + name: release, clang++-6.0 + addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"], packages: ["g++-7", "clang-6.0"] } } + env: CC=clang-6.0 CXX=clang++-6.0 + script: ./scripts/build_release.sh + + # + # macosx (xcode10) + # + + - os: osx + osx_image: xcode10 + stage: macosx + name: debug, xcode10 + script: ./scripts/build_debug.sh + + - os: osx + osx_image: xcode10 + stage: macosx + name: release, xcode10 + script: ./scripts/build_release.sh + + # + # macosx (xcode11) + # + + - os: osx + osx_image: xcode11 + stage: macosx + name: debug, xcode11 + script: ./scripts/build_debug.sh + + - os: osx + osx_image: xcode11 + stage: macosx + name: release, xcode11 + script: ./scripts/build_release.sh + + # + # coverage + # + + - os: osx + osx_image: xcode10 + stage: coverage + name: coverage, xcode10 + addons: { homebrew: { packages: ["lcov"], update: true } } + script: ./scripts/upload_coverage.sh + +before_install: + - if [ "$TRAVIS_OS_NAME" == 'linux' ]; then + mkdir $HOME/cmake; + export PATH="$HOME/cmake/bin:$PATH"; + travis_retry wget -q https://cmake.org/files/v3.11/cmake-3.11.4-Linux-x86_64.sh; + sh cmake-3.11.4-Linux-x86_64.sh --prefix=$HOME/cmake --exclude-subdir --skip-license; + fi diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..db191d3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +# 3.8 version is required for `cxx_std_17` +cmake_minimum_required(VERSION 3.8 FATAL_ERROR) + +if(NOT DEFINED PROJECT_NAME) + set(BUILD_AS_STANDALONE ON) +endif() + +project(defer.hpp) + +add_library(${PROJECT_NAME} INTERFACE) +target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17) +target_include_directories(${PROJECT_NAME} INTERFACE headers) + +if(BUILD_AS_STANDALONE) + option(BUILD_WITH_UNTESTS "Build with unit tests" ON) + if(BUILD_WITH_UNTESTS) + enable_testing() + add_subdirectory(untests) + endif() +endif() diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1bfae40 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..37ea727 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# defer.hpp + +[![travis][badge.travis]][travis] +[![appveyor][badge.appveyor]][appveyor] +[![codecov][badge.codecov]][codecov] +[![language][badge.language]][language] +[![license][badge.license]][license] +[![paypal][badge.paypal]][paypal] + +[badge.travis]: https://img.shields.io/travis/BlackMATov/defer.hpp/master.svg?logo=travis +[badge.appveyor]: https://img.shields.io/appveyor/ci/BlackMATov/defer-hpp/master.svg?logo=appveyor +[badge.codecov]: https://img.shields.io/codecov/c/github/BlackMATov/defer.hpp/master.svg?logo=codecov +[badge.language]: https://img.shields.io/badge/language-C%2B%2B17-yellow.svg +[badge.license]: https://img.shields.io/badge/license-MIT-blue.svg +[badge.paypal]: https://img.shields.io/badge/donate-PayPal-orange.svg?logo=paypal&colorA=00457C + +[travis]: https://travis-ci.org/BlackMATov/defer.hpp +[appveyor]: https://ci.appveyor.com/project/BlackMATov/defer-hpp +[codecov]: https://codecov.io/gh/BlackMATov/defer.hpp +[language]: https://en.wikipedia.org/wiki/C%2B%2B17 +[license]: https://en.wikipedia.org/wiki/MIT_License +[paypal]: https://www.paypal.me/matov + +[defer]: https://github.com/BlackMATov/defer.hpp + +## Requirements + +- [gcc](https://www.gnu.org/software/gcc/) **>= 7** +- [clang](https://clang.llvm.org/) **>= 5.0** +- [msvc](https://visualstudio.microsoft.com/) **>= 2017** + +## Installation + +[defer.hpp][defer] is a header-only library. All you need to do is copy the headers files from `headers` directory into your project and include them: + +```cpp +#include "defer.hpp/defer.hpp" +``` + +Also, you can add the root repository directory to your [cmake](https://cmake.org) project: + +```cmake +add_subdirectory(external/defer.hpp) +target_link_libraries(your_project_target defer.hpp) +``` + +## Examples + +TODO + +## [License (MIT)](./LICENSE.md) diff --git a/headers/defer.hpp/defer.hpp b/headers/defer.hpp/defer.hpp new file mode 100644 index 0000000..c7bd702 --- /dev/null +++ b/headers/defer.hpp/defer.hpp @@ -0,0 +1,150 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/defer.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include + +namespace defer_hpp +{ + namespace impl + { + class noncopyable { + public: + noncopyable(const noncopyable&) = delete; + noncopyable& operator=(const noncopyable&) = delete; + protected: + noncopyable() = default; + ~noncopyable() = default; + }; + + template < typename F, typename... Args > + class defer_impl : noncopyable { + public: + template < typename UF > + explicit defer_impl( + UF&& f, + std::tuple&& args) + : f_(std::forward(f)) + , args_(std::move(args)) {} + + virtual ~defer_impl() noexcept { + if ( !dismissed_ ) { + std::apply(std::move(f_), std::move(args_)); + } + } + + void dismiss() noexcept { + dismissed_ = true; + } + private: + F f_; + std::tuple args_; + bool dismissed_{}; + }; + + template < typename F, typename... Args > + class error_defer_impl final : public defer_impl { + public: + template < typename UF > + explicit error_defer_impl( + UF&& f, + std::tuple&& args) + : defer_impl(std::forward(f), std::move(args)) + , exceptions_(std::uncaught_exceptions()) {} + + ~error_defer_impl() noexcept final { + if ( exceptions_ == std::uncaught_exceptions() ) { + this->dismiss(); + } + } + private: + int exceptions_{}; + }; + + template < typename F, typename... Args > + class return_defer_impl final : public defer_impl { + public: + template < typename UF > + explicit return_defer_impl( + UF&& f, + std::tuple&& args) + : defer_impl(std::forward(f), std::move(args)) + , exceptions_(std::uncaught_exceptions()) {} + + ~return_defer_impl() noexcept final { + if ( exceptions_ != std::uncaught_exceptions() ) { + this->dismiss(); + } + } + private: + int exceptions_{}; + }; + } + + template < typename F, typename... Args > + auto make_defer(F&& f, Args&&... args) { + using defer_t = impl::defer_impl< + std::decay_t, + std::decay_t...>; + return defer_t( + std::forward(f), + std::make_tuple(std::forward(args)...)); + } + + template < typename F, typename... Args > + auto make_error_defer(F&& f, Args&&... args) { + using defer_t = impl::error_defer_impl< + std::decay_t, + std::decay_t...>; + return defer_t( + std::forward(f), + std::make_tuple(std::forward(args)...)); + } + + template < typename F, typename... Args > + auto make_return_defer(F&& f, Args&&... args) { + using defer_t = impl::return_defer_impl< + std::decay_t, + std::decay_t...>; + return defer_t( + std::forward(f), + std::make_tuple(std::forward(args)...)); + } +} + +#define DEFER_IMPL_PP_CAT(x, y) DEFER_IMPL_PP_CAT_I(x, y) +#define DEFER_IMPL_PP_CAT_I(x, y) x ## y + +#ifdef __COUNTER__ + #define DEFER(...)\ + auto DEFER_IMPL_PP_CAT(generated_defer_, __COUNTER__) =\ + ::defer_hpp::make_defer(__VA_ARGS__) + + #define ERROR_DEFER(...)\ + auto DEFER_IMPL_PP_CAT(generated_error_defer_, __COUNTER__) =\ + ::defer_hpp::make_error_defer(__VA_ARGS__) + + #define RETURN_DEFER(...)\ + auto DEFER_IMPL_PP_CAT(generated_return_defer_, __COUNTER__) =\ + ::defer_hpp::make_return_defer(__VA_ARGS__) +#else + #define DEFER(...)\ + auto DEFER_IMPL_PP_CAT(generated_defer_, __LINE__) =\ + ::defer_hpp::make_defer(__VA_ARGS__) + + #define ERROR_DEFER(...)\ + auto DEFER_IMPL_PP_CAT(generated_error_defer_, __LINE__) =\ + ::defer_hpp::make_error_defer(__VA_ARGS__) + + #define RETURN_DEFER(...)\ + auto DEFER_IMPL_PP_CAT(generated_return_defer_, __LINE__) =\ + ::defer_hpp::make_return_defer(__VA_ARGS__) +#endif diff --git a/scripts/build_all.bat b/scripts/build_all.bat new file mode 100644 index 0000000..9e778dc --- /dev/null +++ b/scripts/build_all.bat @@ -0,0 +1,12 @@ +@echo off +set SCRIPT_DIR=%~dp0% +call %SCRIPT_DIR%\build_debug_x86.bat || goto :error +call %SCRIPT_DIR%\build_debug_x64.bat || goto :error +call %SCRIPT_DIR%\build_release_x86.bat || goto :error +call %SCRIPT_DIR%\build_release_x64.bat || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/build_all.sh b/scripts/build_all.sh new file mode 100755 index 0000000..d9cd585 --- /dev/null +++ b/scripts/build_all.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e +SCRIPT_DIR=`dirname "$BASH_SOURCE"` +$SCRIPT_DIR/build_debug.sh +$SCRIPT_DIR/build_release.sh diff --git a/scripts/build_clear.bat b/scripts/build_clear.bat new file mode 100644 index 0000000..44375fb --- /dev/null +++ b/scripts/build_clear.bat @@ -0,0 +1,9 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +rmdir /s /q %BUILD_DIR% || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/build_clear.sh b/scripts/build_clear.sh new file mode 100755 index 0000000..ef8a2e3 --- /dev/null +++ b/scripts/build_clear.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +BUILD_DIR=`dirname "$BASH_SOURCE"`/../build +rm -rf $BUILD_DIR diff --git a/scripts/build_debug.sh b/scripts/build_debug.sh new file mode 100755 index 0000000..a069095 --- /dev/null +++ b/scripts/build_debug.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +BUILD_DIR=`dirname "$BASH_SOURCE"`/../build +mkdir -p $BUILD_DIR/Debug +pushd $BUILD_DIR/Debug +cmake -DCMAKE_BUILD_TYPE=Debug ../.. +cmake --build . +ctest --verbose +popd diff --git a/scripts/build_debug_x64.bat b/scripts/build_debug_x64.bat new file mode 100644 index 0000000..f80c2f3 --- /dev/null +++ b/scripts/build_debug_x64.bat @@ -0,0 +1,14 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +mkdir %BUILD_DIR%\Debug\x64 || goto :error +pushd %BUILD_DIR%\Debug\x64 || goto :error +cmake ..\..\.. -A x64 || goto :error +cmake --build . --config Debug || goto :error +ctest --verbose || goto :error +popd || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/build_debug_x86.bat b/scripts/build_debug_x86.bat new file mode 100644 index 0000000..ee05129 --- /dev/null +++ b/scripts/build_debug_x86.bat @@ -0,0 +1,14 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +mkdir %BUILD_DIR%\Debug\x86 || goto :error +pushd %BUILD_DIR%\Debug\x86 || goto :error +cmake ..\..\.. -A Win32 || goto :error +cmake --build . --config Debug || goto :error +ctest --verbose || goto :error +popd || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/build_release.sh b/scripts/build_release.sh new file mode 100755 index 0000000..1377504 --- /dev/null +++ b/scripts/build_release.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +BUILD_DIR=`dirname "$BASH_SOURCE"`/../build +mkdir -p $BUILD_DIR/Release +pushd $BUILD_DIR/Release +cmake -DCMAKE_BUILD_TYPE=Release ../.. +cmake --build . +ctest --verbose +popd diff --git a/scripts/build_release_x64.bat b/scripts/build_release_x64.bat new file mode 100644 index 0000000..65e251e --- /dev/null +++ b/scripts/build_release_x64.bat @@ -0,0 +1,14 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +mkdir %BUILD_DIR%\Release\x64 || goto :error +pushd %BUILD_DIR%\Release\x64 || goto :error +cmake ..\..\.. -A x64 || goto :error +cmake --build . --config Release || goto :error +ctest --verbose || goto :error +popd || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/build_release_x86.bat b/scripts/build_release_x86.bat new file mode 100644 index 0000000..1be857b --- /dev/null +++ b/scripts/build_release_x86.bat @@ -0,0 +1,14 @@ +@echo off +set BUILD_DIR=%~dp0%\..\build +mkdir %BUILD_DIR%\Release\x86 || goto :error +pushd %BUILD_DIR%\Release\x86 || goto :error +cmake ..\..\.. -A Win32 || goto :error +cmake --build . --config Release || goto :error +ctest --verbose || goto :error +popd || goto :error + +goto :EOF + +:error +echo Failed with error #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/upload_coverage.sh b/scripts/upload_coverage.sh new file mode 100755 index 0000000..b36265d --- /dev/null +++ b/scripts/upload_coverage.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +BUILD_DIR=`dirname "$BASH_SOURCE"`/../build +mkdir -p $BUILD_DIR/coverage +cd $BUILD_DIR/coverage +cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_COVERAGE=ON ../.. +cmake --build . + +lcov -d . -z +ctest --verbose + +lcov -d . -c -o "coverage.info" +lcov -r "coverage.info" "*/usr/*" "*/catch.hpp" "*/catch_main.cpp" "*_tests.cpp" "*_examples.cpp" -o "coverage.info" +lcov -l "coverage.info" + +bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" diff --git a/untests/CMakeLists.txt b/untests/CMakeLists.txt new file mode 100644 index 0000000..e9f8208 --- /dev/null +++ b/untests/CMakeLists.txt @@ -0,0 +1,50 @@ +# 3.11 version is required for `FetchContent` +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) + +project(defer.hpp.untests) + +# +# coverage +# + +option(BUILD_WITH_COVERAGE "Build with coverage" OFF) +if(BUILD_WITH_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")) + set(COVERAGE_FLAGS "--coverage") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS}") + set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${COVERAGE_FLAGS}") +endif() + +# +# executable +# + +file(GLOB UNTESTS_SOURCES "*.cpp" "*.hpp") +add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES}) +target_link_libraries(${PROJECT_NAME} defer.hpp) + +target_compile_options(${PROJECT_NAME} + PRIVATE + $<$: + /W4> + PRIVATE + $<$,$,$>: + -Wall -Wextra -Wpedantic>) + +add_test(${PROJECT_NAME} ${PROJECT_NAME}) + +# +# catchorg/catch2 +# + +include(FetchContent) +FetchContent_Declare( + catchorg_catch2 + GIT_REPOSITORY https://github.com/catchorg/catch2) + +FetchContent_GetProperties(catchorg_catch2) +if(NOT catchorg_catch2_POPULATED) + FetchContent_Populate(catchorg_catch2) + target_include_directories(${PROJECT_NAME} + PRIVATE ${catchorg_catch2_SOURCE_DIR}/single_include) +endif() diff --git a/untests/catch_main.cpp b/untests/catch_main.cpp new file mode 100644 index 0000000..9e05b68 --- /dev/null +++ b/untests/catch_main.cpp @@ -0,0 +1,9 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/defer.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#define CATCH_CONFIG_MAIN +#define CATCH_CONFIG_FAST_COMPILE +#include diff --git a/untests/defer_examples.cpp b/untests/defer_examples.cpp new file mode 100644 index 0000000..53eb66d --- /dev/null +++ b/untests/defer_examples.cpp @@ -0,0 +1,17 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/defer.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#define CATCH_CONFIG_FAST_COMPILE +#include + +#include + +namespace +{ +} + +TEST_CASE("examples") { +} diff --git a/untests/defer_tests.cpp b/untests/defer_tests.cpp new file mode 100644 index 0000000..1e0da85 --- /dev/null +++ b/untests/defer_tests.cpp @@ -0,0 +1,17 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/defer.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#define CATCH_CONFIG_FAST_COMPILE +#include + +#include + +namespace +{ +} + +TEST_CASE("defer") { +}