aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/fmt/test/gtest-extra.cc
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:45:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:01 +0300
commit2d37894b1b037cf24231090eda8589bbb44fb6fc (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/fmt/test/gtest-extra.cc
parent718c552901d703c502ccbefdfc3c9028d608b947 (diff)
downloadydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/fmt/test/gtest-extra.cc')
-rw-r--r--contrib/libs/fmt/test/gtest-extra.cc168
1 files changed, 84 insertions, 84 deletions
diff --git a/contrib/libs/fmt/test/gtest-extra.cc b/contrib/libs/fmt/test/gtest-extra.cc
index 3f38cbd1e6..58628a8a98 100644
--- a/contrib/libs/fmt/test/gtest-extra.cc
+++ b/contrib/libs/fmt/test/gtest-extra.cc
@@ -1,87 +1,87 @@
-// Formatting library for C++ - custom Google Test assertions
-//
-// Copyright (c) 2012 - present, Victor Zverovich
-// All rights reserved.
-//
-// For the license information refer to format.h.
-
-#include "gtest-extra.h"
-
-#if FMT_USE_FCNTL
-
-using fmt::file;
-
-void OutputRedirect::flush() {
-# if EOF != -1
-# error "FMT_RETRY assumes return value of -1 indicating failure"
-# endif
- int result = 0;
- FMT_RETRY(result, fflush(file_));
- if (result != 0) throw fmt::system_error(errno, "cannot flush stream");
-}
-
-void OutputRedirect::restore() {
- if (original_.descriptor() == -1) return; // Already restored.
- flush();
- // Restore the original file.
- original_.dup2(FMT_POSIX(fileno(file_)));
- original_.close();
-}
-
-OutputRedirect::OutputRedirect(FILE* f) : file_(f) {
- flush();
- int fd = FMT_POSIX(fileno(f));
- // Create a file object referring to the original file.
- original_ = file::dup(fd);
- // Create a pipe.
- file write_end;
- file::pipe(read_end_, write_end);
- // Connect the passed FILE object to the write end of the pipe.
- write_end.dup2(fd);
-}
-
-OutputRedirect::~OutputRedirect() FMT_NOEXCEPT {
- try {
- restore();
- } catch (const std::exception& e) {
- std::fputs(e.what(), stderr);
- }
-}
-
-std::string OutputRedirect::restore_and_read() {
- // Restore output.
- restore();
-
- // Read everything from the pipe.
- std::string content;
- if (read_end_.descriptor() == -1) return content; // Already read.
- enum { BUFFER_SIZE = 4096 };
- char buffer[BUFFER_SIZE];
+// Formatting library for C++ - custom Google Test assertions
+//
+// Copyright (c) 2012 - present, Victor Zverovich
+// All rights reserved.
+//
+// For the license information refer to format.h.
+
+#include "gtest-extra.h"
+
+#if FMT_USE_FCNTL
+
+using fmt::file;
+
+void OutputRedirect::flush() {
+# if EOF != -1
+# error "FMT_RETRY assumes return value of -1 indicating failure"
+# endif
+ int result = 0;
+ FMT_RETRY(result, fflush(file_));
+ if (result != 0) throw fmt::system_error(errno, "cannot flush stream");
+}
+
+void OutputRedirect::restore() {
+ if (original_.descriptor() == -1) return; // Already restored.
+ flush();
+ // Restore the original file.
+ original_.dup2(FMT_POSIX(fileno(file_)));
+ original_.close();
+}
+
+OutputRedirect::OutputRedirect(FILE* f) : file_(f) {
+ flush();
+ int fd = FMT_POSIX(fileno(f));
+ // Create a file object referring to the original file.
+ original_ = file::dup(fd);
+ // Create a pipe.
+ file write_end;
+ file::pipe(read_end_, write_end);
+ // Connect the passed FILE object to the write end of the pipe.
+ write_end.dup2(fd);
+}
+
+OutputRedirect::~OutputRedirect() FMT_NOEXCEPT {
+ try {
+ restore();
+ } catch (const std::exception& e) {
+ std::fputs(e.what(), stderr);
+ }
+}
+
+std::string OutputRedirect::restore_and_read() {
+ // Restore output.
+ restore();
+
+ // Read everything from the pipe.
+ std::string content;
+ if (read_end_.descriptor() == -1) return content; // Already read.
+ enum { BUFFER_SIZE = 4096 };
+ char buffer[BUFFER_SIZE];
size_t count = 0;
- do {
- count = read_end_.read(buffer, BUFFER_SIZE);
- content.append(buffer, count);
- } while (count != 0);
- read_end_.close();
- return content;
-}
-
+ do {
+ count = read_end_.read(buffer, BUFFER_SIZE);
+ content.append(buffer, count);
+ } while (count != 0);
+ read_end_.close();
+ return content;
+}
+
std::string read(file& f, size_t count) {
- std::string buffer(count, '\0');
+ std::string buffer(count, '\0');
size_t n = 0, offset = 0;
- do {
- n = f.read(&buffer[offset], count - offset);
- // We can't read more than size_t bytes since count has type size_t.
- offset += n;
- } while (offset < count && n != 0);
- buffer.resize(offset);
- return buffer;
-}
-
-#endif // FMT_USE_FCNTL
-
-std::string format_system_error(int error_code, fmt::string_view message) {
- fmt::memory_buffer out;
- format_system_error(out, error_code, message);
- return to_string(out);
-}
+ do {
+ n = f.read(&buffer[offset], count - offset);
+ // We can't read more than size_t bytes since count has type size_t.
+ offset += n;
+ } while (offset < count && n != 0);
+ buffer.resize(offset);
+ return buffer;
+}
+
+#endif // FMT_USE_FCNTL
+
+std::string format_system_error(int error_code, fmt::string_view message) {
+ fmt::memory_buffer out;
+ format_system_error(out, error_code, message);
+ return to_string(out);
+}