mirror of
https://github.com/BlackMATov/defer.hpp.git
synced 2025-12-14 18:05:29 +07:00
doctest instead catch2
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
ignore:
|
|
||||||
- "catch.hpp"
|
|
||||||
- "catch_main.hpp"
|
|
||||||
- "*_tests.cpp"
|
|
||||||
46
.travis.yml
46
.travis.yml
@@ -1,32 +1,12 @@
|
|||||||
|
git:
|
||||||
|
depth: false
|
||||||
|
quiet: true
|
||||||
|
|
||||||
language: cpp
|
language: cpp
|
||||||
|
|
||||||
matrix:
|
jobs:
|
||||||
include:
|
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)
|
# linux (g++-7)
|
||||||
#
|
#
|
||||||
@@ -75,7 +55,7 @@ matrix:
|
|||||||
dist: xenial
|
dist: xenial
|
||||||
stage: linux
|
stage: linux
|
||||||
name: debug, clang++-5.0
|
name: debug, clang++-5.0
|
||||||
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-5.0"], packages: ["g++-7", "clang-5.0"] } }
|
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-5.0"] } }
|
||||||
env: CC=clang-5.0 CXX=clang++-5.0
|
env: CC=clang-5.0 CXX=clang++-5.0
|
||||||
script: ./scripts/build_debug.sh
|
script: ./scripts/build_debug.sh
|
||||||
|
|
||||||
@@ -83,7 +63,7 @@ matrix:
|
|||||||
dist: xenial
|
dist: xenial
|
||||||
stage: linux
|
stage: linux
|
||||||
name: release, clang++-5.0
|
name: release, clang++-5.0
|
||||||
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-5.0"], packages: ["g++-7", "clang-5.0"] } }
|
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-5.0"] } }
|
||||||
env: CC=clang-5.0 CXX=clang++-5.0
|
env: CC=clang-5.0 CXX=clang++-5.0
|
||||||
script: ./scripts/build_release.sh
|
script: ./scripts/build_release.sh
|
||||||
|
|
||||||
@@ -95,7 +75,7 @@ matrix:
|
|||||||
dist: xenial
|
dist: xenial
|
||||||
stage: linux
|
stage: linux
|
||||||
name: debug, clang++-6.0
|
name: debug, clang++-6.0
|
||||||
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"], packages: ["g++-7", "clang-6.0"] } }
|
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-6.0"] } }
|
||||||
env: CC=clang-6.0 CXX=clang++-6.0
|
env: CC=clang-6.0 CXX=clang++-6.0
|
||||||
script: ./scripts/build_debug.sh
|
script: ./scripts/build_debug.sh
|
||||||
|
|
||||||
@@ -103,7 +83,7 @@ matrix:
|
|||||||
dist: xenial
|
dist: xenial
|
||||||
stage: linux
|
stage: linux
|
||||||
name: release, clang++-6.0
|
name: release, clang++-6.0
|
||||||
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"], packages: ["g++-7", "clang-6.0"] } }
|
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-6.0"] } }
|
||||||
env: CC=clang-6.0 CXX=clang++-6.0
|
env: CC=clang-6.0 CXX=clang++-6.0
|
||||||
script: ./scripts/build_release.sh
|
script: ./scripts/build_release.sh
|
||||||
|
|
||||||
@@ -149,11 +129,3 @@ matrix:
|
|||||||
name: coverage, xcode10
|
name: coverage, xcode10
|
||||||
addons: { homebrew: { packages: ["lcov"], update: true } }
|
addons: { homebrew: { packages: ["lcov"], update: true } }
|
||||||
script: ./scripts/upload_coverage.sh
|
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
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ lcov -d . -z
|
|||||||
ctest --verbose
|
ctest --verbose
|
||||||
|
|
||||||
lcov -d . -c -o "coverage.info"
|
lcov -d . -c -o "coverage.info"
|
||||||
lcov -r "coverage.info" "*/usr/*" "*/catch.hpp" "*/catch_main.cpp" "*_tests.cpp" "*_examples.cpp" -o "coverage.info"
|
lcov -r "coverage.info" "*/usr/*" "*/untests/*" -o "coverage.info"
|
||||||
lcov -l "coverage.info"
|
lcov -l "coverage.info"
|
||||||
|
|
||||||
bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
|
bash <(curl -s https://codecov.io/bash) -f "coverage.info" || echo "Codecov did not collect coverage reports"
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
# 3.11 version is required for `FetchContent`
|
|
||||||
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
|
|
||||||
|
|
||||||
project(defer.hpp.untests)
|
project(defer.hpp.untests)
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -19,7 +16,7 @@ endif()
|
|||||||
# executable
|
# executable
|
||||||
#
|
#
|
||||||
|
|
||||||
file(GLOB UNTESTS_SOURCES "*.cpp" "*.hpp")
|
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
|
||||||
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
||||||
target_link_libraries(${PROJECT_NAME} defer.hpp)
|
target_link_libraries(${PROJECT_NAME} defer.hpp)
|
||||||
|
|
||||||
@@ -32,20 +29,3 @@ target_compile_options(${PROJECT_NAME}
|
|||||||
-Wall -Wextra -Wpedantic>)
|
-Wall -Wextra -Wpedantic>)
|
||||||
|
|
||||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||||
|
|
||||||
#
|
|
||||||
# catchorg/catch2
|
|
||||||
#
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
catchorg_catch2
|
|
||||||
GIT_REPOSITORY https://github.com/catchorg/catch2
|
|
||||||
GIT_TAG v2.13.2)
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* 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 <catch2/catch.hpp>
|
|
||||||
@@ -4,17 +4,15 @@
|
|||||||
* Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com)
|
* Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#define CATCH_CONFIG_FAST_COMPILE
|
#include <defer.hpp/defer.hpp>
|
||||||
#include <catch2/catch.hpp>
|
#include "doctest/doctest.hpp"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <defer.hpp/defer.hpp>
|
|
||||||
|
|
||||||
TEST_CASE("examples") {
|
TEST_CASE("examples") {
|
||||||
SECTION("basic_defer") {
|
SUBCASE("basic_defer") {
|
||||||
if ( FILE *file = std::fopen("output.txt", "a") ) {
|
if ( FILE *file = std::fopen("output.txt", "a") ) {
|
||||||
// defer will close the file after scope or on exception
|
// defer will close the file after scope or on exception
|
||||||
DEFER_HPP([file]{ std::fclose(file); });
|
DEFER_HPP([file]{ std::fclose(file); });
|
||||||
@@ -26,7 +24,7 @@ TEST_CASE("examples") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("error_defer") {
|
SUBCASE("error_defer") {
|
||||||
if ( FILE *file = std::fopen("output.txt", "a") ) {
|
if ( FILE *file = std::fopen("output.txt", "a") ) {
|
||||||
// defer will close the file after scope or on exception
|
// defer will close the file after scope or on exception
|
||||||
DEFER_HPP([file]{ std::fclose(file); });
|
DEFER_HPP([file]{ std::fclose(file); });
|
||||||
@@ -43,7 +41,7 @@ TEST_CASE("examples") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("return_defer") {
|
SUBCASE("return_defer") {
|
||||||
if ( FILE *file = std::fopen("output.txt", "a") ) {
|
if ( FILE *file = std::fopen("output.txt", "a") ) {
|
||||||
// defer will close the file after scope or on exception
|
// defer will close the file after scope or on exception
|
||||||
DEFER_HPP([file]{ std::fclose(file); });
|
DEFER_HPP([file]{ std::fclose(file); });
|
||||||
|
|||||||
@@ -4,17 +4,13 @@
|
|||||||
* Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com)
|
* Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#define CATCH_CONFIG_FAST_COMPILE
|
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
#include <defer.hpp/defer.hpp>
|
#include <defer.hpp/defer.hpp>
|
||||||
|
#include "doctest/doctest.hpp"
|
||||||
|
|
||||||
namespace
|
#include <functional>
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("defer") {
|
TEST_CASE("defer") {
|
||||||
SECTION("simple") {
|
SUBCASE("simple") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
{
|
{
|
||||||
DEFER_HPP([&i]{ ++i; });
|
DEFER_HPP([&i]{ ++i; });
|
||||||
@@ -23,7 +19,7 @@ TEST_CASE("defer") {
|
|||||||
REQUIRE(i == 1);
|
REQUIRE(i == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_arg") {
|
SUBCASE("simple_with_arg") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
{
|
{
|
||||||
DEFER_HPP([](int& i){ ++i; }, std::ref(i));
|
DEFER_HPP([](int& i){ ++i; }, std::ref(i));
|
||||||
@@ -32,7 +28,7 @@ TEST_CASE("defer") {
|
|||||||
REQUIRE(i == 1);
|
REQUIRE(i == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_args") {
|
SUBCASE("simple_with_args") {
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
{
|
{
|
||||||
DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j));
|
DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j));
|
||||||
@@ -43,7 +39,7 @@ TEST_CASE("defer") {
|
|||||||
REQUIRE(j == 2);
|
REQUIRE(j == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_exception") {
|
SUBCASE("simple_with_exception") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
try {
|
try {
|
||||||
DEFER_HPP([&i]{ ++i; });
|
DEFER_HPP([&i]{ ++i; });
|
||||||
@@ -56,7 +52,7 @@ TEST_CASE("defer") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("error_defer") {
|
TEST_CASE("error_defer") {
|
||||||
SECTION("simple") {
|
SUBCASE("simple") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
{
|
{
|
||||||
ERROR_DEFER_HPP([&i]{ ++i; });
|
ERROR_DEFER_HPP([&i]{ ++i; });
|
||||||
@@ -65,7 +61,7 @@ TEST_CASE("error_defer") {
|
|||||||
REQUIRE(i == 0);
|
REQUIRE(i == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_arg") {
|
SUBCASE("simple_with_arg") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
{
|
{
|
||||||
ERROR_DEFER_HPP([](int& i){ ++i; }, std::ref(i));
|
ERROR_DEFER_HPP([](int& i){ ++i; }, std::ref(i));
|
||||||
@@ -74,7 +70,7 @@ TEST_CASE("error_defer") {
|
|||||||
REQUIRE(i == 0);
|
REQUIRE(i == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_args") {
|
SUBCASE("simple_with_args") {
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
{
|
{
|
||||||
ERROR_DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j));
|
ERROR_DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j));
|
||||||
@@ -85,7 +81,7 @@ TEST_CASE("error_defer") {
|
|||||||
REQUIRE(j == 0);
|
REQUIRE(j == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_exception") {
|
SUBCASE("simple_with_exception") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
try {
|
try {
|
||||||
ERROR_DEFER_HPP([&i]{ ++i; });
|
ERROR_DEFER_HPP([&i]{ ++i; });
|
||||||
@@ -98,7 +94,7 @@ TEST_CASE("error_defer") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("return_defer") {
|
TEST_CASE("return_defer") {
|
||||||
SECTION("simple") {
|
SUBCASE("simple") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
{
|
{
|
||||||
RETURN_DEFER_HPP([&i]{ ++i; });
|
RETURN_DEFER_HPP([&i]{ ++i; });
|
||||||
@@ -107,7 +103,7 @@ TEST_CASE("return_defer") {
|
|||||||
REQUIRE(i == 1);
|
REQUIRE(i == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_arg") {
|
SUBCASE("simple_with_arg") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
{
|
{
|
||||||
RETURN_DEFER_HPP([](int& i){ ++i; }, std::ref(i));
|
RETURN_DEFER_HPP([](int& i){ ++i; }, std::ref(i));
|
||||||
@@ -116,7 +112,7 @@ TEST_CASE("return_defer") {
|
|||||||
REQUIRE(i == 1);
|
REQUIRE(i == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_args") {
|
SUBCASE("simple_with_args") {
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
{
|
{
|
||||||
RETURN_DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j));
|
RETURN_DEFER_HPP([](int& i, int& j){ ++i; j += 2; }, std::ref(i), std::ref(j));
|
||||||
@@ -127,7 +123,7 @@ TEST_CASE("return_defer") {
|
|||||||
REQUIRE(j == 2);
|
REQUIRE(j == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple_with_exception") {
|
SUBCASE("simple_with_exception") {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
try {
|
try {
|
||||||
RETURN_DEFER_HPP([&i]{ ++i; });
|
RETURN_DEFER_HPP([&i]{ ++i; });
|
||||||
|
|||||||
2
untests/doctest/doctest.cpp
Normal file
2
untests/doctest/doctest.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
||||||
6260
untests/doctest/doctest.h
Normal file
6260
untests/doctest/doctest.h
Normal file
File diff suppressed because it is too large
Load Diff
11
untests/doctest/doctest.hpp
Normal file
11
untests/doctest/doctest.hpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "doctest.h"
|
||||||
|
|
||||||
|
#define STATIC_REQUIRE(...)\
|
||||||
|
static_assert(__VA_ARGS__, #__VA_ARGS__);\
|
||||||
|
REQUIRE(__VA_ARGS__);
|
||||||
|
|
||||||
|
#define STATIC_REQUIRE_FALSE(...)\
|
||||||
|
static_assert(!(__VA_ARGS__), "!(" #__VA_ARGS__ ")");\
|
||||||
|
REQUIRE(!(__VA_ARGS__));
|
||||||
Reference in New Issue
Block a user