diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3749bf9e..b3f34183 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,8 @@ jobs: # keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare debian package run: myci-deb-prepare.sh - name: install deps @@ -114,6 +116,8 @@ jobs: apt --quiet install --assume-yes devscripts equivs - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare debian package run: myci-deb-prepare.sh - name: install deps @@ -147,6 +151,8 @@ jobs: install: myci locales git devscripts equivs - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare debian package run: myci-deb-prepare.sh - name: install deps @@ -187,6 +193,8 @@ jobs: # keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: set PACKAGE_VERSION uses: myci-actions/export-env-var@main with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh)} @@ -258,6 +266,8 @@ jobs: # keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: set PACKAGE_VERSION uses: myci-actions/export-env-var@main with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh)} @@ -347,6 +357,8 @@ jobs: rm -rf /usr/local/bin/python3*-config - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: install clang-tidy and clang-format run: | brew install llvm @@ -388,6 +400,8 @@ jobs: steps: - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: add cppfw deb repo uses: myci-actions/add-deb-repo@main with: @@ -446,6 +460,8 @@ jobs: # key-server: https://gagis.hopto.org/repo/cppfw/pubkey.gpg - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare pacman package run: myci-apply-version.sh build/msys2/PKGBUILD.in - name: build @@ -484,6 +500,8 @@ jobs: install: myci cmake git curl zip unzip tar nodejs - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: install vcpkg run: | git clone https://github.com/microsoft/vcpkg.git vcpkg-installation diff --git a/build/conan/conanfile.py b/build/conan/conanfile.py index 16174d4a..13938624 100644 --- a/build/conan/conanfile.py +++ b/build/conan/conanfile.py @@ -42,7 +42,7 @@ def source(self): # shallow fetch commit git.fetch_commit(url=sources["url"], commit=sources['commit']) # shallow clone submodules - git.run("submodule update --init --remote --depth 1") + git.run("submodule update --init --depth 1") def build(self): if self.settings.os == "Emscripten": diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index b6f2f268..b63c750a 100644 --- a/src/utki/debug.hpp +++ b/src/utki/debug.hpp @@ -32,6 +32,7 @@ SOFTWARE. #include #include #include +#include #include "config.hpp" #include "log.hpp" @@ -289,17 +290,34 @@ inline void assert( #endif +// a type invocable with no arguments, producing a value convertible to bool +#if CFG_CPP >= 20 +template +concept assert_checker = std::is_invocable_r_v; +#endif + /** * @brief Assert that condion is true. * In debug build this function invokes assert_always(). * In non-debug build this fuction does nothing. - * @param condition_checker - function which checks for condition and returns its boolean value. + * @param condition_checker - callable object (e.g. a lambda) which checks for condition + * and returns its boolean value. The checker is invoked only in debug builds. * @param print - function providing information string to print in case the assertion fails. * @param source_location - location of the assert() invocation in the source code. */ #ifdef DEBUG +template < // + class checker_type +# if CFG_CPP < 20 + , + typename std::enable_if_t, int> = 0 +# endif + > +# if CFG_CPP >= 20 +requires assert_checker +# endif inline void assert( - const std::function& condition_checker, + const checker_type& condition_checker, const std::function& print, const utki::source_location& source_location # if CFG_CPP >= 20 @@ -314,8 +332,18 @@ inline void assert( ); } #else +template < // + class checker_type +# if CFG_CPP < 20 + , + typename std::enable_if_t, int> = 0 +# endif + > +# if CFG_CPP >= 20 +requires assert_checker +# endif inline void assert( - const std::function&, + const checker_type&, const std::function&, const utki::source_location& # if CFG_CPP >= 20 @@ -351,11 +379,22 @@ inline void assert( * @brief Assert that condion is true. * In debug build this function invokes assert_always(). * In non-debug build this fuction does nothing. - * @param condition_checker - function which checks for condition and returns its boolean value. + * @param condition_checker - callable object (e.g. a lambda) which checks for condition + * and returns its boolean value. The checker is invoked only in debug builds. * @param source_location - location of the assert() invocation in the source code. */ +template < // + class checker_type +#if CFG_CPP < 20 + , + typename std::enable_if_t, int> = 0 +#endif + > +#if CFG_CPP >= 20 +requires assert_checker +#endif inline void assert( - const std::function& condition_checker, + const checker_type& condition_checker, const utki::source_location& source_location #if CFG_CPP >= 20 = std_source_location::current() @@ -364,7 +403,7 @@ inline void assert( { utki::assert( condition_checker, // - nullptr, + std::function{nullptr}, source_location ); } @@ -474,42 +513,6 @@ void assert( ); } -// std::function does not have implicit conversion to bool, so we need to define -// template overloads of the assert function for it - -template -void assert( - const std::function& p, - const std::function& print, - const utki::source_location& source_location -#if CFG_CPP >= 20 - = std_source_location::current() -#endif -) -{ - assert( - p != nullptr, // - print, - source_location - ); -} - -template -void assert( - const std::function& p, - const utki::source_location& source_location -#if CFG_CPP >= 20 - = std_source_location::current() -#endif -) -{ - assert( - p != nullptr, // - nullptr, - source_location - ); -} - } // namespace utki #ifdef DEBUG diff --git a/tests/harness/clargs b/tests/harness/clargs index 24ecdc1f..26f70055 160000 --- a/tests/harness/clargs +++ b/tests/harness/clargs @@ -1 +1 @@ -Subproject commit 24ecdc1ffb03f01cb1bd7e66309a165eabf684f2 +Subproject commit 26f700559da08bac27d91ab53fb22908bfcab941 diff --git a/tests/harness/tst b/tests/harness/tst index 94871f70..8cfcd74f 160000 --- a/tests/harness/tst +++ b/tests/harness/tst @@ -1 +1 @@ -Subproject commit 94871f7015751b974db38c1d45976bcdc536b21d +Subproject commit 8cfcd74f1feb6e2726dbb882b4a3ca876452507a diff --git a/tests/unit/src/debug.cpp b/tests/unit/src/debug.cpp index 74ad99ea..448fbf4c 100644 --- a/tests/unit/src/debug.cpp +++ b/tests/unit/src/debug.cpp @@ -58,6 +58,46 @@ const tst::set set("debug", [](tst::suite& suite) { #endif }); + suite.add("assert_with_checker_captureless", []() { + const int b = 13; + utki::assert( + [&]() { // + return b == 13; + }, + SL + ); + utki::assert( + []() { // + return 13 == 13; + }, + SL + ); +#if CFG_CPP >= 20 + utki::assert([&]() { // + return b == 13; + }); + utki::assert([]() { + return 13 == 13; + }); +#endif + }); + + suite.add("assert_with_std_function_checker", []() { + // a std::function object binds to the checker overload and is invoked + int b = 13; + int calls = 0; + const std::function checker = [&]() { // + calls++; + return b == 13; + }; + utki::assert(checker, SL); + utki::assert(calls == 1, SL); +#if CFG_CPP >= 20 + utki::assert(checker); + utki::assert(calls == 2, SL); +#endif + }); + suite.add("assert_with_message", []() { int b = 13; utki::assert(