mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 11:17:35 +02:00
Don't hang on test failure
This commit is contained in:
@ -17,9 +17,12 @@
|
|||||||
|
|
||||||
#include <climits> // INT_MAX
|
#include <climits> // INT_MAX
|
||||||
#include <cmath> // std::signbit
|
#include <cmath> // std::signbit
|
||||||
|
#include <condition_variable> // std::condition_variable
|
||||||
#include <cstring> // std::strlen
|
#include <cstring> // std::strlen
|
||||||
#include <iterator> // std::back_inserter
|
#include <iterator> // std::back_inserter
|
||||||
#include <list> // std::list
|
#include <list> // std::list
|
||||||
|
#include <mutex> // std::mutex
|
||||||
|
#include <thread> // std::thread
|
||||||
#include <type_traits> // std::is_default_constructible
|
#include <type_traits> // std::is_default_constructible
|
||||||
|
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
@ -1756,14 +1759,26 @@ TEST(format_test, big_print) {
|
|||||||
#if FMT_USE_FCNTL && !defined(_WIN32)
|
#if FMT_USE_FCNTL && !defined(_WIN32)
|
||||||
TEST(format_test, line_buffering) {
|
TEST(format_test, line_buffering) {
|
||||||
auto pipe = fmt::pipe();
|
auto pipe = fmt::pipe();
|
||||||
auto read_end = pipe.read_end.fdopen("r");
|
|
||||||
auto write_end = pipe.write_end.fdopen("w");
|
auto write_end = pipe.write_end.fdopen("w");
|
||||||
setvbuf(write_end.get(), nullptr, _IOLBF, 4096);
|
setvbuf(write_end.get(), nullptr, _IOLBF, 4096);
|
||||||
write_end.print("42\n");
|
write_end.print("42\n");
|
||||||
|
|
||||||
|
std::mutex mutex;
|
||||||
|
std::condition_variable cv;
|
||||||
|
auto read_end = pipe.read_end.fdopen("r");
|
||||||
|
std::thread reader([&]() {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int result = fscanf(read_end.get(), "%d", &n);
|
int result = fscanf(read_end.get(), "%d", &n);
|
||||||
(void)result;
|
(void)result;
|
||||||
EXPECT_EQ(n, 42);
|
EXPECT_EQ(n, 42);
|
||||||
|
cv.notify_one();
|
||||||
|
});
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(mutex);
|
||||||
|
ASSERT_EQ(cv.wait_for(lock, std::chrono::seconds(1)),
|
||||||
|
std::cv_status::no_timeout);
|
||||||
|
reader.join();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user