From b47192f0695048b481895f8f82138a28caf607e3 Mon Sep 17 00:00:00 2001 From: Justin Bassett Date: Wed, 29 Aug 2018 02:48:30 -0700 Subject: [PATCH] fix detail::pythonbuf::overflow()'s return value to return not_eof(c) (#1479) --- include/pybind11/iostream.h | 2 +- tests/test_iostream.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/pybind11/iostream.h b/include/pybind11/iostream.h index a9c27aac1..3caf55639 100644 --- a/include/pybind11/iostream.h +++ b/include/pybind11/iostream.h @@ -34,7 +34,7 @@ private: *pptr() = traits_type::to_char_type(c); pbump(1); } - return sync() ? traits_type::not_eof(c) : traits_type::eof(); + return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof(); } int sync() { diff --git a/tests/test_iostream.py b/tests/test_iostream.py index 3364849a4..167b88756 100644 --- a/tests/test_iostream.py +++ b/tests/test_iostream.py @@ -53,6 +53,16 @@ def test_captured(capsys): assert stdout == '' assert stderr == msg +def test_captured_large_string(capsys): + # Make this bigger than the buffer used on the C++ side: 1024 chars + msg = "I've been redirected to Python, I hope!" + msg = msg * (1024 // len(msg) + 1) + + m.captured_output_default(msg) + stdout, stderr = capsys.readouterr() + assert stdout == msg + assert stderr == '' + def test_guard_capture(capsys): msg = "I've been redirected to Python, I hope!"