Skip to content

Commit

Permalink
update test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
i80287 committed Jul 18, 2024
1 parent ad3dc7d commit 928ffd7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions number_theory/test_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <array>
#include <cerrno>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <stdexcept>
Expand All @@ -20,13 +21,13 @@ namespace test_tools_detail {

template <class T>
[[noreturn]] ATTRIBUTE_COLD inline void throw_impl(const char* message_format, T arg,
const char* file_name, uint32_t line,
const char* file_name, std::uint32_t line,
const char* function_name) {
std::array<char, 1024> buffer{};
int bytes_written = std::snprintf(buffer.data(), buffer.size(),
"Check failed at %s:%u %s\nError messssage: ", file_name,
line, function_name);
size_t err_msg_offset = uint32_t(bytes_written);
int bytes_written = std::snprintf(buffer.data(), buffer.size(),
"Check failed at %s:%u %s\nError messssage: ", file_name,
line, function_name);
auto err_msg_offset = static_cast<std::size_t>(static_cast<std::int64_t>(bytes_written));
if (err_msg_offset > buffer.size()) {
perror("std::snprintf");
err_msg_offset = 0;
Expand Down Expand Up @@ -105,10 +106,10 @@ struct Wrapper final {
private:
[[noreturn]] ATTRIBUTE_COLD static void ThrowOnFOpenFail(const char* fname, const char* mode) {
std::array<char, 1024> buffer{};
int bytes_written = std::snprintf(
buffer.data(), buffer.size(),
"Wrapper::Wrapper(const char* fname, const char* mode): std::fopen(\"%s\", \"%s\") failed: %s",
fname, mode, strerror(errno));
int bytes_written = std::snprintf(buffer.data(), buffer.size(),
"Wrapper::Wrapper(const char* fname, const char* mode): "
"std::fopen(\"%s\", \"%s\") failed: %s",
fname, mode, std::strerror(errno));
if (bytes_written < 0) [[unlikely]] {
constexpr std::string_view msg =
"Wrapper::Wrapper(const char* fname,const char* mode): "
Expand Down

0 comments on commit 928ffd7

Please sign in to comment.