AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
assert.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2020 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-ut-export.hpp"
23
24#include <string>
25#include <string_view>
26#include <format>
27#include <source_location>
28#include <concepts>
29#include <type_traits>
30#include <iostream>
31#include <optional>
32#include <list>
33#include <set>
34#include <vector>
35#include <memory>
36
37namespace anch::ut {
38
52 template<typename... T>
54
56 std::format_string<const T&...> format;
57
59 std::source_location location;
60
69 template<typename S>
70 requires std::convertible_to<const S&, std::string_view>
71 consteval AssertMessage(const S& fmt, std::source_location loc = std::source_location::current());
72
73 };
74
83 [[noreturn]]
84 ANCH_UT_EXPORT void fail(std::string_view message = "", const std::source_location& location = std::source_location::current());
85
95 void assertTrue(bool check, std::string_view message = "", const std::source_location& location = std::source_location::current());
96
106 void assertFalse(bool check, std::string_view message = "", const std::source_location& location = std::source_location::current());
107
121 template<typename... T>
122 void assertThat(bool check, std::type_identity_t<anch::ut::AssertMessage<T...>> message, const T&... args);
123
136 template<typename T>
137 bool equals(const char* const field, const std::set<T>& expected, const std::set<T>& value, std::ostream& out = std::cout);
138
151 template<typename T>
152 bool equals(const char* const field, const std::list<T>& expected, const std::list<T>& value, std::ostream& out = std::cout);
153
166 template<typename T>
167 bool equals(const char* const field, const std::vector<T>& expected, const std::vector<T>& value, std::ostream& out = std::cout);
168
181 template<typename T>
182 bool equals(const char* const field, const std::optional<T>& expected, const std::optional<T>& value, std::ostream& out = std::cout);
183
196 template<typename T>
197 bool equals(const char* const field, const std::shared_ptr<T>& expected, const std::shared_ptr<T>& value, std::ostream& out = std::cout);
198
212 template<typename T>
213 bool equalsPtr(const char* const field, const T* const expected, const T* const value, std::ostream& out = std::cout);
214
227 template<typename T>
228 bool equals(const char* const field, const T& expected, const T& value, std::ostream& out = std::cout);
229
230} // anch::ut
231
232#include "ut/impl/assert.hpp"
AnCH unit tests library namespace.
Definition assert.hpp:37
void fail(std::string_view message="", const std::source_location &location=std::source_location::current())
void assertFalse(bool check, std::string_view message="", const std::source_location &location=std::source_location::current())
bool equals(const char *const field, const std::set< T > &expected, const std::set< T > &value, std::ostream &out=std::cout)
bool equalsPtr(const char *const field, const T *const expected, const T *const value, std::ostream &out=std::cout)
void assertTrue(bool check, std::string_view message="", const std::source_location &location=std::source_location::current())
void assertThat(bool check, std::type_identity_t< anch::ut::AssertMessage< T... > > message, const T &... args)
Assertion message with its location.
Definition assert.hpp:53
consteval AssertMessage(const S &fmt, std::source_location loc=std::source_location::current())
std::source_location location
Definition assert.hpp:59
std::format_string< const T &... > format
Definition assert.hpp:56