Merge branch 'dev' into main

This commit is contained in:
BlackMATov
2021-01-12 15:51:41 +07:00
30 changed files with 6466 additions and 335 deletions

View File

@@ -7,34 +7,17 @@ platform:
- 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
- .ci\build_windows_x86.bat
-
matrix:
@@ -42,4 +25,4 @@ for:
- platform: x64
configuration: Release
build_script:
- scripts\build_release_x64.bat
- .ci\build_windows_x64.bat

19
.ci/build_coverage.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
ROOT_DIR="${DIR}/.."
BUILD_DIR="${ROOT_DIR}/build/coverage"
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake "${ROOT_DIR}" -DCMAKE_BUILD_TYPE=Debug -DBUILD_WITH_COVERAGE=ON)
(cd "${BUILD_DIR}" && cmake --build .)
(cd "${BUILD_DIR}" && lcov -d . -z)
(cd "${BUILD_DIR}" && ctest --verbose)
(cd "${BUILD_DIR}" && lcov -d . -c -o "coverage.info")
(cd "${BUILD_DIR}" && lcov -r "coverage.info" "*/usr/*" "*/untests/*" -o "coverage.info")
(cd "${BUILD_DIR}" && lcov -l "coverage.info")
bash <(curl -s https://codecov.io/bash) -f "${BUILD_DIR}/coverage.info" || echo "Codecov did not collect coverage reports"

11
.ci/build_darwin.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
ROOT_DIR="${DIR}/.."
BUILD_DIR="${ROOT_DIR}/build/darwin_release"
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake "${ROOT_DIR}" -DCMAKE_BUILD_TYPE=Release)
(cd "${BUILD_DIR}" && cmake --build .)
(cd "${BUILD_DIR}" && ctest --verbose)

11
.ci/build_linux.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
ROOT_DIR="${DIR}/.."
BUILD_DIR="${ROOT_DIR}/build/linux_release"
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake "${ROOT_DIR}" -DCMAKE_BUILD_TYPE=Release)
(cd "${BUILD_DIR}" && cmake --build .)
(cd "${BUILD_DIR}" && ctest --verbose)

19
.ci/build_windows_x64.bat Normal file
View File

@@ -0,0 +1,19 @@
@echo off
set DIR=%~dp0
set ROOT_DIR=%DIR%..\
set BUILD_DIR=%ROOT_DIR%build\windows_release_x64\
if not exist %BUILD_DIR% mkdir %BUILD_DIR% || goto :error
pushd %BUILD_DIR% || goto :error
cmake %ROOT_DIR% -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%

19
.ci/build_windows_x86.bat Normal file
View File

@@ -0,0 +1,19 @@
@echo off
set DIR=%~dp0
set ROOT_DIR=%DIR%..\
set BUILD_DIR=%ROOT_DIR%build\windows_release_x86\
if not exist %BUILD_DIR% mkdir %BUILD_DIR% || goto :error
pushd %BUILD_DIR% || goto :error
cmake %ROOT_DIR% -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%

View File

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

View File

@@ -1,143 +1,81 @@
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)
# linux (g++)
#
- os: linux
dist: xenial
dist: bionic
stage: linux
name: debug, g++-7
name: g++-7
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7"] } }
env: CC=gcc-7 CXX=g++-7
script: ./scripts/build_debug.sh
script: .ci/build_linux.sh
- os: linux
dist: xenial
dist: bionic
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
name: 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
script: .ci/build_linux.sh
#
# linux (clang++-5.0)
# linux (clang++)
#
- os: linux
dist: xenial
dist: bionic
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"] } }
name: clang++-5.0
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["clang-5.0"] } }
env: CC=clang-5.0 CXX=clang++-5.0
script: ./scripts/build_debug.sh
script: .ci/build_linux.sh
- os: linux
dist: xenial
dist: bionic
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"] } }
name: clang++-6.0
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["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
script: .ci/build_linux.sh
#
# macosx (xcode10)
# darwin
#
- 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)
#
stage: darwin
name: xcode10
script: .ci/build_darwin.sh
- os: osx
osx_image: xcode11
stage: macosx
name: debug, xcode11
script: ./scripts/build_debug.sh
stage: darwin
name: xcode11
script: .ci/build_darwin.sh
- os: osx
osx_image: xcode11
stage: macosx
name: release, xcode11
script: ./scripts/build_release.sh
#
# windows
#
- os: windows
stage: windows
name: x86
script: .ci/build_windows_x86.bat
- os: windows
stage: windows
name: x64
script: .ci/build_windows_x64.bat
#
# coverage
@@ -146,14 +84,6 @@ matrix:
- os: osx
osx_image: xcode10
stage: coverage
name: coverage, xcode10
name: coverage
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
script: .ci/build_coverage.sh

