Merge pull request #1 from BlackMATov/dev

Dev
This commit is contained in:
2020-11-30 21:50:31 +07:00
committed by GitHub
11 changed files with 6304 additions and 99 deletions

View File

@@ -1,4 +0,0 @@
ignore:
- "catch.hpp"
- "catch_main.hpp"
- "*_tests.cpp"

View File

@@ -1,32 +1,12 @@
git:
depth: false
quiet: true
language: cpp
matrix:
jobs:
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)
#
@@ -75,7 +55,7 @@ matrix:
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"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-5.0"] } }
env: CC=clang-5.0 CXX=clang++-5.0
script: ./scripts/build_debug.sh
@@ -83,7 +63,7 @@ matrix:
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"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-5.0"] } }
env: CC=clang-5.0 CXX=clang++-5.0
script: ./scripts/build_release.sh
@@ -95,7 +75,7 @@ matrix:
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"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-6.0"] } }
env: CC=clang-6.0 CXX=clang++-6.0
script: ./scripts/build_debug.sh
@@ -103,7 +83,7 @@ matrix:
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"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-6.0"] } }
env: CC=clang-6.0 CXX=clang++-6.0
script: ./scripts/build_release.sh
@@ -149,11 +129,3 @@ matrix:
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

View File

@@ -7,7 +7,6 @@
#pragma once
#include <exception>
#include <functional>
#include <tuple>
#include <type_traits>
#include <utility>

View File

@@ -11,7 +11,7 @@ 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 -r "coverage.info" "*/usr/*" "*/untests/*" -o "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"

View File

@@ -1,6 +1,3 @@
# 3.11 version is required for `FetchContent`
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(defer.hpp.untests)
#
@@ -19,7 +16,7 @@ endif()
# executable
#
file(GLOB UNTESTS_SOURCES "*.cpp" "*.hpp")
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME} defer.hpp)
@@ -32,20 +29,3 @@ target_compile_options(${PROJECT_NAME}
-Wall -Wextra -Wpedantic>)
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()

View File

@@ -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>

View File

@@ -4,17 +4,15 @@
* Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <defer.hpp/defer.hpp>
#include "doctest/doctest.hpp"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <defer.hpp/defer.hpp>
TEST_CASE("examples") {
SECTION("basic_defer") {
SUBCASE("basic_defer") {
if ( FILE *file = std::fopen("output.txt", "a") ) {
// defer will close the file after scope or on exception
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") ) {
// defer will close the file after scope or on exception
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") ) {
// defer will close the file after scope or on exception
DEFER_HPP([file]{ std::fclose(file); });

View File

@@ -4,17 +4,13 @@
* Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <defer.hpp/defer.hpp>
#include "doctest/doctest.hpp"
namespace
{
}
#include <functional>
TEST_CASE("defer") {
SECTION("simple") {
SUBCASE("simple") {
int i = 0;
{
DEFER_HPP([&i]{ ++i; });
@@ -23,7 +19,7 @@ TEST_CASE("defer") {
REQUIRE(i == 1);
}
SECTION("simple_with_arg") {
SUBCASE("simple_with_arg") {
int i = 0;
{
DEFER_HPP([](int& i){ ++i; }, std::ref(i));
@@ -32,7 +28,7 @@ TEST_CASE("defer") {
REQUIRE(i == 1);
}
SECTION("simple_with_args") {
SUBCASE("simple_with_args") {
int i = 0, j = 0;
{
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);
}
SECTION("simple_with_exception") {
SUBCASE("simple_with_exception") {
int i = 0;
try {
DEFER_HPP([&i]{ ++i; });
@@ -56,7 +52,7 @@ TEST_CASE("defer") {
}
TEST_CASE("error_defer") {
SECTION("simple") {
SUBCASE("simple") {
int i = 0;
{
ERROR_DEFER_HPP([&i]{ ++i; });
@@ -65,7 +61,7 @@ TEST_CASE("error_defer") {
REQUIRE(i == 0);
}
SECTION("simple_with_arg") {
SUBCASE("simple_with_arg") {
int i = 0;
{
ERROR_DEFER_HPP([](int& i){ ++i; }, std::ref(i));
@@ -74,7 +70,7 @@ TEST_CASE("error_defer") {
REQUIRE(i == 0);
}
SECTION("simple_with_args") {
SUBCASE("simple_with_args") {
int i = 0, j = 0;
{
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);
}
SECTION("simple_with_exception") {
SUBCASE("simple_with_exception") {
int i = 0;
try {
ERROR_DEFER_HPP([&i]{ ++i; });
@@ -98,7 +94,7 @@ TEST_CASE("error_defer") {
}
TEST_CASE("return_defer") {
SECTION("simple") {
SUBCASE("simple") {
int i = 0;
{
RETURN_DEFER_HPP([&i]{ ++i; });
@@ -107,7 +103,7 @@ TEST_CASE("return_defer") {
REQUIRE(i == 1);
}
SECTION("simple_with_arg") {
SUBCASE("simple_with_arg") {
int i = 0;
{
RETURN_DEFER_HPP([](int& i){ ++i; }, std::ref(i));
@@ -116,7 +112,7 @@ TEST_CASE("return_defer") {
REQUIRE(i == 1);
}
SECTION("simple_with_args") {
SUBCASE("simple_with_args") {
int i = 0, j = 0;
{
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);
}
SECTION("simple_with_exception") {
SUBCASE("simple_with_exception") {
int i = 0;
try {
RETURN_DEFER_HPP([&i]{ ++i; });

View File

@@ -0,0 +1,2 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

6260
untests/doctest/doctest.h Normal file

File diff suppressed because it is too large Load Diff

View 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__));