userver: userver/utest/impl/assert_macros.hpp Source File
Loading...
Searching...
No Matches
assert_macros.hpp
1#pragma once
2
3#include <exception>
4#include <functional>
5#include <string>
6#include <string_view>
7#include <type_traits>
8#include <typeinfo>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace utest::impl {
13
14template <typename ExceptionType>
15bool IsSubtype(const std::exception& ex) noexcept {
16 static_assert(
17 std::is_base_of_v<std::exception, ExceptionType>,
18 "Exception types not inherited from std::exception are not supported");
19 if constexpr (std::is_same_v<ExceptionType, std::exception>) {
20 return true;
21 } else {
22 return dynamic_cast<const ExceptionType*>(&ex) != nullptr;
23 }
24}
25
26std::string AssertThrow(std::function<void()> statement,
27 std::string_view statement_text,
28 std::function<bool(const std::exception&)> type_checker,
29 const std::type_info& expected_type,
30 std::string_view message_substring);
31
32std::string AssertNoThrow(std::function<void()> statement,
33 std::string_view statement_text);
34
35} // namespace utest::impl
36
37USERVER_NAMESPACE_END