[binutils-gdb] [gdb] Add selftest for tui_setup_io

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b90e5339140ee1ff0ff454098c882bf7dcf9bbf9

commit b90e5339140ee1ff0ff454098c882bf7dcf9bbf9
Author: Tom de Vries <[email protected]>
Date:   Fri Apr 10 15:50:22 2026 +0200

    [gdb] Add selftest for tui_setup_io
    
    Add a selftest for the problem described in commit b171f68e945 ("[gdb/tui]
    Make tui_setup_io more robust").
    
    Reviewed-By: Guinevere Larsen <[email protected]>

Diff:
---
 gdb/tui/tui-io.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 4b4bc818430..642b88ead0c 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -46,6 +46,7 @@
 #include "pager.h"
 #include "gdbsupport/gdb-checked-static-cast.h"
 #include "logging-file.h"
+#include "gdbsupport/selftest.h"
 
 /* This redefines CTRL if it is not already defined, so it must come
    after terminal state related include files like <term.h> and
@@ -1328,3 +1329,36 @@ tui_getc (FILE *fp)
       return 0;
     }
 }
+
+#if GDB_SELF_TEST
+namespace selftests {
+namespace tui {
+namespace io {
+
+static void
+run_tests ()
+{
+  if (!tui_active)
+    {
+      /* Calling tui_setup_io (0) when tui is disabled should have no effect.  */
+      tui_setup_io (0);
+
+      /* If the output streams are reduced to nullptrs, then the self-test
+	 infrastructure will crash when trying to report these failures.  */
+      SELF_CHECK (*redirectable_stdout () != nullptr);
+      SELF_CHECK (*redirectable_stderr () != nullptr);
+      SELF_CHECK (*redirectable_stdlog () != nullptr);
+    }
+}
+
+} /* namespace io */
+} /* namespace tui */
+} /* namespace selftests */
+#endif /* GDB_SELF_TEST */
+
+INIT_GDB_FILE (tui_io)
+{
+#if GDB_SELF_TEST
+  selftests::register_test ("tui-io", selftests::tui::io::run_tests);
+#endif
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.