lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master c28ef2c 5/9: Demonstrate substitutability of


From: Greg Chicares
Subject: [lmi-commits] [lmi] master c28ef2c 5/9: Demonstrate substitutability of alert streams
Date: Thu, 12 Jul 2018 13:12:58 -0400 (EDT)

branch: master
commit c28ef2ce007cfb8fdf3ca129aceed238558e60e0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Demonstrate substitutability of alert streams
    
    It's obvious that this has to work, but it's helpful to show useful
    techniques in unit tests.
---
 alert_test.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/alert_test.cpp b/alert_test.cpp
index 120bbde..ffc6937 100644
--- a/alert_test.cpp
+++ b/alert_test.cpp
@@ -30,6 +30,13 @@
 #include <stdexcept>
 #include <vector>
 
+/// Demonstrate that alert streams can be used as arguments.
+
+void test_stream_arg(std::ostream& os, std::string const& s)
+{
+    os << s << std::flush;
+}
+
 int test_main(int, char*[])
 {
     safely_show_message("  This message should appear on stderr.");
@@ -78,6 +85,13 @@ int test_main(int, char*[])
     s = "Second simulated alarum.";
     BOOST_TEST_THROW(alarum() << s << std::flush, std::runtime_error, s);
 
+    // The CLI handler should gobble this message.
+    test_stream_arg(status(), "This should not be printed.");
+
+    test_stream_arg(warning(), "This message should appear on stdout.");
+
+    BOOST_TEST_THROW(test_stream_arg(alarum(), "X"), std::runtime_error, "X");
+
     return 0;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]