|
11 | 11 | # define SNATCH_WITH_CXXOPTS 0
|
12 | 12 | #endif
|
13 | 13 |
|
14 |
| -namespace snatch::impl::color { |
15 |
| -const char* error_start = "\x1b[1;31m"; |
16 |
| -const char* warning_start = "\x1b[1;33m"; |
17 |
| -const char* status_start = "\x1b[1;36m"; |
18 |
| -const char* fail_start = "\x1b[1;31m"; |
19 |
| -const char* skipped_start = "\x1b[1;33m"; |
20 |
| -const char* pass_start = "\x1b[1;32m"; |
21 |
| -const char* highlight1_start = "\x1b[1;35m"; |
22 |
| -const char* highlight2_start = "\x1b[1;36m"; |
23 |
| -const char* reset = "\x1b[0m"; |
24 |
| -} // namespace snatch::impl::color |
| 14 | +namespace { namespace color { |
| 15 | +const char* error_start [[maybe_unused]] = "\x1b[1;31m"; |
| 16 | +const char* warning_start [[maybe_unused]] = "\x1b[1;33m"; |
| 17 | +const char* status_start [[maybe_unused]] = "\x1b[1;36m"; |
| 18 | +const char* fail_start [[maybe_unused]] = "\x1b[1;31m"; |
| 19 | +const char* skipped_start [[maybe_unused]] = "\x1b[1;33m"; |
| 20 | +const char* pass_start [[maybe_unused]] = "\x1b[1;32m"; |
| 21 | +const char* highlight1_start [[maybe_unused]] = "\x1b[1;35m"; |
| 22 | +const char* highlight2_start [[maybe_unused]] = "\x1b[1;36m"; |
| 23 | +const char* reset [[maybe_unused]] = "\x1b[0m"; |
| 24 | +}} // namespace ::color |
25 | 25 |
|
26 | 26 | namespace {
|
27 | 27 | using namespace snatch;
|
@@ -133,9 +133,13 @@ constexpr const char* get_format_code() noexcept {
|
133 | 133 |
|
134 | 134 | template<typename T>
|
135 | 135 | bool append_fmt(basic_small_string& ss, T value) noexcept {
|
136 |
| - const std::size_t length = std::snprintf(ss.end(), 0, get_format_code<T>(), value); |
| 136 | + const int return_code = std::snprintf(ss.end(), 0, get_format_code<T>(), value); |
| 137 | + if (return_code < 0) { |
| 138 | + return false; |
| 139 | + } |
137 | 140 |
|
138 |
| - const bool could_fit = length <= ss.available(); |
| 141 | + const std::size_t length = static_cast<std::size_t>(return_code); |
| 142 | + const bool could_fit = length <= ss.available(); |
139 | 143 |
|
140 | 144 | const std::size_t offset = ss.size();
|
141 | 145 | const std::size_t prev_space = ss.available();
|
@@ -205,19 +209,21 @@ void truncate_end(basic_small_string& ss) noexcept {
|
205 | 209 | } // namespace snatch::impl
|
206 | 210 |
|
207 | 211 | namespace snatch::matchers {
|
208 |
| -contains_substring::contains_substring(std::string_view pattern) noexcept : pattern(pattern) {} |
| 212 | +contains_substring::contains_substring(std::string_view pattern) noexcept : |
| 213 | + substring_pattern(pattern) {} |
209 | 214 |
|
210 | 215 | bool contains_substring::match(std::string_view message) const noexcept {
|
211 |
| - return message.find(pattern) != message.npos; |
| 216 | + return message.find(substring_pattern) != message.npos; |
212 | 217 | }
|
213 | 218 |
|
214 | 219 | std::string_view contains_substring::describe_fail(std::string_view message) const noexcept {
|
215 |
| - description.clear(); |
216 |
| - if (!append(description, "could not find '", pattern, "' in '", message, "'")) { |
217 |
| - truncate_end(description); |
| 220 | + description_buffer.clear(); |
| 221 | + if (!append( |
| 222 | + description_buffer, "could not find '", substring_pattern, "' in '", message, "'")) { |
| 223 | + truncate_end(description_buffer); |
218 | 224 | }
|
219 | 225 |
|
220 |
| - return description.str(); |
| 226 | + return description_buffer.str(); |
221 | 227 | }
|
222 | 228 |
|
223 | 229 | with_what_contains::with_what_contains(std::string_view pattern) noexcept :
|
|
0 commit comments