]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Add selftest for tui_setup_io master
authorTom de Vries <tdevries@suse.de>
Fri, 10 Apr 2026 13:50:22 +0000 (15:50 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 10 Apr 2026 13:50:22 +0000 (15:50 +0200)
Add a selftest for the problem described in commit b171f68e945 ("[gdb/tui]
Make tui_setup_io more robust").

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
gdb/tui/tui-io.c

index 4b4bc818430e1f7b476ab57b76905a6c7db10518..642b88ead0c9d6bbfedcc9dbd3d5f61ce297f77b 100644 (file)
@@ -46,6 +46,7 @@
 #include "pager.h"
 #include "gdbsupport/gdb-checked-static-cast.h"
 #include "logging-file.h"
 #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
 
 /* 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;
     }
 }
       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
+}