doctest instead catch2

This commit is contained in:
BlackMATov
2020-12-01 06:03:19 +07:00
parent 5ce2cfb048
commit 01a461d682
11 changed files with 6315 additions and 105 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 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

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (C) 2017-2019, by Matvey Cherevko (blackmatov@gmail.com) Copyright (C) 2017-2020, by Matvey Cherevko (blackmatov@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
* This file is part of the "https://github.com/BlackMATov/kari.hpp" * This file is part of the "https://github.com/BlackMATov/kari.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md * For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2017-2019, by Matvey Cherevko (blackmatov@gmail.com) * Copyright (C) 2017-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/ ******************************************************************************/
#pragma once #pragma once

View File

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

View File

@@ -1,6 +1,3 @@
# 3.11 version is required for `FetchContent`
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(kari.hpp.untests) project(kari.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} kari.hpp) target_link_libraries(${PROJECT_NAME} kari.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()

View File

@@ -1,9 +0,0 @@
/*******************************************************************************
* This file is part of the "https://github.com/BlackMATov/kari.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2017-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,13 +1,11 @@
/******************************************************************************* /*******************************************************************************
* This file is part of the "https://github.com/BlackMATov/kari.hpp" * This file is part of the "https://github.com/BlackMATov/kari.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md * For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2017-2019, by Matvey Cherevko (blackmatov@gmail.com) * Copyright (C) 2017-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/ ******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <kari.hpp/kari.hpp> #include <kari.hpp/kari.hpp>
#include "doctest/doctest.hpp"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@@ -197,7 +195,7 @@ namespace
using namespace kari; using namespace kari;
TEST_CASE("kari_feature") { TEST_CASE("kari_feature") {
SECTION("underscore") { SUBCASE("underscore") {
using namespace kari::underscore; using namespace kari::underscore;
REQUIRE((-_)(40) == -40); REQUIRE((-_)(40) == -40);
@@ -234,7 +232,7 @@ TEST_CASE("kari_feature") {
REQUIRE_FALSE((_ == _)(42,40)); REQUIRE_FALSE((_ == _)(42,40));
REQUIRE_FALSE((_ != _)(42,42)); REQUIRE_FALSE((_ != _)(42,42));
} }
SECTION("ref_functor") { SUBCASE("ref_functor") {
REQUIRE(curry(minus3_gf())(1,2,3) == -4); REQUIRE(curry(minus3_gf())(1,2,3) == -4);
{ {
auto gf1 = id_gf(); auto gf1 = id_gf();
@@ -253,7 +251,7 @@ TEST_CASE("kari_feature") {
REQUIRE(curry(gf3)(1,2,3) == -4); REQUIRE(curry(gf3)(1,2,3) == -4);
} }
} }
SECTION("ref_forwarding") { SUBCASE("ref_forwarding") {
{ {
int i = 42; int i = 42;
const int& g = curry([](const int& v, int){ const int& g = curry([](const int& v, int){
@@ -269,7 +267,7 @@ TEST_CASE("kari_feature") {
REQUIRE(&i == &g); REQUIRE(&i == &g);
} }
} }
SECTION("move_vs_copy") { SUBCASE("move_vs_copy") {
{ {
box::resetCounters(); box::resetCounters();
const auto b1 = box(1); const auto b1 = box(1);
@@ -366,7 +364,7 @@ TEST_CASE("kari_feature") {
REQUIRE(box::copyCount() == 15); REQUIRE(box::copyCount() == 15);
} }
} }
SECTION("persistent") { SUBCASE("persistent") {
auto c = curry(minus3_gl); auto c = curry(minus3_gl);
auto c10 = c(box(10)); auto c10 = c(box(10));
@@ -392,14 +390,14 @@ TEST_CASE("kari_feature") {
} }
TEST_CASE("kari") { TEST_CASE("kari") {
SECTION("arity/min_arity") { SUBCASE("arity/min_arity") {
REQUIRE(curry(minus3_gl).min_arity() == 0); REQUIRE(curry(minus3_gl).min_arity() == 0);
REQUIRE(curryV(plusV_gf()).min_arity() == std::numeric_limits<std::size_t>::max()); REQUIRE(curryV(plusV_gf()).min_arity() == std::numeric_limits<std::size_t>::max());
REQUIRE(curryN<3>(plusV_gf()).min_arity() == 3); REQUIRE(curryN<3>(plusV_gf()).min_arity() == 3);
REQUIRE(curryN<3>(plusV_gf())(1).min_arity() == 2); REQUIRE(curryN<3>(plusV_gf())(1).min_arity() == 2);
REQUIRE(curryN<3>(plusV_gf())(1)(2).min_arity() == 1); REQUIRE(curryN<3>(plusV_gf())(1)(2).min_arity() == 1);
} }
SECTION("arity/recurring") { SUBCASE("arity/recurring") {
constexpr auto max_size_t = std::numeric_limits<std::size_t>::max(); constexpr auto max_size_t = std::numeric_limits<std::size_t>::max();
{ {
REQUIRE(curry(curry(minus3_gl)).min_arity() == 0); REQUIRE(curry(curry(minus3_gl)).min_arity() == 0);
@@ -417,7 +415,7 @@ TEST_CASE("kari") {
REQUIRE(curryN<2>(curryN<3>(plusV_gf())).min_arity() == 2); REQUIRE(curryN<2>(curryN<3>(plusV_gf())).min_arity() == 2);
} }
} }
SECTION("is_curried") { SUBCASE("is_curried") {
static_assert(!is_curried_v<void(int)>, "static unit test error"); static_assert(!is_curried_v<void(int)>, "static unit test error");
static_assert(!is_curried_v<decltype(minus2_gl)>, "static unit test error"); static_assert(!is_curried_v<decltype(minus2_gl)>, "static unit test error");
static_assert(is_curried_v<decltype(curry(minus2_gl))>, "static unit test error"); static_assert(is_curried_v<decltype(curry(minus2_gl))>, "static unit test error");
@@ -436,18 +434,18 @@ TEST_CASE("kari") {
REQUIRE(c10_2_3.v() == 5); REQUIRE(c10_2_3.v() == 5);
} }
SECTION("typed_lambdas/simple") { SUBCASE("typed_lambdas/simple") {
REQUIRE(curry(_42_tl) == 42); REQUIRE(curry(_42_tl) == 42);
REQUIRE(curry(id_tl)(42) == 42); REQUIRE(curry(id_tl)(42) == 42);
REQUIRE(curry(minus2_tl)(8,4) == 4); REQUIRE(curry(minus2_tl)(8,4) == 4);
REQUIRE(curry(minus3_tl)(8,5,2) == 1); REQUIRE(curry(minus3_tl)(8,5,2) == 1);
} }
SECTION("typed_lambdas/one_by_one_calling") { SUBCASE("typed_lambdas/one_by_one_calling") {
REQUIRE(curry(id_tl)(42) == 42); REQUIRE(curry(id_tl)(42) == 42);
REQUIRE(curry(minus2_tl)(8)(4) == 4); REQUIRE(curry(minus2_tl)(8)(4) == 4);
REQUIRE(curry(minus3_tl)(8)(5)(2) == 1); REQUIRE(curry(minus3_tl)(8)(5)(2) == 1);
} }
SECTION("typed_lambdas/combined_calling") { SUBCASE("typed_lambdas/combined_calling") {
REQUIRE(curry(minus3_tl)(8,5)(2) == 1); REQUIRE(curry(minus3_tl)(8,5)(2) == 1);
REQUIRE(curry(minus3_tl)(8)(5,2) == 1); REQUIRE(curry(minus3_tl)(8)(5,2) == 1);
@@ -458,17 +456,17 @@ TEST_CASE("kari") {
REQUIRE(curry(minus4_tl)(14,2,3)(4) == 5); REQUIRE(curry(minus4_tl)(14,2,3)(4) == 5);
REQUIRE(curry(minus4_tl)(14)(2,3,4) == 5); REQUIRE(curry(minus4_tl)(14)(2,3,4) == 5);
} }
SECTION("generic_lambdas/simple") { SUBCASE("generic_lambdas/simple") {
REQUIRE(curry(id_gl)(42) == 42); REQUIRE(curry(id_gl)(42) == 42);
REQUIRE(curry(minus2_gl)(8,4) == 4); REQUIRE(curry(minus2_gl)(8,4) == 4);
REQUIRE(curry(minus3_gl)(8,5,2) == 1); REQUIRE(curry(minus3_gl)(8,5,2) == 1);
} }
SECTION("generic_lambdas/one_by_one_calling") { SUBCASE("generic_lambdas/one_by_one_calling") {
REQUIRE(curry(id_gl)(42) == 42); REQUIRE(curry(id_gl)(42) == 42);
REQUIRE(curry(minus2_gl)(8)(4) == 4); REQUIRE(curry(minus2_gl)(8)(4) == 4);
REQUIRE(curry(minus3_gl)(8)(5)(2) == 1); REQUIRE(curry(minus3_gl)(8)(5)(2) == 1);
} }
SECTION("generic_lambdas/combined_calling") { SUBCASE("generic_lambdas/combined_calling") {
REQUIRE(curry(minus3_gl)(8,5)(2) == 1); REQUIRE(curry(minus3_gl)(8,5)(2) == 1);
REQUIRE(curry(minus3_gl)(8)(5,2) == 1); REQUIRE(curry(minus3_gl)(8)(5,2) == 1);
@@ -479,7 +477,7 @@ TEST_CASE("kari") {
REQUIRE(curry(minus4_gl)(14,2,3)(4) == 5); REQUIRE(curry(minus4_gl)(14,2,3)(4) == 5);
REQUIRE(curry(minus4_gl)(14)(2,3,4) == 5); REQUIRE(curry(minus4_gl)(14)(2,3,4) == 5);
} }
SECTION("nested_lambdas/full_apply") { SUBCASE("nested_lambdas/full_apply") {
{ {
REQUIRE(curry([](){ REQUIRE(curry([](){
return _42_tl; return _42_tl;
@@ -524,7 +522,7 @@ TEST_CASE("kari") {
})(9)(4,3) == 2); })(9)(4,3) == 2);
} }
} }
SECTION("variadic_functions") { SUBCASE("variadic_functions") {
{ {
const auto c = curry(plusV_gf()); const auto c = curry(plusV_gf());
REQUIRE(c(15) == 15); REQUIRE(c(15) == 15);
@@ -553,7 +551,7 @@ TEST_CASE("kari") {
REQUIRE(std::strcmp("37 + 5 = 42", buffer) == 0); REQUIRE(std::strcmp("37 + 5 = 42", buffer) == 0);
} }
} }
SECTION("variadic_functions/recurring") { SUBCASE("variadic_functions/recurring") {
{ {
auto c0 = curry(curry(plusV_gf())); auto c0 = curry(curry(plusV_gf()));
auto c1 = curry(curryV(plusV_gf())); auto c1 = curry(curryV(plusV_gf()));
@@ -586,7 +584,7 @@ TEST_CASE("kari") {
REQUIRE(c1(40,2) == 42); REQUIRE(c1(40,2) == 42);
} }
} }
SECTION("member_functions") { SUBCASE("member_functions") {
{ {
auto c0 = curry(&box::addV); auto c0 = curry(&box::addV);
auto c1 = curry(&box::v); auto c1 = curry(&box::v);
@@ -610,7 +608,7 @@ TEST_CASE("kari") {
REQUIRE(c1(&b2) == 10); REQUIRE(c1(&b2) == 10);
} }
} }
SECTION("member_objects") { SUBCASE("member_objects") {
struct box2 : box { struct box2 : box {
box2(int v) : box(v), ov(v) {} box2(int v) : box(v), ov(v) {}
int ov; int ov;
@@ -627,10 +625,10 @@ TEST_CASE("kari") {
} }
TEST_CASE("kari_helpers") { TEST_CASE("kari_helpers") {
SECTION("fid") { SUBCASE("fid") {
REQUIRE(fid(box(10)).v() == 10); REQUIRE(fid(box(10)).v() == 10);
} }
SECTION("fconst") { SUBCASE("fconst") {
REQUIRE(fconst(box(10), 20).v() == 10); REQUIRE(fconst(box(10), 20).v() == 10);
{ {
auto b10 = fconst(box(10)); auto b10 = fconst(box(10));
@@ -639,17 +637,17 @@ TEST_CASE("kari_helpers") {
REQUIRE(b10(20).v() == 100500); REQUIRE(b10(20).v() == 100500);
} }
} }
SECTION("fflip") { SUBCASE("fflip") {
REQUIRE(fflip(curry(std::minus<>()))(10, 20) == 10); REQUIRE(fflip(curry(std::minus<>()))(10, 20) == 10);
REQUIRE(fflip(minus3_gl)(10,20,50) == -40); REQUIRE(fflip(minus3_gl)(10,20,50) == -40);
} }
SECTION("fpipe") { SUBCASE("fpipe") {
using namespace kari::underscore; using namespace kari::underscore;
REQUIRE(fpipe(_+2, _*2, 4) == 12); REQUIRE(fpipe(_+2, _*2, 4) == 12);
REQUIRE(((_+2) | (_*2) | 4) == 12); REQUIRE(((_+2) | (_*2) | 4) == 12);
REQUIRE((4 | (_+2) | (_*2)) == 12); REQUIRE((4 | (_+2) | (_*2)) == 12);
} }
SECTION("fcompose") { SUBCASE("fcompose") {
using namespace kari::underscore; using namespace kari::underscore;
REQUIRE(fcompose(_+2, _*2, 4) == 10); REQUIRE(fcompose(_+2, _*2, 4) == 10);
REQUIRE((_+2) * (_*2) * 4 == 10); REQUIRE((_+2) * (_*2) * 4 == 10);
@@ -695,7 +693,7 @@ namespace kari_regression {
} }
TEST_CASE("kari_regression") { TEST_CASE("kari_regression") {
SECTION("change_type_after_applying") { SUBCASE("change_type_after_applying") {
using namespace kari_regression::change_type_after_applying; using namespace kari_regression::change_type_after_applying;
const auto f3 = [](int& v1, int v2, int v3){ const auto f3 = [](int& v1, int v2, int v3){
return v1 + v2 + v3; return v1 + v2 + v3;
@@ -709,7 +707,7 @@ TEST_CASE("kari_regression") {
typename first_type<decltype(c2)>::type typename first_type<decltype(c2)>::type
>::value,"static unit test error"); >::value,"static unit test error");
} }
SECTION("curryN_already_curried_function") { SUBCASE("curryN_already_curried_function") {
auto c = curryN<3>(plusV_gf()); auto c = curryN<3>(plusV_gf());
auto c2 = curryN<3>(c); auto c2 = curryN<3>(c);
REQUIRE(c2(1,2,3) == 6); REQUIRE(c2(1,2,3) == 6);