summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmdline/transient_message.cc16
-rw-r--r--src/cmdline/transient_message.h3
-rw-r--r--tests/test_transient_message.cc55
3 files changed, 69 insertions, 5 deletions
diff --git a/src/cmdline/transient_message.cc b/src/cmdline/transient_message.cc
index 6be506ee..0bac3211 100644
--- a/src/cmdline/transient_message.cc
+++ b/src/cmdline/transient_message.cc
@@ -46,6 +46,17 @@ namespace aptitude
namespace
{
+ /** \brief Transient message implementation that makes all
+ * methods into NOPs.
+ */
+ class dummy_transient_message : public transient_message
+ {
+ public:
+ void set_text(const std::wstring &msg)
+ {
+ }
+ };
+
class transient_message_impl : public transient_message
{
// The length of the last line we displayed. Not
@@ -140,7 +151,10 @@ namespace aptitude
create_transient_message(const shared_ptr<terminal> &term,
const shared_ptr<terminal_locale> &term_locale)
{
- return make_shared<transient_message_impl>(term, term_locale);
+ if(!term->output_is_a_terminal())
+ return make_shared<dummy_transient_message>();
+ else
+ return make_shared<transient_message_impl>(term, term_locale);
}
}
}
diff --git a/src/cmdline/transient_message.h b/src/cmdline/transient_message.h
index 4389106d..123333d0 100644
--- a/src/cmdline/transient_message.h
+++ b/src/cmdline/transient_message.h
@@ -48,6 +48,9 @@ namespace aptitude
/** \brief Create a new transient message object.
*
+ * If the given terminal is not a tty when this function is
+ * invoked, no output will be generated.
+ *
* \param term The terminal to use for output.
* \param term_locale Locale information for the given terminal.
*/
diff --git a/tests/test_transient_message.cc b/tests/test_transient_message.cc
index d76f002c..6e864ddb 100644
--- a/tests/test_transient_message.cc
+++ b/tests/test_transient_message.cc
@@ -52,16 +52,29 @@ namespace
shared_ptr<transient_message> message;
std::wstring widechar;
+ // I need to set up expectations on the terminal during member
+ // initialization, since some of the other member initializers
+ // cause methods to be invoked on it.
+ static shared_ptr<mocks::terminal> create_terminal()
+ {
+ shared_ptr<mocks::terminal> rval = mocks::create_combining_terminal();
+
+ EXPECT_CALL(*rval, output_is_a_terminal())
+ .WillRepeatedly(Return(true));
+
+ EXPECT_CALL(*rval, get_screen_width())
+ .WillRepeatedly(Return(80));
+
+ return rval;
+ }
+
TransientMessage()
- : term(mocks::create_combining_terminal()),
+ : term(create_terminal()),
term_locale(mocks::terminal_locale::create()),
teletype(mocks::create_teletype(term, term_locale)),
message(create_transient_message(term, term_locale)),
widechar(1, two_column_char)
{
- EXPECT_CALL(*term, get_screen_width())
- .WillRepeatedly(Return(80));
-
EXPECT_CALL(*term_locale, wcwidth(two_column_char))
.WillRepeatedly(Return(2));
@@ -208,3 +221,37 @@ TEST_F(TransientMessage, ReplaceTruncatedWideCharLine)
message->set_text(widechar + widechar + L"abcdef");
message->set_text(L"z");
}
+
+TEST_F(TransientMessage, RequireTtyDecorationsWithTty)
+{
+ EXPECT_CALL(*term, output_is_a_terminal())
+ .WillRepeatedly(Return(true));
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"abc")));
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"xyz")));
+
+ // Need to create a new message object since it reads and caches the
+ // value of output_is_a_terminal() when it's created.
+ const shared_ptr<transient_message> requiring_message =
+ create_transient_message(term, term_locale);
+
+ requiring_message->set_text(L"abc");
+ requiring_message->set_text(L"xyz");
+}
+
+TEST_F(TransientMessage, RequireTtyDecorationsWithoutTty)
+{
+ EXPECT_CALL(*term, output_is_a_terminal())
+ .WillRepeatedly(Return(false));
+
+ EXPECT_CALL(*teletype, set_last_line(_))
+ .Times(0);
+
+ // Need to create a new message object since it reads and caches the
+ // value of output_is_a_terminal() when it's created.
+ const shared_ptr<transient_message> requiring_message =
+ create_transient_message(term, term_locale);
+
+ requiring_message->set_text(L"abc");
+ requiring_message->set_text(L"xyz");
+}