16#include "sequoia/PlatformSpecific/Preprocessor.hpp"
20#include <source_location>
22namespace sequoia::testing
29 constexpr explicit line_breaks(std::size_t n) : m_Breaks{n}
33 constexpr std::size_t value()
const noexcept
38 std::size_t m_Breaks{};
42 consteval line_breaks operator ""_linebreaks(
unsigned long long int n)
noexcept
48 std::string emphasise(std::string_view s);
51 inline constexpr bool is_character_v{
52 std::is_same_v<std::remove_cvref_t<Char>,
char>
53 || std::is_same_v<std::remove_cvref_t<Char>,
wchar_t>
54 || std::is_same_v<std::remove_cvref_t<Char>,
char8_t>
55 || std::is_same_v<std::remove_cvref_t<Char>,
char16_t>
56 || std::is_same_v<std::remove_cvref_t<Char>,
char32_t>
60 requires is_character_v<Char>
62 std::string display_character(Char c)
64 if(c ==
'\a')
return "'\\a'";
65 if(c ==
'\b')
return "'\\b'";
66 if(c ==
'\f')
return "'\\f'";
67 if(c ==
'\n')
return "'\\n'";
68 if(c ==
'\r')
return "'\\r'";
69 if(c ==
'\t')
return "'\\t'";
70 if(c ==
'\v')
return "'\\v'";
71 if(c ==
'\0')
return "'\\0'";
72 if(c ==
' ')
return "' '";
74 return std::string(1,
static_cast<char>(c));
77 void end_block(std::string& s, line_breaks newlines, std::string_view footer=
"");
80 std::string end_block(std::string_view s, line_breaks newlines, std::string_view footer=
"");
83 std::string exception_message(std::string_view tag,
84 const std::filesystem::path& filename,
85 const uncaught_exception_info& info,
86 std::string_view exceptionMessage);
89 std::string operator_message(std::string_view op, std::string_view retVal);
92 std::string nullable_type_message(
bool obtainedHoldsValue,
bool predictedHoldsValue);
95 std::string equality_operator_failure_message();
98 std::string pointer_prediction_message();
101 std::string default_prediction_message(std::string_view obtained, std::string_view prediction);
104 std::string prediction_message(
const std::string& obtained,
const std::string& prediction);
107 requires is_character_v<Char>
109 std::string prediction_message(Char obtained, Char prediction)
111 return prediction_message(display_character(obtained), display_character(prediction));
115 requires std::is_pointer_v<Ptr> || is_const_pointer_v<Ptr>
117 std::string prediction_message(Ptr obtained, Ptr prediction)
119 return (obtained && prediction) ? pointer_prediction_message() : nullable_type_message(obtained, prediction);
122 template<serializable T>
123 requires (!is_character_v<T> && !std::is_pointer_v<T> && !is_const_pointer_v<T>)
125 std::string prediction_message(
const T& obtained,
const T& prediction)
127 return default_prediction_message(to_string(obtained), to_string(prediction));
130 template<
bool IsFinalMessage>
137 inline constexpr is_not_final_message_t is_not_final_message{};
143 template<reportable T>
144 requires std::is_same_v<T, bool>
148 return "check failed";
151 template<reportable T>
152 requires (!std::is_same_v<T, bool>)
154 std::string failure_message(is_final_message_t,
const T& obtained,
const T& prediction)
156 auto message{equality_operator_failure_message()};
158 append_lines(message, prediction_message(obtained, prediction));
165 std::string
failure_message(is_not_final_message_t,
const T&,
const T&)
167 return equality_operator_failure_message();
171 std::string footer();
174 std::string instability_footer();
177 std::string report_line(std::string_view message,
const std::filesystem::path& repository,
const std::source_location loc);
180 std::filesystem::path path_for_reporting(
const std::filesystem::path& file,
const std::filesystem::path& repository);
188 reporter(
const char* message,
const std::source_location loc = std::source_location::current())
189 :
reporter{std::string{message},loc}
192 reporter(std::string_view message,
const std::source_location loc = std::source_location::current())
193 :
reporter{std::string{message},loc}
196 reporter(std::string message,
const std::source_location loc = std::source_location::current())
197 : m_Message{std::move(message)}
202 : m_Message{std::move(message)}
206 :
reporter{std::string{message}, no_source_location}
210 const std::string& message()
const noexcept {
return m_Message; }
213 const std::optional<std::source_location>& location()
const noexcept {
return m_Loc; }
215 std::string m_Message{};
216 std::optional<std::source_location> m_Loc{};
220 std::string tidy_name(std::string name, clang_type);
223 std::string tidy_name(std::string name, gcc_type);
226 std::string tidy_name(std::string name, msvc_type);
229 std::string tidy_name(std::string name, other_compiler_type);
232 std::string demangle(std::string mangled);
234 template<
class T, invocable_r<std::
string, std::
string> T
idy>
236 std::string demangle(Tidy tidy)
238 return tidy(demangle({
typeid(T).name()}));
243 std::string demangle()
245 return demangle<type_normalizer_t<T>>([](std::string name) -> std::string {
return tidy_name(name, compiler_constant{}); });
258 static std::string make()
260 return demangle<T>();
266 template<
class T,
class... U>
270 static std::string make()
273 if constexpr(
sizeof...(U) > 0)
283 template<
class T,
class... U>
285 std::string make_type_info()
287 return std::string{
"["}.append(type_list_demangler<T, U...>::make()).append(
"]");
290 template<
class T,
class... U>
292 std::string add_type_info(std::string description)
294 return append_lines(std::move(description), make_type_info<T, U...>());
Core declarations / definitions used in the testing framework.
A collection of functions for formatting test output.
std::string failure_message(is_final_message_t, T, T)
To prevent implicit conversions to bool.
Definition: Output.hpp:146
Definition: Output.hpp:25
Definition: Output.hpp:186
Definition: Output.hpp:140
Definition: CoreInfrastructure.hpp:54
Definition: Output.hpp:131
Definition: Output.hpp:182
Specialize this struct template to customize the way in which type info is generated for a given clas...
Definition: Output.hpp:256
Demangles T; if U... is not empty, appends each demangled element of U on a new line.
Definition: Output.hpp:268