Cleanup tests
This commit is contained in:
+20
-20
@@ -11,24 +11,7 @@
|
||||
|
||||
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) {
|
||||
output_redirect::output_redirect(FILE* f) : file_(f) {
|
||||
flush();
|
||||
int fd = FMT_POSIX(fileno(f));
|
||||
// Create a file object referring to the original file.
|
||||
@@ -40,7 +23,7 @@ OutputRedirect::OutputRedirect(FILE* f) : file_(f) {
|
||||
write_end.dup2(fd);
|
||||
}
|
||||
|
||||
OutputRedirect::~OutputRedirect() FMT_NOEXCEPT {
|
||||
output_redirect::~output_redirect() FMT_NOEXCEPT {
|
||||
try {
|
||||
restore();
|
||||
} catch (const std::exception& e) {
|
||||
@@ -48,7 +31,24 @@ OutputRedirect::~OutputRedirect() FMT_NOEXCEPT {
|
||||
}
|
||||
}
|
||||
|
||||
std::string OutputRedirect::restore_and_read() {
|
||||
void output_redirect::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 output_redirect::restore() {
|
||||
if (original_.descriptor() == -1) return; // Already restored.
|
||||
flush();
|
||||
// Restore the original file.
|
||||
original_.dup2(FMT_POSIX(fileno(file_)));
|
||||
original_.close();
|
||||
}
|
||||
|
||||
std::string output_redirect::restore_and_read() {
|
||||
// Restore output.
|
||||
restore();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user