/* Support for complaint handling during symbol reading in GDB.
- Copyright (C) 1990-2020 Free Software Foundation, Inc.
+ Copyright (C) 1990-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "complaints.h"
#include "command.h"
#include "gdbcmd.h"
+#include "gdbsupport/selftest.h"
#include <unordered_map>
/* Map format strings to counters. */
value);
}
+#if GDB_SELF_TEST
+namespace selftests {
+
+/* Entry point for complaints unit tests. */
+
+static void
+test_complaints ()
+{
+ std::unordered_map<const char *, int> tmp;
+ scoped_restore reset_counters = make_scoped_restore (&counters, tmp);
+ scoped_restore reset_stop_whining = make_scoped_restore (&stop_whining, 2);
+
+#define CHECK_COMPLAINT(STR, CNT) \
+ do \
+ { \
+ std::string output; \
+ execute_fn_to_string (output, []() { complaint (STR); }, false); \
+ std::string expected \
+ = _("During symbol reading: ") + std::string (STR "\n"); \
+ SELF_CHECK (output == expected); \
+ SELF_CHECK (counters[STR] == CNT); \
+ } while (0)
+
+#define CHECK_COMPLAINT_SILENT(STR, CNT) \
+ do \
+ { \
+ std::string output; \
+ execute_fn_to_string (output, []() { complaint (STR); }, false); \
+ SELF_CHECK (output.empty ()); \
+ SELF_CHECK (counters[STR] == CNT); \
+ } while (0)
+
+ CHECK_COMPLAINT ("maintenance complaint 0", 1);
+ CHECK_COMPLAINT ("maintenance complaint 0", 2);
+ CHECK_COMPLAINT_SILENT ("maintenance complaint 0", 3);
+ CHECK_COMPLAINT ("maintenance complaint 1", 1);
+ clear_complaints ();
+ CHECK_COMPLAINT ("maintenance complaint 0", 1);
+
+#undef CHECK_COMPLAINT
+#undef CHECK_COMPLAINT_SILENT
+}
+
+
+} // namespace selftests
+#endif /* GDB_SELF_TEST */
+
void _initialize_complaints ();
void
_initialize_complaints ()
Show max number of complaints about incorrect symbols."), NULL,
NULL, complaints_show_value,
&setlist, &showlist);
+
+#if GDB_SELF_TEST
+ selftests::register_test ("complaints", selftests::test_complaints);
+#endif /* GDB_SELF_TEST */
}