assert.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "crucible/core/assert.hpp" #include "crucible/core/console.hpp" #include "crucible/core/string.hpp" #include <cstring> #include <exception> namespace crucible::core { // General note: we do the gymnastics with taking `char[]` parameters and converting them // internally to `String_View` to avoid a dependency cycle between `string.hpp` and `assert.hpp`. // Since assertions are generally very low-level, we should have as few interface-exposed // dependencies (i.e., inclusions of other Crucible code) from `assert.hpp` as possible. auto fail_assertion(char const *file_data, std::size_t const file_size, int const line, char const *function_data, std::size_t const function_size) -> void { String_View const file { file_data, file_size }; String_View const function { function_data, function_size }; auto const truncated_file { file.strip_prefix(CRUCIBLE_SOURCE_ROOT) }; print_error_line(); print_error_line("ASSERTION FAILED"); print_error_line("────────────────"); print_error_line("Location: {}:{} [{}]", truncated_file, line, function); std::terminate(); } auto fail_assertion(char const *actual_data, std::size_t const actual_size, char const *expected_data, std::size_t const expected_size, char const *file_data, std::size_t const file_size, int const line, char const *function_data, std::size_t const function_size) -> void { String_View const actual { actual_data, actual_size }; String_View const expected { expected_data, expected_size }; String_View const file { file_data, file_size }; String_View const function { function_data, function_size }; auto const truncated_file { file.strip_prefix(CRUCIBLE_SOURCE_ROOT) }; print_error_line(); print_error_line("ASSERTION FAILED"); print_error_line("────────────────"); print_error_line("Location: {}:{} [{}]", truncated_file, line, function); print_error_line("Expected: {} to be {}", actual, expected); std::terminate(); } auto fail_assertion(char const *lhs_data, std::size_t const lhs_size, char const *rhs_data, std::size_t const rhs_size, char const *operation_data, std::size_t const operation_size, char const *file_data, std::size_t const file_size, int const line, char const *function_data, std::size_t const function_size) -> void { String_View const lhs { lhs_data, lhs_size }; String_View const rhs { rhs_data, rhs_size }; String_View const operation { operation_data, operation_size }; String_View const file { file_data, file_size }; String_View const function { function_data, function_size }; auto const truncated_file { file.strip_prefix(CRUCIBLE_SOURCE_ROOT) }; print_error_line(); print_error_line("ASSERTION FAILED"); print_error_line("────────────────"); print_error_line("Location: {}:{} [{}]", truncated_file, line, function); print_error_line("Expected: {} {} {}", lhs, operation, rhs); std::terminate(); } auto fail_assertion(char const *value_data, std::size_t const value_size, char const *minimum_data, std::size_t const minimum_size, char const *maximum_data, std::size_t const maximum_size, char const *constraint_data, std::size_t const constraint_size, char const *file_data, std::size_t const file_size, int const line, char const *function_data, std::size_t const function_size) -> void { String_View const value { value_data, value_size }; String_View const minimum { minimum_data, minimum_size }; String_View const maximum { maximum_data, maximum_size }; String_View const constraint { constraint_data, constraint_size }; String_View const file { file_data, file_size }; String_View const function { function_data, function_size }; auto const truncated_file { file.strip_prefix(CRUCIBLE_SOURCE_ROOT) }; print_error_line(); print_error_line("ASSERTION FAILED"); print_error_line("────────────────"); print_error_line("Location: {}:{} [{}]", truncated_file, line, function); print_error_line("Expected: {} to be {} the range [{}, {}]", value, constraint, minimum, maximum); std::terminate(); } }