View File

@@ -11,6 +11,9 @@ add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE headers)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE Threads::Threads)
if(BUILD_AS_STANDALONE)
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
if(BUILD_WITH_UNTESTS)

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
Copyright (C) 2018-2021, 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

View File

@@ -1,13 +1,15 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2018-2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "promise.hpp"
#include <algorithm>
namespace jobber_hpp
{
using namespace promise_hpp;

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2018-2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
@@ -123,7 +123,7 @@ namespace promise_hpp
std::size_t size() const noexcept {
return (*state_).size();
}
std::exception_ptr at(std::size_t index) const {
return (*state_).at(index);
}
@@ -886,7 +886,7 @@ namespace promise_hpp
std::forward<ResolveF>(on_resolve),
std::forward<RejectF>(on_reject),
true);
return next;
}

View File

@@ -1,13 +1,15 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2018-2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "promise.hpp"
#include <algorithm>
namespace scheduler_hpp
{
using namespace promise_hpp;

View File

@@ -1,12 +0,0 @@
@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%

View File

@@ -1,5 +0,0 @@
#!/bin/bash
set -e
SCRIPT_DIR=`dirname "$BASH_SOURCE"`
$SCRIPT_DIR/build_debug.sh
$SCRIPT_DIR/build_release.sh

View File

@@ -1,9 +0,0 @@
#!/bin/bash
set -e
BUILD_DIR=`dirname "$BASH_SOURCE"`/../build
mkdir -p $BUILD_DIR/Debug
cd $BUILD_DIR/Debug
cmake -DCMAKE_BUILD_TYPE=Debug ../..
cmake --build .
ctest --verbose
cd ../..

View File

@@ -1,14 +0,0 @@
@echo off
set BUILD_DIR=%~dp0%\..\build
mkdir %BUILD_DIR%\Debug\x64 || goto :error
cd %BUILD_DIR%\Debug\x64 || goto :error
cmake ..\..\.. -A x64 || goto :error
cmake --build . --config Debug || goto :error
ctest --verbose || goto :error
cd ..\..\.. || goto :error
goto :EOF
:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

View File

@@ -1,14 +0,0 @@
@echo off
set BUILD_DIR=%~dp0%\..\build
mkdir %BUILD_DIR%\Debug\x86 || goto :error
cd %BUILD_DIR%\Debug\x86 || goto :error
cmake ..\..\.. -A Win32 || goto :error
cmake --build . --config Debug || goto :error
ctest --verbose || goto :error
cd ..\..\.. || goto :error
goto :EOF
:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

View File

@@ -1,9 +0,0 @@
#!/bin/bash
set -e
BUILD_DIR=`dirname "$BASH_SOURCE"`/../build
mkdir -p $BUILD_DIR/Release
cd $BUILD_DIR/Release
cmake -DCMAKE_BUILD_TYPE=Release ../..
cmake --build .
ctest --verbose
cd ../..

View File

@@ -1,14 +0,0 @@
@echo off
set BUILD_DIR=%~dp0%\..\build
mkdir %BUILD_DIR%\Release\x64 || goto :error
cd %BUILD_DIR%\Release\x64 || goto :error
cmake ..\..\.. -A x64 || goto :error
cmake --build . --config Release || goto :error
ctest --verbose || goto :error
cd ..\..\.. || goto :error
goto :EOF
:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

View File

@@ -1,14 +0,0 @@
@echo off
set BUILD_DIR=%~dp0%\..\build
mkdir %BUILD_DIR%\Release\x86 || goto :error
cd %BUILD_DIR%\Release\x86 || goto :error
cmake ..\..\.. -A Win32 || goto :error
cmake --build . --config Release || goto :error
ctest --verbose || goto :error
cd ..\..\.. || goto :error
goto :EOF
:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%

View File

@@ -1,17 +0,0 @@
#!/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"

View File

@@ -1,6 +1,3 @@
# 3.11 version is required for `FetchContent`
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(promise.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} promise.hpp)
@@ -32,23 +29,3 @@ target_compile_options(${PROJECT_NAME}
-Wall -Wextra -Wpedantic>)
add_test(${PROJECT_NAME} ${PROJECT_NAME})
#
# dependencies
#
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
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/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>

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

