Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/conan/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
87 changes: 45 additions & 42 deletions src/utki/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SOFTWARE.
#include <functional>
#include <memory>
#include <sstream>
#include <type_traits>

#include "config.hpp"
#include "log.hpp"
Expand Down Expand Up @@ -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 <class checker_type>
concept assert_checker = std::is_invocable_r_v<bool, const checker_type&>;
#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<std::is_invocable_r_v<bool, const checker_type&>, int> = 0
# endif
>
# if CFG_CPP >= 20
requires assert_checker<checker_type>
# endif
inline void assert(
const std::function<bool()>& condition_checker,
const checker_type& condition_checker,
const std::function<void(std::ostream&)>& print,
const utki::source_location& source_location
# if CFG_CPP >= 20
Expand All @@ -314,8 +332,18 @@ inline void assert(
);
}
#else
template < //
class checker_type
# if CFG_CPP < 20
,
typename std::enable_if_t<std::is_invocable_r_v<bool, const checker_type&>, int> = 0
# endif
>
# if CFG_CPP >= 20
requires assert_checker<checker_type>
# endif
inline void assert(
const std::function<bool()>&,
const checker_type&,
const std::function<void(std::ostream&)>&,
const utki::source_location&
# if CFG_CPP >= 20
Expand Down Expand Up @@ -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<std::is_invocable_r_v<bool, const checker_type&>, int> = 0
#endif
>
#if CFG_CPP >= 20
requires assert_checker<checker_type>
#endif
inline void assert(
const std::function<bool()>& condition_checker,
const checker_type& condition_checker,
const utki::source_location& source_location
#if CFG_CPP >= 20
= std_source_location::current()
Expand All @@ -364,7 +403,7 @@ inline void assert(
{
utki::assert(
condition_checker, //
nullptr,
std::function<void(std::ostream&)>{nullptr},
source_location
);
}
Expand Down Expand Up @@ -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 <class func_type>
void assert(
const std::function<func_type>& p,
const std::function<void(std::ostream&)>& print,
const utki::source_location& source_location
#if CFG_CPP >= 20
= std_source_location::current()
#endif
)
{
assert(
p != nullptr, //
print,
source_location
);
}

template <class func_type>
void assert(
const std::function<func_type>& 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
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool()> object binds to the checker overload and is invoked
int b = 13;
int calls = 0;
const std::function<bool()> 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(
Expand Down
Loading