File | Lines added | Lines deleted |
---|---|---|
asserter/src/asserter.cpp | 15 | 8 |
asserter/src/asserter.h | 5 | 3 |
asserter/src/asserter.hxx | 1 | 1 |
asserter/test/src/check_assert.cpp | 0 | 1 |
File asserter/src/asserter.cpp changed (mode: 100644) (index fb5c2e1..379f1e5) | |||
... | ... | asserter_t::asserter_t(bool value) | |
19 | 19 | , m_value(value) | , m_value(value) |
20 | 20 | { | { |
21 | 21 | } | } |
22 | ///////////////////////////////////////////////////////////////////////////////////////////// | ||
23 | const char* asserter_t::code_red() | ||
24 | { | ||
25 | return "\x1b[31m"; | ||
26 | } | ||
27 | |||
28 | ///////////////////////////////////////////////////////////////////////////////////////////// | ||
29 | const char* asserter_t::code_reset() | ||
30 | { | ||
31 | return "\x1b[39;49m"; | ||
32 | } | ||
22 | 33 | ||
23 | 34 | ///////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////// |
24 | 35 | bool asserter_t::pass() const | bool asserter_t::pass() const |
... | ... | const asserter_t& asserter_t::print_message( | |
33 | 44 | const char* function, | const char* function, |
34 | 45 | const char* message) const | const char* message) const |
35 | 46 | { | { |
36 | static const char* code_red("\x1b[31m"); | ||
37 | static const char* code_reset("\x1b[39;49m"); | ||
38 | |||
39 | 47 | using namespace std; | using namespace std; |
40 | 48 | ||
41 | 49 | if (!pass()) { | if (!pass()) { |
42 | cout << code_red | ||
43 | << "assertion failed: " << message << endl | ||
44 | << "file: " << file << endl | ||
45 | << "line: " << line << endl | ||
50 | cout << code_red() | ||
51 | << file << ":" << line << ": " | ||
52 | << "assert failed: " << message << endl | ||
46 | 53 | << "function: " << function | << "function: " << function |
47 | << code_reset << endl; | ||
54 | << code_reset() << endl; | ||
48 | 55 | } | } |
49 | 56 | return *this; | return *this; |
50 | 57 | } | } |
File asserter/src/asserter.h changed (mode: 100644) (index 0f8a8de..74d8f2a) | |||
20 | 20 | } local_obj = asserter_t(false) | } local_obj = asserter_t(false) |
21 | 21 | ||
22 | 22 | // asserter_t | // asserter_t |
23 | class asserter_t { | ||
24 | public: | ||
23 | struct asserter_t { | ||
25 | 24 | template <class T> | template <class T> |
26 | 25 | const asserter_t operator()(const T&) const { return asserter_t(); } | const asserter_t operator()(const T&) const { return asserter_t(); } |
27 | 26 | }; | }; |
... | ... | struct asserter_t final { | |
76 | 75 | asserter_t& SMART_ASSERT_B; | asserter_t& SMART_ASSERT_B; |
77 | 76 | ||
78 | 77 | private: | private: |
78 | static const char* code_red(); | ||
79 | static const char* code_reset(); | ||
80 | |||
79 | 81 | const bool m_value; | const bool m_value; |
80 | 82 | }; | }; |
81 | 83 | ||
... | ... | private: | |
83 | 85 | ||
84 | 86 | #endif // NDEBUG | #endif // NDEBUG |
85 | 87 | ||
86 | #endif // ASSERT_H_9879879hkjh | ||
88 | #endif // ASSERT_H_9879879hkjh |
File asserter/src/asserter.hxx changed (mode: 100644) (index 3ad5288..d4a63da) | |||
... | ... | template <class U> | |
5 | 5 | const asserter_t& asserter_t::print_current_val(const U& value, const char* message) const | const asserter_t& asserter_t::print_current_val(const U& value, const char* message) const |
6 | 6 | { | { |
7 | 7 | if (!pass()) { | if (!pass()) { |
8 | std::cout << message << ": " << value << std::endl; | ||
8 | std::cout << code_red() << message << ": " << value << code_reset() << std::endl; | ||
9 | 9 | } | } |
10 | 10 | return *this; | return *this; |
11 | 11 | } | } |
File asserter/test/src/check_assert.cpp changed (mode: 100644) (index d9ab4da..0e96a35) | |||
... | ... | int main(int argc, const char* argv[]) | |
10 | 10 | ||
11 | 11 | ASSERT(!a.empty()) | ASSERT(!a.empty()) |
12 | 12 | (a)(a.size()); | (a)(a.size()); |
13 | |||
14 | 13 | return 0; | return 0; |
15 | 14 | } | } |