View File

@@ -1,17 +1,19 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2018-2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <promise.hpp/jobber.hpp>
#include "doctest/doctest.h"
#include <thread>
#include <numeric>
#include <iostream>
#include <cmath>
#include <cstring>
#include <promise.hpp/jobber.hpp>
namespace jb = jobber_hpp;
TEST_CASE("jobber") {
@@ -66,8 +68,8 @@ TEST_CASE("jobber") {
auto p1 = j.async([](float angle){
return std::cos(angle);
}, pi * 2);
REQUIRE(p0.get() == Approx(0.f).margin(0.01f));
REQUIRE(p1.get() == Approx(1.f).margin(0.01f));
REQUIRE(p0.get() == doctest::Approx(0.f).epsilon(0.01f));
REQUIRE(p1.get() == doctest::Approx(1.f).epsilon(0.01f));
}
{
jb::jobber j(1);
@@ -324,6 +326,6 @@ TEST_CASE("jobber") {
for ( std::size_t i = 0; i < 50; ++i ) {
r1 += std::sin(static_cast<float>(i));
}
REQUIRE(r0 == Approx(r1 * 50.f).margin(0.01f));
REQUIRE(r0 == doctest::Approx(r1 * 50.f).epsilon(0.01f));
}
}

View File

@@ -1,18 +1,17 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2018-2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <promise.hpp/promise.hpp>
#include "doctest/doctest.h"
#include <array>
#include <thread>
#include <numeric>
#include <cstring>
#include <promise.hpp/promise.hpp>
namespace pr = promise_hpp;
namespace
@@ -75,7 +74,7 @@ namespace
}
TEST_CASE("is_promise") {
SECTION("positive") {
SUBCASE("positive") {
static_assert(
pr::is_promise<pr::promise<void>>::value,
"unit test fail");
@@ -96,7 +95,7 @@ TEST_CASE("is_promise") {
pr::is_promise<const volatile pr::promise<int>>::value,
"unit test fail");
}
SECTION("negative") {
SUBCASE("negative") {
static_assert(
!pr::is_promise<pr::promise<void>&>::value,
"unit test fail");
@@ -120,7 +119,7 @@ TEST_CASE("is_promise") {
}
TEST_CASE("is_promise_r") {
SECTION("positive") {
SUBCASE("positive") {
static_assert(
pr::is_promise_r<void, pr::promise<void>>::value,
"unit test fail");
@@ -131,7 +130,7 @@ TEST_CASE("is_promise_r") {
pr::is_promise_r<double, const pr::promise<int>>::value,
"unit test fail");
}
SECTION("negative") {
SUBCASE("negative") {
static_assert(
!pr::is_promise_r<void, pr::promise<int>>::value,
"unit test fail");
@@ -148,7 +147,7 @@ TEST_CASE("is_promise_r") {
}
TEST_CASE("promise") {
SECTION("basic") {
SUBCASE("basic") {
{
auto p1 = pr::promise<int>();
auto p2 = pr::promise<int>();
@@ -194,7 +193,7 @@ TEST_CASE("promise") {
REQUIRE_FALSE(p1 == p3);
}
}
SECTION("resolved") {
SUBCASE("resolved") {
{
int check_42_int = 0;
auto p = pr::promise<int>();
@@ -226,7 +225,7 @@ TEST_CASE("promise") {
REQUIRE(check_100500_transform == 100500);
}
}
SECTION("resolved_ref") {
SUBCASE("resolved_ref") {
{
int* check_42_int = nullptr;
auto p = pr::promise<std::reference_wrapper<int>>();
@@ -250,7 +249,7 @@ TEST_CASE("promise") {
REQUIRE(*check_42_int == 42);
}
}
SECTION("rejected") {
SUBCASE("rejected") {
{
bool call_fail_with_logic_error = false;
bool not_call_then_on_reject = true;
@@ -300,7 +299,7 @@ TEST_CASE("promise") {
REQUIRE(check_multi_fail == 2);
}
}
SECTION("unresolved") {
SUBCASE("unresolved") {
{
int check_42_int = 0;
bool not_call_before_resolve = true;
@@ -334,7 +333,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("finally") {
SUBCASE("finally") {
{
bool all_is_ok = false;
auto p = pr::promise<int>();
@@ -372,7 +371,7 @@ TEST_CASE("promise") {
REQUIRE(all_is_ok);
}
}
SECTION("after_finally") {
SUBCASE("after_finally") {
{
int check_84_int = 0;
auto p = pr::promise<>();
@@ -400,7 +399,7 @@ TEST_CASE("promise") {
REQUIRE(check_84_int == 84);
}
}
SECTION("failed_finally") {
SUBCASE("failed_finally") {
{
int check_84_int = 0;
auto p = pr::promise<>();
@@ -460,7 +459,7 @@ TEST_CASE("promise") {
REQUIRE(check_84_int == 84);
}
}
SECTION("make_promise") {
SUBCASE("make_promise") {
{
int check_84_int = 0;
auto p = pr::make_promise<int>([](auto resolve, auto reject){
@@ -500,7 +499,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("make_resolved_promise") {
SUBCASE("make_resolved_promise") {
{
bool call_check = false;
pr::make_resolved_promise()
@@ -518,7 +517,7 @@ TEST_CASE("promise") {
REQUIRE(check_42_int == 42);
}
}
SECTION("make_rejected_promise") {
SUBCASE("make_rejected_promise") {
{
bool call_fail_with_logic_error = false;
pr::make_rejected_promise<int>(std::logic_error("hello fail"))
@@ -537,7 +536,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("exceptions") {
SUBCASE("exceptions") {
{
bool not_call_then_on_reject = true;
bool call_fail_with_logic_error = false;
@@ -569,7 +568,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("multi_then") {
SUBCASE("multi_then") {
{
auto p = pr::promise<int>();
@@ -631,7 +630,7 @@ TEST_CASE("promise") {
REQUIRE(pb_value == 21);
}
}
SECTION("chaining") {
SUBCASE("chaining") {
{
int check_84_int = 0;
auto p1 = pr::make_resolved_promise(42);
@@ -687,7 +686,7 @@ TEST_CASE("promise") {
REQUIRE(check_84_int == 84);
}
}
SECTION("lazy_chaining") {
SUBCASE("lazy_chaining") {
{
int check_84_int = 0;
auto p1 = pr::make_promise<int>();
@@ -707,7 +706,7 @@ TEST_CASE("promise") {
REQUIRE(check_84_int == 84);
}
}
SECTION("typed_chaining_fails") {
SUBCASE("typed_chaining_fails") {
{
bool call_fail_with_logic_error = false;
auto p1 = pr::make_resolved_promise(42);
@@ -773,7 +772,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("void_chaining_fails") {
SUBCASE("void_chaining_fails") {
{
bool call_fail_with_logic_error = false;
auto p1 = pr::make_resolved_promise();
@@ -831,7 +830,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("make_all_promise") {
SUBCASE("make_all_promise") {
{
bool all_is_ok = false;
pr::make_all_promise(std::vector<pr::promise<int>>())
@@ -913,7 +912,7 @@ TEST_CASE("promise") {
});
}
}
SECTION("make_any_promise") {
SUBCASE("make_any_promise") {
{
bool all_is_ok = false;
auto p = pr::make_any_promise(std::vector<pr::promise<int>>{});
@@ -973,7 +972,7 @@ TEST_CASE("promise") {
REQUIRE(all_is_ok);
}
}
SECTION("make_race_promise") {
SUBCASE("make_race_promise") {
{
auto p1 = pr::promise<int>();
auto p2 = pr::promise<int>();
@@ -1049,7 +1048,7 @@ TEST_CASE("promise") {
});
}
}
SECTION("make_tuple_promise") {
SUBCASE("make_tuple_promise") {
{
static_assert(
std::is_same<
@@ -1131,7 +1130,7 @@ TEST_CASE("promise") {
});
}
}
SECTION("make_all_promise_fail") {
SUBCASE("make_all_promise_fail") {
{
bool call_fail_with_logic_error = false;
bool not_call_then_on_reject = true;
@@ -1169,7 +1168,7 @@ TEST_CASE("promise") {
REQUIRE(call_except_count == 1);
}
}
SECTION("make_race_promise_fail") {
SUBCASE("make_race_promise_fail") {
{
bool call_fail_with_logic_error = false;
bool not_call_then_on_reject = true;
@@ -1186,7 +1185,7 @@ TEST_CASE("promise") {
REQUIRE(call_fail_with_logic_error);
}
}
SECTION("make_tuple_promise_fail") {
SUBCASE("make_tuple_promise_fail") {
{
auto p1 = pr::promise<int>();
auto p2 = pr::make_tuple_promise(std::make_tuple(p1));
@@ -1224,7 +1223,7 @@ TEST_CASE("promise") {
REQUIRE_THROWS_AS(p3.get(), std::logic_error);
}
}
SECTION("then_all") {
SUBCASE("then_all") {
{
int check_42_int = 0;
pr::make_resolved_promise()
@@ -1257,7 +1256,7 @@ TEST_CASE("promise") {
REQUIRE(check_42_int2 == 42);
}
}
SECTION("then_race") {
SUBCASE("then_race") {
{
int check_42_int = 0;
pr::make_resolved_promise()
@@ -1302,7 +1301,7 @@ TEST_CASE("promise") {
REQUIRE(call_then_only_once == 1);
}
}
SECTION("then_tuple") {
SUBCASE("then_tuple") {
{
float check_42_float = 0.f;
pr::make_resolved_promise()
@@ -1313,7 +1312,7 @@ TEST_CASE("promise") {
}).then([&check_42_float](const std::tuple<int, float>& t){
check_42_float = std::get<0>(t) + std::get<1>(t);
});
REQUIRE(check_42_float == Approx(42.f).margin(0.01f));
REQUIRE(check_42_float == doctest::Approx(42.f).epsilon(0.01f));
}
{
float check_42_float = 0.f;
@@ -1325,7 +1324,7 @@ TEST_CASE("promise") {
}).then([&check_42_float](const std::tuple<int, float>& t){
check_42_float = std::get<0>(t) + std::get<1>(t);
});
REQUIRE(check_42_float == Approx(42.f).margin(0.01f));
REQUIRE(check_42_float == doctest::Approx(42.f).epsilon(0.01f));
}
{
bool call_fail_with_logic_error = false;
@@ -1344,7 +1343,7 @@ TEST_CASE("promise") {
}
TEST_CASE("get_and_wait") {
SECTION("get_void_promises") {
SUBCASE("get_void_promises") {
{
auto p = pr::make_resolved_promise();
REQUIRE_NOTHROW(p.get());
@@ -1416,7 +1415,7 @@ TEST_CASE("get_and_wait") {
== pr::promise_wait_status::no_timeout);
}
}
SECTION("get_typed_promises") {
SUBCASE("get_typed_promises") {
{
auto p = pr::make_resolved_promise(42);
REQUIRE(p.get() == 42);
@@ -1471,7 +1470,7 @@ TEST_CASE("get_and_wait") {
REQUIRE(p.get() == 42);
}
}
SECTION("get_or_default") {
SUBCASE("get_or_default") {
{
auto p = pr::make_resolved_promise(42);
REQUIRE(p.get_or_default(84) == 42);
@@ -1548,7 +1547,7 @@ TEST_CASE("promise_transformations") {
std::is_same<decltype(p_d)::value_type, double>::value,
"unit test fail");
}
SECTION("after_except") {
SUBCASE("after_except") {
{
auto p_v = pr::promise<int>()
.then([](int)->int{

View File

@@ -1,17 +1,19 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/promise.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2018-2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <promise.hpp/scheduler.hpp>
#include "doctest/doctest.h"
#include <thread>
#include <numeric>
#include <iostream>
#include <cmath>
#include <cstring>
#include <promise.hpp/scheduler.hpp>
namespace sd = scheduler_hpp;
TEST_CASE("scheduler") {