From 45cd3a6d6804246c72a1d99be62feabd8d7baa0d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 17 Jul 2025 16:54:58 -0400
Subject: [PATCH 34/41] {needs ChangeLog} reorganize diagnostics selftests

---
 gcc/Makefile.in                               |   1 +
 gcc/c-family/c-format.cc                      |   2 +-
 gcc/diagnostic.cc                             |   2 +-
 gcc/diagnostics/color.cc                      |   4 +-
 gcc/diagnostics/diagnostics-selftests.cc      |  54 +++++
 gcc/diagnostics/diagnostics-selftests.h       |  53 +++++
 gcc/diagnostics/digraphs.cc                   |   6 +-
 gcc/diagnostics/edit-context.cc               |   8 +-
 gcc/diagnostics/html-sink.cc                  |  17 +-
 gcc/diagnostics/lazy-paths.cc                 |  12 +-
 gcc/diagnostics/output-spec.cc                |  11 +-
 gcc/diagnostics/paths-output.cc               | 133 ++++++-----
 gcc/diagnostics/sarif-sink.cc                 |  20 +-
 gcc/diagnostics/selftest-context.cc           |  36 +--
 gcc/diagnostics/selftest-context.h            |  14 +-
 gcc/diagnostics/selftest-logical-locations.cc |  32 +--
 gcc/diagnostics/selftest-logical-locations.h  |  15 +-
 gcc/diagnostics/selftest-paths.cc             | 120 +++++-----
 gcc/diagnostics/selftest-paths.h              |  49 ++--
 gcc/diagnostics/selftest-source-printing.h    |  20 +-
 gcc/diagnostics/source-printing.cc            | 220 +++++++++---------
 gcc/diagnostics/state-graphs.cc               |  10 +-
 gcc/selftest-run-tests.cc                     |  15 +-
 gcc/selftest.h                                |  11 -
 .../plugin/expensive_selftests_plugin.cc      |   2 +-
 25 files changed, 499 insertions(+), 368 deletions(-)
 create mode 100644 gcc/diagnostics/diagnostics-selftests.cc
 create mode 100644 gcc/diagnostics/diagnostics-selftests.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b1880add25aa..97b624ac0713 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1871,6 +1871,7 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o \
 	diagnostics/selftest-context.o \
 	diagnostics/selftest-logical-locations.o \
 	diagnostics/selftest-paths.o \
+	diagnostics/diagnostics-selftests.o \
 	graphviz.o pex.o \
 	pretty-print.o intl.o \
 	json.o json-parsing.o \
diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 8fd32d40ea89..310cf752dbf3 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -5577,7 +5577,7 @@ test_type_mismatch_range_labels ()
   gcc_rich_location richloc (fmt, &fmt_label, nullptr);
   richloc.add_range (param, SHOW_RANGE_WITHOUT_CARET, &param_label);
 
-  test_diagnostic_context dc;
+  diagnostics::selftest::test_context dc;
   diagnostic_show_locus (&dc,
 			 dc.m_source_printing,
 			 &richloc, DK_ERROR, dc.get_reference_printer ());
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 74a3a0b0af4f..a6eae2a6455e 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -1995,7 +1995,7 @@ assert_location_text (const char *expected_loc_text,
 		      enum diagnostics_column_unit column_unit
 			= DIAGNOSTICS_COLUMN_UNIT_BYTE)
 {
-  test_diagnostic_context dc;
+  diagnostics::selftest::test_context dc;
   dc.m_column_unit = column_unit;
   dc.m_column_origin = origin;
 
diff --git a/gcc/diagnostics/color.cc b/gcc/diagnostics/color.cc
index 622027b4c0e1..7b499fea8523 100644
--- a/gcc/diagnostics/color.cc
+++ b/gcc/diagnostics/color.cc
@@ -475,6 +475,7 @@ determine_url_format (diagnostic_url_rule_t rule)
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
 /* Test of an empty diagnostic_color_dict.  */
@@ -522,7 +523,7 @@ test_color_dict_envvar_parsing ()
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_color_cc_tests ()
+color_cc_tests ()
 {
   test_empty_color_dict ();
   test_default_color_dict ();
@@ -530,5 +531,6 @@ diagnostics_color_cc_tests ()
 }
 
 } // namespace selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/diagnostics-selftests.cc b/gcc/diagnostics/diagnostics-selftests.cc
new file mode 100644
index 000000000000..e4e9cd84c991
--- /dev/null
+++ b/gcc/diagnostics/diagnostics-selftests.cc
@@ -0,0 +1,54 @@
+/* Selftest support for diagnostics.
+   Copyright (C) 2019-2025 Free Software Foundation, Inc.
+   Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "selftest.h"
+#include "diagnostics/diagnostics-selftests.h"
+
+#if CHECKING_P
+
+namespace diagnostics {
+
+namespace selftest {
+
+/* Run all diagnostics-specific selftests.  */
+
+void
+run_diagnostics_selftests ()
+{
+  color_cc_tests ();
+  source_printing_cc_tests ();
+  html_sink_cc_tests ();
+  sarif_sink_cc_tests ();
+  digraphs_cc_tests ();
+  output_spec_cc_tests ();
+  state_graphs_cc_tests ();
+  lazy_paths_cc_tests ();
+  paths_output_cc_tests ();
+  edit_context_cc_tests ();
+}
+
+} /* end of namespace diagnostics::selftest.  */
+
+} // namespace diagnostics
+
+#endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/diagnostics-selftests.h b/gcc/diagnostics/diagnostics-selftests.h
new file mode 100644
index 000000000000..278447f67e7f
--- /dev/null
+++ b/gcc/diagnostics/diagnostics-selftests.h
@@ -0,0 +1,53 @@
+/* Selftests for diagnostics.
+   Copyright (C) 2019-2025 Free Software Foundation, Inc.
+   Contributed by David Malcolm <dmalcolm@redhat.com>.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_DIAGNOSTICS_SELFTESTS_H
+#define GCC_DIAGNOSTICS_SELFTESTS_H
+
+#if CHECKING_P
+
+namespace diagnostics {
+
+namespace selftest {
+
+extern void run_diagnostics_selftests ();
+
+/* Declarations for specific families of tests (by source file within
+   "diagnostics/"), in alphabetical order.  */
+
+extern void color_cc_tests ();
+extern void digraphs_cc_tests ();
+extern void edit_context_cc_tests ();
+extern void html_sink_cc_tests ();
+extern void lazy_paths_cc_tests ();
+extern void output_spec_cc_tests ();
+extern void paths_output_cc_tests ();
+extern void sarif_sink_cc_tests ();
+extern void selftest_logical_locations_cc_tests ();
+extern void source_printing_cc_tests ();
+extern void state_graphs_cc_tests ();
+
+} /* end of namespace diagnostics::selftest.  */
+
+} // namespace diagnostics
+
+#endif /* #if CHECKING_P */
+
+#endif /* GCC_DIAGNOSTICS_SELFTESTS_H */
diff --git a/gcc/diagnostics/digraphs.cc b/gcc/diagnostics/digraphs.cc
index 6a5b86c28263..b77390c0f1c7 100644
--- a/gcc/diagnostics/digraphs.cc
+++ b/gcc/diagnostics/digraphs.cc
@@ -375,6 +375,7 @@ diagnostics::digraphs::lazy_digraphs::get_or_create_digraphs () const
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
 static void
@@ -473,12 +474,13 @@ test_simple_graph ()
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_digraphs_cc_tests ()
+digraphs_cc_tests ()
 {
   test_empty_graph ();
   test_simple_graph ();
 }
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* CHECKING_P */
diff --git a/gcc/diagnostics/edit-context.cc b/gcc/diagnostics/edit-context.cc
index 4ca571b92466..0b6c12df57d9 100644
--- a/gcc/diagnostics/edit-context.cc
+++ b/gcc/diagnostics/edit-context.cc
@@ -897,15 +897,16 @@ edited_line::ensure_terminated ()
   m_content[m_len] = '\0';
 }
 
-} // namespace diagnostics
-
 #if CHECKING_P
 
 /* Selftests of code-editing.  */
 
 namespace selftest {
 
-using edit_context = diagnostics::edit_context;
+using line_table_case = ::selftest::line_table_case;
+using line_table_test = ::selftest::line_table_test;
+using temp_source_file = ::selftest::temp_source_file;
+using named_temp_file = ::selftest::named_temp_file;
 
 /* A wrapper class for ensuring that the underlying pointer is freed.  */
 
@@ -1849,5 +1850,6 @@ edit_context_cc_tests ()
 }
 
 } // namespace selftest
+} // namespace diagnostics
 
 #endif /* CHECKING_P */
diff --git a/gcc/diagnostics/html-sink.cc b/gcc/diagnostics/html-sink.cc
index 260f756edfa8..5d8636cd160f 100644
--- a/gcc/diagnostics/html-sink.cc
+++ b/gcc/diagnostics/html-sink.cc
@@ -1499,14 +1499,10 @@ make_html_sink (context &dc,
   return sink;
 }
 
-} // namespace diagnostics
-
 #if CHECKING_P
 
 namespace selftest {
 
-using namespace diagnostics;
-
 /* Helper for writing tests of html_token_printer.
    Printing to m_pp will appear as HTML within m_top_element, a <div>.  */
 
@@ -1567,10 +1563,10 @@ test_token_printer ()
    The XML output is cached internally, rather than written
    out to a file.  */
 
-class test_html_diagnostic_context : public test_diagnostic_context
+class test_html_context : public test_context
 {
 public:
-  test_html_diagnostic_context ()
+  test_html_context ()
   {
     html_generation_options html_gen_opts;
     html_gen_opts.m_css = false;
@@ -1621,7 +1617,7 @@ private:
 static void
 test_simple_log ()
 {
-  test_html_diagnostic_context dc;
+  test_html_context dc;
 
   rich_location richloc (line_table, UNKNOWN_LOCATION);
   dc.report (DK_ERROR, richloc, nullptr, 0, "this is a test: %qs", "foo");
@@ -1652,7 +1648,7 @@ test_simple_log ()
 static void
 test_metadata ()
 {
-  test_html_diagnostic_context dc;
+  test_html_context dc;
   html_builder &b = dc.get_builder ();
 
   {
@@ -1695,14 +1691,15 @@ test_metadata ()
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_html_sink_cc_tests ()
+html_sink_cc_tests ()
 {
-  auto_fix_quotes fix_quotes;
+  ::selftest::auto_fix_quotes fix_quotes;
   test_token_printer ();
   test_simple_log ();
   test_metadata ();
 }
 
 } // namespace selftest
+} // namespace diagnostics
 
 #endif /* CHECKING_P */
diff --git a/gcc/diagnostics/lazy-paths.cc b/gcc/diagnostics/lazy-paths.cc
index 322ad786d114..51ed12fae126 100644
--- a/gcc/diagnostics/lazy-paths.cc
+++ b/gcc/diagnostics/lazy-paths.cc
@@ -87,8 +87,11 @@ lazy_path::lazily_generate_path () const
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
+using auto_fix_quotes = ::selftest::auto_fix_quotes;
+
 class test_lazy_path : public lazy_path
 {
 public:
@@ -171,7 +174,7 @@ test_emission (pretty_printer *event_pp)
   /* Verify that we don't bother generating the inner path if the warning
      is skipped.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_option_manager (std::make_unique<all_warnings_disabled> (), 0);
 
     test_rich_location rich_loc (*event_pp);
@@ -189,7 +192,7 @@ test_emission (pretty_printer *event_pp)
   /* Verify that we *do* generate the inner path for a diagnostic that
      is emitted, such as an error.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
 
     test_rich_location rich_loc (*event_pp);
     ASSERT_FALSE (rich_loc.m_path.generated_p ());
@@ -216,7 +219,7 @@ test_emission (pretty_printer *event_pp)
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_lazy_paths_cc_tests ()
+lazy_paths_cc_tests ()
 {
   /* In a few places we use the global dc's printer to determine
      colorization so ensure this off during the tests.  */
@@ -234,6 +237,7 @@ diagnostics_lazy_paths_cc_tests ()
   pp_show_color (global_pp) = saved_show_color;
 }
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/output-spec.cc b/gcc/diagnostics/output-spec.cc
index 433f3af6f609..08128a92add1 100644
--- a/gcc/diagnostics/output-spec.cc
+++ b/gcc/diagnostics/output-spec.cc
@@ -660,12 +660,13 @@ html_scheme_handler::make_sink (const context &ctxt,
 }
 
 } // namespace output_spec
-} // namespace diagnostics
 
 #if CHECKING_P
 
 namespace selftest {
 
+using auto_fix_quotes = ::selftest::auto_fix_quotes;
+
 /* RAII class to temporarily override "progname" to the
    string "PROGNAME".  */
 
@@ -737,7 +738,7 @@ struct parser_test
   }
 
 private:
-  test_diagnostic_context m_dc;
+  diagnostics::selftest::test_context m_dc;
   test_spec_context m_ctxt;
   diagnostics::sink &m_fmt;
 };
@@ -839,12 +840,12 @@ test_output_arg_parsing ()
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_output_spec_cc_tests ()
+output_spec_cc_tests ()
 {
   test_output_arg_parsing ();
 }
 
-} // namespace selftest
-
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/paths-output.cc b/gcc/diagnostics/paths-output.cc
index 5ccc3b0a0d24..87c5876a6a36 100644
--- a/gcc/diagnostics/paths-output.cc
+++ b/gcc/diagnostics/paths-output.cc
@@ -1407,8 +1407,17 @@ diagnostics::print_path_as_html (xml::printer &xp,
 
 #if CHECKING_P
 
+namespace diagnostics {
+namespace paths {
 namespace selftest {
 
+using location = ::selftest::location;
+using line_table_case = ::selftest::line_table_case;
+using line_table_test = ::selftest::line_table_test;
+using temp_source_file = ::selftest::temp_source_file;
+
+using test_context = diagnostics::selftest::test_context;
+
 /* Return true iff all events in PATH_ have locations for which column data
    is available, so that selftests that require precise string output can
    bail out for awkward line_table cases.  */
@@ -1435,11 +1444,11 @@ path_events_have_column_data_p (const path &path_)
 static void
 test_empty_path (pretty_printer *event_pp)
 {
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   ASSERT_FALSE (path.interprocedural_p ());
 
-  test_diagnostic_context dc;
-  diagnostics::text_sink text_output (dc);
+  test_context dc;
+  text_sink text_output (dc);
   path_print_policy policy (text_output);
   path_summary summary (policy, *event_pp, path, false);
   ASSERT_EQ (summary.get_num_ranges (), 0);
@@ -1454,15 +1463,15 @@ test_empty_path (pretty_printer *event_pp)
 static void
 test_intraprocedural_path (pretty_printer *event_pp)
 {
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   const char *const funcname = "foo";
   path.add_event (UNKNOWN_LOCATION, funcname, 0, "first %qs", "free");
   path.add_event (UNKNOWN_LOCATION, funcname, 0, "double %qs", "free");
 
   ASSERT_FALSE (path.interprocedural_p ());
 
-  test_diagnostic_context dc;
-  diagnostics::text_sink text_output (dc);
+  selftest::test_context dc;
+  text_sink text_output (dc);
   path_print_policy policy (text_output);
   path_summary summary (policy, *event_pp, path, false, false, false);
   ASSERT_EQ (summary.get_num_ranges (), 1);
@@ -1479,7 +1488,7 @@ test_intraprocedural_path (pretty_printer *event_pp)
 static void
 test_interprocedural_path_1 (pretty_printer *event_pp)
 {
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   path.add_entry ("test", 0);
   path.add_call ("test", 0, "make_boxed_int");
   path.add_call ("make_boxed_int", 1, "wrapped_malloc");
@@ -1498,8 +1507,8 @@ test_interprocedural_path_1 (pretty_printer *event_pp)
   ASSERT_TRUE (path.interprocedural_p ());
 
   {
-    test_diagnostic_context dc;
-    diagnostics::text_sink text_output (dc, nullptr, false);
+    selftest::test_context dc;
+    text_sink text_output (dc, nullptr, false);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     ASSERT_EQ (summary.get_num_ranges (), 9);
@@ -1559,9 +1568,9 @@ test_interprocedural_path_1 (pretty_printer *event_pp)
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     print_path_summary_as_text (summary, text_output, true);
@@ -1626,7 +1635,7 @@ test_interprocedural_path_1 (pretty_printer *event_pp)
 static void
 test_interprocedural_path_2 (pretty_printer *event_pp)
 {
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   path.add_entry ("foo", 0);
   path.add_call ("foo", 0, "bar");
   path.add_call ("bar", 1, "baz");
@@ -1637,8 +1646,8 @@ test_interprocedural_path_2 (pretty_printer *event_pp)
   ASSERT_TRUE (path.interprocedural_p ());
 
   {
-    test_diagnostic_context dc;
-    diagnostics::text_sink text_output (dc);
+    selftest::test_context dc;
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     ASSERT_EQ (summary.get_num_ranges (), 5);
@@ -1673,9 +1682,9 @@ test_interprocedural_path_2 (pretty_printer *event_pp)
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     print_path_summary_as_text (summary, text_output, true);
@@ -1715,7 +1724,7 @@ test_interprocedural_path_2 (pretty_printer *event_pp)
 static void
 test_recursion (pretty_printer *event_pp)
 {
- test_diagnostic_path path (event_pp);
+ test_path path (event_pp);
   path.add_entry ("factorial", 0);
   for (int depth = 0; depth < 3; depth++)
     path.add_call ("factorial", depth, "factorial");
@@ -1724,10 +1733,10 @@ test_recursion (pretty_printer *event_pp)
   ASSERT_TRUE (path.interprocedural_p ());
 
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
 
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     ASSERT_EQ (summary.get_num_ranges (), 4);
@@ -1756,10 +1765,10 @@ test_recursion (pretty_printer *event_pp)
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
 
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     print_path_summary_as_text (summary, text_output, true);
@@ -1792,7 +1801,7 @@ test_recursion (pretty_printer *event_pp)
 class control_flow_test
 {
 public:
-  control_flow_test (const location &loc,
+  control_flow_test (const selftest::location &loc,
 		     const line_table_case &case_,
 		     const char *content)
   : m_tmp_file (loc, ".c", content,
@@ -1861,7 +1870,7 @@ test_control_flow_1 (const line_table_case &case_,
   const location_t conditional = t.get_line_and_column (3, 7);
   const location_t cfg_dest = t.get_line_and_column (5, 10);
 
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   path.add_event (conditional, nullptr, 0,
 		  "following %qs branch (when %qs is NULL)...",
 		  "false", "p");
@@ -1878,10 +1887,10 @@ test_control_flow_1 (const line_table_case &case_,
 
 
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_event_links_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -1904,10 +1913,10 @@ test_control_flow_1 (const line_table_case &case_,
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_event_links_p = false;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -1927,11 +1936,11 @@ test_control_flow_1 (const line_table_case &case_,
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_line_numbers_p = true;
     dc.m_source_printing.show_event_links_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -1954,11 +1963,11 @@ test_control_flow_1 (const line_table_case &case_,
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_line_numbers_p = true;
     dc.m_source_printing.show_event_links_p = false;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -1978,10 +1987,10 @@ test_control_flow_1 (const line_table_case &case_,
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
     dc.m_source_printing.show_event_links_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -2004,11 +2013,11 @@ test_control_flow_1 (const line_table_case &case_,
        pp_formatted_text (text_output.get_printer ()));
   }
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
     dc.m_source_printing.show_event_links_p = true;
     dc.m_source_printing.show_line_numbers_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -2058,7 +2067,7 @@ test_control_flow_2 (const line_table_case &case_,
   const location_t loop_body_start = t.get_line_and_columns (5, 12, 17);
   const location_t loop_body_end = t.get_line_and_columns (5, 5, 9, 17);
 
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   path.add_event (iter_test, nullptr, 0, "infinite loop here");
 
   path.add_event (iter_test, nullptr, 0, "looping from here...");
@@ -2075,11 +2084,11 @@ test_control_flow_2 (const line_table_case &case_,
     return;
 
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_event_links_p = true;
     dc.m_source_printing.show_line_numbers_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -2145,7 +2154,7 @@ test_control_flow_3 (const line_table_case &case_,
   const location_t iter_test = t.get_line_and_column (3, 19);
   const location_t iter_next = t.get_line_and_columns (3, 22, 24);
 
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   path.add_event (iter_test, nullptr, 0, "infinite loop here");
 
   path.add_event (iter_test, nullptr, 0, "looping from here...");
@@ -2162,11 +2171,11 @@ test_control_flow_3 (const line_table_case &case_,
     return;
 
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_event_links_p = true;
     dc.m_source_printing.show_line_numbers_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -2211,7 +2220,7 @@ assert_cfg_edge_path_streq (const location &loc,
 			    const location_t dst_loc,
 			    const char *expected_str)
 {
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   path.add_event (src_loc, nullptr, 0, "from here...");
   path.connect_to_next_event ();
 
@@ -2220,11 +2229,11 @@ assert_cfg_edge_path_streq (const location &loc,
   if (!path_events_have_column_data_p (path))
     return;
 
-  test_diagnostic_context dc;
+  selftest::test_context dc;
   dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
   dc.m_source_printing.show_event_links_p = true;
   dc.m_source_printing.show_line_numbers_p = true;
-  diagnostics::text_sink text_output (dc);
+  text_sink text_output (dc);
   path_print_policy policy (text_output);
   path_summary summary (policy, *event_pp, path, true);
   print_path_summary_as_text (summary, text_output, false);
@@ -2515,7 +2524,7 @@ test_control_flow_5 (const line_table_case &case_,
 
   control_flow_test t (SELFTEST_LOCATION, case_, content);
 
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   /* (1) */
   path.add_event (t.get_line_and_column (1, 6), nullptr, 0,
 		  "following %qs branch (when %qs is non-NULL)...",
@@ -2544,11 +2553,11 @@ test_control_flow_5 (const line_table_case &case_,
     return;
 
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_event_links_p = true;
     dc.m_source_printing.show_line_numbers_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -2604,7 +2613,7 @@ test_control_flow_6 (const line_table_case &case_,
 
   control_flow_test t (SELFTEST_LOCATION, case_, content);
 
-  test_diagnostic_path path (event_pp);
+  test_path path (event_pp);
   /* (1) */
   path.add_event (t.get_line_and_columns (6, 25, 35), nullptr, 0,
 		  "allocated here");
@@ -2633,11 +2642,11 @@ test_control_flow_6 (const line_table_case &case_,
     return;
 
   {
-    test_diagnostic_context dc;
+    selftest::test_context dc;
     dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
     dc.m_source_printing.show_event_links_p = true;
     dc.m_source_printing.show_line_numbers_p = true;
-    diagnostics::text_sink text_output (dc);
+    text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, true);
     print_path_summary_as_text (summary, text_output, false);
@@ -2690,24 +2699,30 @@ control_flow_tests (const line_table_case &case_)
   test_control_flow_6 (case_, &pp);
 }
 
+} // namespace diagnostics::paths::selftest
+} // namespace diagnostics::paths
+
+namespace selftest { // diagnostics::selftest
+
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_paths_output_cc_tests ()
+paths_output_cc_tests ()
 {
   pretty_printer pp;
   pp_show_color (&pp) = false;
 
-  auto_fix_quotes fix_quotes;
-  test_empty_path (&pp);
-  test_intraprocedural_path (&pp);
-  test_interprocedural_path_1 (&pp);
-  test_interprocedural_path_2 (&pp);
-  test_recursion (&pp);
-  for_each_line_table_case (control_flow_tests);
+  ::selftest::auto_fix_quotes fix_quotes;
+  diagnostics::paths::selftest::test_empty_path (&pp);
+  diagnostics::paths::selftest::test_intraprocedural_path (&pp);
+  diagnostics::paths::selftest::test_interprocedural_path_1 (&pp);
+  diagnostics::paths::selftest::test_interprocedural_path_2 (&pp);
+  diagnostics::paths::selftest::test_recursion (&pp);
+  for_each_line_table_case (diagnostics::paths::selftest::control_flow_tests);
 }
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #if __GNUC__ >= 10
 #  pragma GCC diagnostic pop
diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc
index 115351027b47..a18320322d0f 100644
--- a/gcc/diagnostics/sarif-sink.cc
+++ b/gcc/diagnostics/sarif-sink.cc
@@ -4317,13 +4317,12 @@ sarif_generation_options::sarif_generation_options ()
 {
 }
 
-} // namespace diagnostics
-
 #if CHECKING_P
 
 namespace selftest {
 
-using namespace diagnostics;
+using auto_fix_quotes = ::selftest::auto_fix_quotes;
+using line_table_case = ::selftest::line_table_case;
 
 static void
 test_sarif_array_of_unique_1 ()
@@ -4399,7 +4398,7 @@ test_sarif_array_of_unique_2 ()
    The JSON output is cached internally, rather than written
    out to a file.  */
 
-class test_sarif_diagnostic_context : public test_diagnostic_context
+class test_sarif_diagnostic_context : public test_context
 {
 public:
   test_sarif_diagnostic_context (const char *main_input_filename,
@@ -4453,16 +4452,16 @@ private:
 
 static void
 test_make_location_object (const sarif_generation_options &sarif_gen_opts,
-			   const line_table_case &case_)
+			   const ::selftest::line_table_case &case_)
 {
-  diagnostic_show_locus_fixture_one_liner_utf8 f (case_);
+  source_printing_fixture_one_liner_utf8 f (case_);
   location_t line_end = linemap_position_for_column (line_table, 31);
 
   /* Don't attempt to run the tests if column data might be unavailable.  */
   if (line_end > LINE_MAP_MAX_LOCATION_WITH_COLS)
     return;
 
-  test_diagnostic_context dc;
+  test_context dc;
   pretty_printer pp;
   sarif_builder builder
     (dc, pp, line_table,
@@ -4706,7 +4705,7 @@ test_simple_log_2 (const sarif_generation_options &sarif_gen_opts,
     /* 000000000111111
        123456789012345.  */
     = "unsinged int i;\n";
-  diagnostic_show_locus_fixture f (case_, content);
+  source_printing_fixture f (case_, content);
   location_t line_end = linemap_position_for_column (line_table, 31);
 
   /* Don't attempt to run the tests if column data might be unavailable.  */
@@ -5056,7 +5055,7 @@ run_line_table_case_tests_per_version (const line_table_case &case_)
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_sarif_sink_cc_tests ()
+sarif_sink_cc_tests ()
 {
   test_sarif_array_of_unique_1 ();
   test_sarif_array_of_unique_2 ();
@@ -5070,6 +5069,7 @@ diagnostics_sarif_sink_cc_tests ()
   for_each_line_table_case (run_line_table_case_tests_per_version);
 }
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* CHECKING_P */
diff --git a/gcc/diagnostics/selftest-context.cc b/gcc/diagnostics/selftest-context.cc
index 918bd5e430b1..5dd7364053be 100644
--- a/gcc/diagnostics/selftest-context.cc
+++ b/gcc/diagnostics/selftest-context.cc
@@ -30,53 +30,54 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
-/* Implementation of class selftest::test_diagnostic_context.  */
+/* Implementation of class diagnostics::selftest::test_context.  */
 
-test_diagnostic_context::test_diagnostic_context ()
+test_context::test_context ()
 {
   diagnostic_initialize (this, 0);
   pp_show_color (get_reference_printer ()) = false;
   m_source_printing.enabled = true;
   m_source_printing.show_labels_p = true;
   m_show_column = true;
-  diagnostics::start_span (this) = start_span_cb;
+  start_span (this) = start_span_cb;
   m_source_printing.min_margin_width = 6;
   m_source_printing.max_width = 80;
   pp_buffer (get_sink (0).get_printer ())->m_flush_p = false;
 }
 
-test_diagnostic_context::~test_diagnostic_context ()
+test_context::~test_context ()
 {
   diagnostic_finish (this);
 }
 
-/* Implementation of diagnostic_start_span_fn, hiding the
+/* Implementation of diagnostics::start_span_fn, hiding the
    real filename (to avoid printing the names of tempfiles).  */
 
 void
-test_diagnostic_context::
-start_span_cb (const diagnostics::location_print_policy &loc_policy,
-	       diagnostics::to_text &sink,
+test_context::
+start_span_cb (const location_print_policy &loc_policy,
+	       to_text &sink,
 	       expanded_location exploc)
 {
   exploc.file = "FILENAME";
-  diagnostics::default_start_span_fn<diagnostics::to_text>
+  default_start_span_fn<to_text>
     (loc_policy, sink, exploc);
 }
 
 bool
-test_diagnostic_context::report (diagnostic_t kind,
-				 rich_location &richloc,
-				 const diagnostics::metadata *metadata,
-				 diagnostic_option_id option,
-				 const char * fmt, ...)
+test_context::report (diagnostic_t kind,
+		      rich_location &richloc,
+		      const metadata *metadata_,
+		      diagnostic_option_id option,
+		      const char * fmt, ...)
 {
   va_list ap;
   va_start (ap, fmt);
   begin_group ();
-  bool result = diagnostic_impl (&richloc, metadata, option, fmt, &ap, kind);
+  bool result = diagnostic_impl (&richloc, metadata_, option, fmt, &ap, kind);
   end_group ();
   va_end (ap);
   return result;
@@ -86,15 +87,16 @@ test_diagnostic_context::report (diagnostic_t kind,
    Return the text buffer from the printer.  */
 
 const char *
-test_diagnostic_context::test_show_locus (rich_location &richloc)
+test_context::test_show_locus (rich_location &richloc)
 {
   pretty_printer *pp = get_reference_printer ();
   gcc_assert (pp);
-  diagnostics::source_print_policy source_policy (*this);
+  source_print_policy source_policy (*this);
   source_policy.print (*pp, richloc, DK_ERROR, nullptr);
   return pp_formatted_text (pp);
 }
 
 } // namespace selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/selftest-context.h b/gcc/diagnostics/selftest-context.h
index afbc6611ed77..a1193347b754 100644
--- a/gcc/diagnostics/selftest-context.h
+++ b/gcc/diagnostics/selftest-context.h
@@ -25,22 +25,23 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
 /* Convenience subclass of diagnostics::context for testing
    the diagnostic subsystem.  */
 
-class test_diagnostic_context : public diagnostics::context
+class test_context : public context
 {
  public:
-  test_diagnostic_context ();
-  ~test_diagnostic_context ();
+  test_context ();
+  ~test_context ();
 
   /* Implementation of diagnostic_start_span_fn, hiding the
      real filename (to avoid printing the names of tempfiles).  */
   static void
-  start_span_cb (const diagnostics::location_print_policy &,
-		 diagnostics::to_text &sink,
+  start_span_cb (const location_print_policy &,
+		 to_text &sink,
 		 expanded_location exploc);
 
   /* Report a diagnostic to this context.  For a selftest, this
@@ -49,7 +50,7 @@ class test_diagnostic_context : public diagnostics::context
   bool
   report (diagnostic_t kind,
 	  rich_location &richloc,
-	  const diagnostics::metadata *metadata,
+	  const metadata *,
 	  diagnostic_option_id option,
 	  const char * fmt, ...) ATTRIBUTE_GCC_DIAG(6,7);
 
@@ -57,6 +58,7 @@ class test_diagnostic_context : public diagnostics::context
 };
 
 } // namespace selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
 
diff --git a/gcc/diagnostics/selftest-logical-locations.cc b/gcc/diagnostics/selftest-logical-locations.cc
index 08b684308855..66a92c41fc48 100644
--- a/gcc/diagnostics/selftest-logical-locations.cc
+++ b/gcc/diagnostics/selftest-logical-locations.cc
@@ -26,20 +26,20 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
+namespace logical_locations {
 namespace selftest {
 
-using namespace diagnostics::logical_locations;
+/* class test_manager : public manager.  */
 
-/* class test_logical_location_manager : public logical_location_manager.  */
-
-test_logical_location_manager::~test_logical_location_manager ()
+test_manager::~test_manager ()
 {
   for (auto iter : m_name_to_item_map)
     delete iter.second;
 }
 
 const char *
-test_logical_location_manager::get_short_name (key k) const
+test_manager::get_short_name (key k) const
 {
   auto item = item_from_key (k);
   if (!item)
@@ -48,43 +48,43 @@ test_logical_location_manager::get_short_name (key k) const
 }
 
 const char *
-test_logical_location_manager::get_name_with_scope (key k) const
+test_manager::get_name_with_scope (key k) const
 {
   auto item = item_from_key (k);
   return item->m_name;
 }
 
 const char *
-test_logical_location_manager::get_internal_name (key k) const
+test_manager::get_internal_name (key k) const
 {
   auto item = item_from_key (k);
   return item->m_name;
 }
 
 enum diagnostics::logical_locations::kind
-test_logical_location_manager::get_kind (key k) const
+test_manager::get_kind (key k) const
 {
   auto item = item_from_key (k);
   return item->m_kind;
 }
 
 label_text
-test_logical_location_manager::get_name_for_path_output (key k) const
+test_manager::get_name_for_path_output (key k) const
 {
   auto item = item_from_key (k);
   return label_text::borrow (item->m_name);
 }
 
 diagnostics::logical_locations::key
-test_logical_location_manager::
+test_manager::
 logical_location_from_funcname (const char *funcname)
 {
   const item *i = item_from_funcname (funcname);
   return key::from_ptr (i);
 }
 
-const test_logical_location_manager::item *
-test_logical_location_manager::item_from_funcname (const char *funcname)
+const test_manager::item *
+test_manager::item_from_funcname (const char *funcname)
 {
   if (!funcname)
     return nullptr;
@@ -100,9 +100,9 @@ test_logical_location_manager::item_from_funcname (const char *funcname)
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_selftest_logical_locations_cc_tests ()
+selftest_logical_locations_cc_tests ()
 {
-  test_logical_location_manager mgr;
+  test_manager mgr;
 
   ASSERT_FALSE (mgr.logical_location_from_funcname (nullptr));
 
@@ -115,6 +115,8 @@ diagnostics_selftest_logical_locations_cc_tests ()
   ASSERT_STREQ (mgr.get_short_name (loc_bar), "bar");
 }
 
-} // namespace selftest
+} // namespace diagnostics::logical_locations::selftest
+} // namespace diagnostics::logical_locations
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/selftest-logical-locations.h b/gcc/diagnostics/selftest-logical-locations.h
index d6a7a7464c25..0e9650135998 100644
--- a/gcc/diagnostics/selftest-logical-locations.h
+++ b/gcc/diagnostics/selftest-logical-locations.h
@@ -28,18 +28,16 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
+namespace logical_locations {
 namespace selftest {
 
 /* Concrete subclass of logical_locations::manager for use in selftests.  */
 
-class test_logical_location_manager
-  : public diagnostics::logical_locations::manager
+class test_manager : public manager
 {
 public:
-  using key = diagnostics::logical_locations::key;
-  using kind = diagnostics::logical_locations::kind;
-
-  ~test_logical_location_manager ();
+  ~test_manager ();
 
   const char *get_short_name (key) const final override;
   const char *get_name_with_scope (key) const final override;
@@ -79,9 +77,10 @@ private:
   hash_map<nofree_string_hash, item *> m_name_to_item_map;
 };
 
-} // namespace selftest
+} // namespace diagnostics::logical_locations::selftest
+} // namespace diagnostics::logical_locations::
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
 
-
 #endif /* GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H.  */
diff --git a/gcc/diagnostics/selftest-paths.cc b/gcc/diagnostics/selftest-paths.cc
index beb795ddab78..e002b503093f 100644
--- a/gcc/diagnostics/selftest-paths.cc
+++ b/gcc/diagnostics/selftest-paths.cc
@@ -31,13 +31,13 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
+namespace paths {
 namespace selftest {
 
-using namespace diagnostics::paths;
+/* class test_path : public diagnostics::paths::path.  */
 
-/* class test_diagnostic_path : public diagnostics::paths::path.  */
-
-test_diagnostic_path::test_diagnostic_path (pretty_printer *event_pp)
+test_path::test_path (pretty_printer *event_pp)
 : path (m_test_logical_loc_mgr),
   m_event_pp (event_pp)
 {
@@ -45,47 +45,47 @@ test_diagnostic_path::test_diagnostic_path (pretty_printer *event_pp)
 }
 
 /* Implementation of path::num_events vfunc for
-   test_diagnostic_path: simply get the number of events in the vec.  */
+   test_path: simply get the number of events in the vec.  */
 
 unsigned
-test_diagnostic_path::num_events () const
+test_path::num_events () const
 {
   return m_events.length ();
 }
 
-/* Implementation of diagnostic_path::get_event vfunc for
-   test_diagnostic_path: simply return the event in the vec.  */
+/* Implementation of path::get_event vfunc for
+   test_path: simply return the event in the vec.  */
 
 const event &
-test_diagnostic_path::get_event (int idx) const
+test_path::get_event (int idx) const
 {
   return *m_events[idx];
 }
 
 unsigned
-test_diagnostic_path::num_threads () const
+test_path::num_threads () const
 {
   return m_threads.length ();
 }
 
 const thread &
-test_diagnostic_path::get_thread (thread_id_t idx) const
+test_path::get_thread (thread_id_t idx) const
 {
   return *m_threads[idx];
 }
 
 bool
-test_diagnostic_path::same_function_p (int event_idx_a,
-				       int event_idx_b) const
+test_path::same_function_p (int event_idx_a,
+			    int event_idx_b) const
 {
   return (m_events[event_idx_a]->get_logical_location ()
 	  == m_events[event_idx_b]->get_logical_location ());
 }
 
 thread_id_t
-test_diagnostic_path::add_thread (const char *name)
+test_path::add_thread (const char *name)
 {
-  m_threads.safe_push (new test_diagnostic_thread (name));
+  m_threads.safe_push (new test_thread (name));
   return m_threads.length () - 1;
 }
 
@@ -98,10 +98,10 @@ test_diagnostic_path::add_thread (const char *name)
    Return the id of the new event.  */
 
 event_id_t
-test_diagnostic_path::add_event (location_t loc,
-				 const char *funcname,
-				 int depth,
-				 const char *fmt, ...)
+test_path::add_event (location_t loc,
+		      const char *funcname,
+		      int depth,
+		      const char *fmt, ...)
 {
   pretty_printer *pp = m_event_pp;
   pp_clear_output_area (pp);
@@ -119,11 +119,11 @@ test_diagnostic_path::add_event (location_t loc,
 
   va_end (ap);
 
-  test_diagnostic_event *new_event
-    = new test_diagnostic_event (loc,
-				 logical_location_from_funcname (funcname),
-				 depth,
-				 pp_formatted_text (pp));
+  test_event *new_event
+    = new test_event (loc,
+		      logical_location_from_funcname (funcname),
+		      depth,
+		      pp_formatted_text (pp));
   m_events.safe_push (new_event);
 
   pp_clear_output_area (pp);
@@ -132,11 +132,11 @@ test_diagnostic_path::add_event (location_t loc,
 }
 
 event_id_t
-test_diagnostic_path::add_thread_event (thread_id_t thread_id,
-					location_t loc,
-					const char *funcname,
-					int depth,
-					const char *fmt, ...)
+test_path::add_thread_event (thread_id_t thread_id,
+			     location_t loc,
+			     const char *funcname,
+			     int depth,
+			     const char *fmt, ...)
 {
   pretty_printer *pp = m_event_pp;
   pp_clear_output_area (pp);
@@ -155,12 +155,12 @@ test_diagnostic_path::add_thread_event (thread_id_t thread_id,
 
   va_end (ap);
 
-  test_diagnostic_event *new_event
-    = new test_diagnostic_event (loc,
-				 logical_location_from_funcname (funcname),
-				 depth,
-				 pp_formatted_text (pp),
-				 thread_id);
+  test_event *new_event
+    = new test_event (loc,
+		      logical_location_from_funcname (funcname),
+		      depth,
+		      pp_formatted_text (pp),
+		      thread_id);
   m_events.safe_push (new_event);
 
   pp_clear_output_area (pp);
@@ -172,35 +172,35 @@ test_diagnostic_path::add_thread_event (thread_id_t thread_id,
    connected to the next one to be added.  */
 
 void
-test_diagnostic_path::connect_to_next_event ()
+test_path::connect_to_next_event ()
 {
   gcc_assert (m_events.length () > 0);
   m_events[m_events.length () - 1]->connect_to_next_event ();
 }
 
 void
-test_diagnostic_path::add_entry (const char *callee_name,
-				 int stack_depth,
-				 thread_id_t thread_id)
+test_path::add_entry (const char *callee_name,
+		      int stack_depth,
+		      thread_id_t thread_id)
 {
   add_thread_event (thread_id, UNKNOWN_LOCATION, callee_name, stack_depth,
 		    "entering %qs", callee_name);
 }
 
 void
-test_diagnostic_path::add_return (const char *caller_name,
-				  int stack_depth,
-				  thread_id_t thread_id)
+test_path::add_return (const char *caller_name,
+		       int stack_depth,
+		       thread_id_t thread_id)
 {
   add_thread_event (thread_id, UNKNOWN_LOCATION, caller_name, stack_depth,
 		    "returning to %qs", caller_name);
 }
 
 void
-test_diagnostic_path::add_call (const char *caller_name,
-				int caller_stack_depth,
-				const char *callee_name,
-				thread_id_t thread_id)
+test_path::add_call (const char *caller_name,
+		     int caller_stack_depth,
+		     const char *callee_name,
+		     thread_id_t thread_id)
 {
   add_thread_event (thread_id, UNKNOWN_LOCATION,
 		    caller_name, caller_stack_depth,
@@ -208,22 +208,22 @@ test_diagnostic_path::add_call (const char *caller_name,
   add_entry (callee_name, caller_stack_depth + 1, thread_id);
 }
 
-diagnostics::logical_locations::key
-test_diagnostic_path::logical_location_from_funcname (const char *funcname)
+logical_locations::key
+test_path::logical_location_from_funcname (const char *funcname)
 {
   return m_test_logical_loc_mgr.logical_location_from_funcname (funcname);
 }
 
-/* struct test_diagnostic_event.  */
+/* struct test_event.  */
 
-/* test_diagnostic_event's ctor.  */
+/* test_event's ctor.  */
 
-test_diagnostic_event::
-test_diagnostic_event (location_t loc,
-		       logical_location logical_loc,
-		       int depth,
-		       const char *desc,
-		       thread_id_t thread_id)
+test_event::
+test_event (location_t loc,
+	    logical_location logical_loc,
+	    int depth,
+	    const char *desc,
+	    thread_id_t thread_id)
 : m_loc (loc),
   m_logical_loc (logical_loc),
   m_depth (depth), m_desc (xstrdup (desc)),
@@ -232,13 +232,15 @@ test_diagnostic_event (location_t loc,
 {
 }
 
-/* test_diagnostic_event's dtor.  */
+/* test_event's dtor.  */
 
-test_diagnostic_event::~test_diagnostic_event ()
+test_event::~test_event ()
 {
   free (m_desc);
 }
 
-} // namespace selftest
+} // namespace diagnostics::paths::selftest
+} // namespace diagnostics::paths
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
diff --git a/gcc/diagnostics/selftest-paths.h b/gcc/diagnostics/selftest-paths.h
index 39b591473f19..bb242a2486b4 100644
--- a/gcc/diagnostics/selftest-paths.h
+++ b/gcc/diagnostics/selftest-paths.h
@@ -29,6 +29,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
+namespace paths {
 namespace selftest {
 
 /* Concrete subclasses of the abstract base classes
@@ -36,20 +38,20 @@ namespace selftest {
 
    This code should have no dependency on "tree".  */
 
-/* An implementation of diagnostic_event.  */
+/* An implementation of diagnostics::paths::event.  */
 
-class test_diagnostic_event : public diagnostics::paths::event
+class test_event : public event
 {
  public:
-  using logical_location = diagnostics::logical_locations::key;
-  using thread_id_t = diagnostics::paths::thread_id_t;
+  using logical_location = logical_locations::key;
+  using thread_id_t = paths::thread_id_t;
 
-  test_diagnostic_event (location_t loc,
-			 logical_location logical_loc,
-			 int depth,
-			 const char *desc,
-			 thread_id_t thread_id = 0);
-  ~test_diagnostic_event ();
+  test_event (location_t loc,
+	      logical_location logical_loc,
+	      int depth,
+	      const char *desc,
+	      thread_id_t thread_id = 0);
+  ~test_event ();
 
   location_t get_location () const final override { return m_loc; }
   int get_stack_depth () const final override { return m_depth; }
@@ -90,10 +92,10 @@ class test_diagnostic_event : public diagnostics::paths::event
 
 /* A simple implementation of diagnostics::paths::thread.  */
 
-class test_diagnostic_thread : public diagnostics::paths::thread
+class test_thread : public thread
 {
 public:
-  test_diagnostic_thread (const char *name) : m_name (name) {}
+  test_thread (const char *name) : m_name (name) {}
   label_text get_name (bool) const final override
   {
     return label_text::borrow (m_name);
@@ -104,20 +106,15 @@ private:
 };
 
 /* A concrete subclass of diagnostics::paths::path for implementing selftests
-   - a vector of test_diagnostic_event instances
+   - a vector of test_event instances
    - adds member functions for adding test event
    - does no translation of its events
    - has no dependency on "tree".  */
 
-class test_diagnostic_path : public diagnostics::paths::path
+class test_path : public path
 {
  public:
-  using thread = diagnostics::paths::thread;
-  using thread_id_t = diagnostics::paths::thread_id_t;
-  using event = diagnostics::paths::event;
-  using event_id_t = diagnostics::paths::event_id_t;
-
-  test_diagnostic_path (pretty_printer *event_pp);
+  test_path (pretty_printer *event_pp);
 
   unsigned num_events () const final override;
   const event & get_event (int idx) const final override;
@@ -151,18 +148,20 @@ class test_diagnostic_path : public diagnostics::paths::path
 		 thread_id_t thread_id = 0);
 
  private:
-  diagnostics::logical_locations::key
+  logical_locations::key
   logical_location_from_funcname (const char *funcname);
 
-  test_logical_location_manager m_test_logical_loc_mgr;
-  auto_delete_vec<test_diagnostic_thread> m_threads;
-  auto_delete_vec<test_diagnostic_event> m_events;
+  logical_locations::selftest::test_manager m_test_logical_loc_mgr;
+  auto_delete_vec<test_thread> m_threads;
+  auto_delete_vec<test_event> m_events;
 
   /* (for use by add_event).  */
   pretty_printer *m_event_pp;
 };
 
-} // namespace selftest
+} // namespace diagnostics::paths::selftest
+} // namespace diagnostics::paths
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
 
diff --git a/gcc/diagnostics/selftest-source-printing.h b/gcc/diagnostics/selftest-source-printing.h
index 7b86d85adc12..8c5866d37cd5 100644
--- a/gcc/diagnostics/selftest-source-printing.h
+++ b/gcc/diagnostics/selftest-source-printing.h
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
 /* RAII class for use in selftests involving diagnostic_show_locus.
@@ -37,10 +38,10 @@ namespace selftest {
      push a line_map starting at the first line of the temporary file
    - provide a file_cache.  */
 
-struct diagnostic_show_locus_fixture
+struct source_printing_fixture
 {
-  diagnostic_show_locus_fixture (const line_table_case &case_,
-				 const char *content);
+  source_printing_fixture (const ::selftest::line_table_case &case_,
+			   const char *content);
 
   const char *get_filename () const
   {
@@ -48,8 +49,8 @@ struct diagnostic_show_locus_fixture
   }
 
   const char *m_content;
-  temp_source_file m_tmp_source_file;
-  line_table_test m_ltt;
+  ::selftest::temp_source_file m_tmp_source_file;
+  ::selftest::line_table_test m_ltt;
   file_cache m_fc;
 };
 
@@ -69,13 +70,14 @@ struct diagnostic_show_locus_fixture
    Here SS represents the two display columns for the U+1F602 emoji and
    P represents the one display column for the U+03C0 pi symbol.  */
 
-struct diagnostic_show_locus_fixture_one_liner_utf8
-  : public diagnostic_show_locus_fixture
+struct source_printing_fixture_one_liner_utf8
+  : public source_printing_fixture
 {
-  diagnostic_show_locus_fixture_one_liner_utf8 (const line_table_case &case_);
+  source_printing_fixture_one_liner_utf8 (const ::selftest::line_table_case &case_);
 };
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
 
diff --git a/gcc/diagnostics/source-printing.cc b/gcc/diagnostics/source-printing.cc
index ab18d8005f35..d5d374115daa 100644
--- a/gcc/diagnostics/source-printing.cc
+++ b/gcc/diagnostics/source-printing.cc
@@ -4032,8 +4032,15 @@ print (const diagnostics::source_print_policy &source_policy)
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
+using test_context = diagnostics::selftest::test_context;
+
+using line_table_case = ::selftest::line_table_case;
+using line_table_test = ::selftest::line_table_test;
+using temp_source_file = ::selftest::temp_source_file;
+
 static std::unique_ptr<xml::node>
 make_element_for_locus (const rich_location &rich_loc,
 			diagnostic_t kind,
@@ -4069,9 +4076,9 @@ make_raw_html_for_locus (const rich_location &rich_loc,
 
 /* Selftests for diagnostic_show_locus.  */
 
-diagnostic_show_locus_fixture::
-diagnostic_show_locus_fixture (const line_table_case &case_,
-			       const char *content)
+source_printing_fixture::
+source_printing_fixture (const line_table_case &case_,
+			 const char *content)
 : m_content (content),
   m_tmp_source_file (SELFTEST_LOCATION, ".c", content),
   m_ltt (case_),
@@ -4109,7 +4116,7 @@ test_display_widths ()
 
   /* No escaping.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     char_display_policy policy (make_char_policy (dc, richloc));
     ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 1);
     ASSERT_EQ (cpp_display_width (emoji, strlen (emoji), policy), 2);
@@ -4120,7 +4127,7 @@ test_display_widths ()
   richloc.set_escape_on_output (true);
 
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
     char_display_policy policy (make_char_policy (dc, richloc));
     ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 8);
@@ -4132,7 +4139,7 @@ test_display_widths ()
   }
 
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
     char_display_policy policy (make_char_policy (dc, richloc));
     ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 8);
@@ -4157,7 +4164,7 @@ test_offset_impl (int caret_byte_col, int max_width,
 		  int expected_x_offset_display,
 		  int left_margin = test_left_margin)
 {
-  test_diagnostic_context dc;
+  test_context dc;
   dc.m_source_printing.max_width = max_width;
   /* min_margin_width sets the minimum space reserved for
      the line number plus one space after.  */
@@ -4196,7 +4203,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
      no multibyte characters earlier on the line.  */
   const int emoji_col = 102;
 
-  diagnostic_show_locus_fixture f (case_, content);
+  source_printing_fixture f (case_, content);
 
   linemap_add (line_table, LC_ENTER, false, f.get_filename (), 1);
 
@@ -4273,7 +4280,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
 
   /* Test that the source line is offset as expected when printed.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.max_width = small_width - 6;
     dc.m_source_printing.min_margin_width
       = test_left_margin - test_linenum_sep + 1;
@@ -4303,7 +4310,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
      the first emoji in the middle of the UTF-8 sequence.  Check that we replace
      it with a padding space in this case.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.max_width = small_width - 5;
     dc.m_source_printing.min_margin_width
       = test_left_margin - test_linenum_sep + 1;
@@ -4394,7 +4401,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
 						      tab_col + 1));
   for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.m_tabstop = tabstop;
       diagnostics::source_print_policy policy (dc);
       layout test_layout (policy, richloc, nullptr);
@@ -4417,7 +4424,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
      over.  */
   for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.m_tabstop = tabstop;
       static const int small_width = 24;
       dc.m_source_printing.max_width = small_width - 4;
@@ -4455,7 +4462,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
 static void
 test_diagnostic_show_locus_unknown_location ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   rich_location richloc (line_table, UNKNOWN_LOCATION);
   ASSERT_STREQ ("", dc.test_show_locus (richloc));
 }
@@ -4475,7 +4482,7 @@ test_diagnostic_show_locus_unknown_location ()
 static void
 test_one_liner_simple_caret ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 10);
   rich_location richloc (line_table, caret);
   ASSERT_STREQ (" foo = bar.field;\n"
@@ -4489,7 +4496,7 @@ test_one_liner_simple_caret ()
 static void
 test_one_liner_no_column ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 0);
   rich_location richloc (line_table, caret);
   ASSERT_STREQ (" foo = bar.field;\n",
@@ -4501,7 +4508,7 @@ test_one_liner_no_column ()
 static void
 test_one_liner_caret_and_range ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 10);
   location_t start = linemap_position_for_column (line_table, 7);
   location_t finish = linemap_position_for_column (line_table, 15);
@@ -4512,7 +4519,7 @@ test_one_liner_caret_and_range ()
 		dc.test_show_locus (richloc));
 
   {
-    test_diagnostic_context dc;
+    test_context dc;
     auto out = make_raw_html_for_locus (richloc, DK_ERROR, dc);
      ASSERT_STREQ
        ("<table class=\"locus\">\n"
@@ -4524,7 +4531,7 @@ test_one_liner_caret_and_range ()
 	out.get ());
   }
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.show_line_numbers_p = true;
     auto out = make_raw_html_for_locus (richloc, DK_ERROR, dc);
      ASSERT_STREQ
@@ -4543,7 +4550,7 @@ test_one_liner_caret_and_range ()
 static void
 test_one_liner_multiple_carets_and_ranges ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t foo
     = make_location (linemap_position_for_column (line_table, 2),
 		     linemap_position_for_column (line_table, 1),
@@ -4575,7 +4582,7 @@ test_one_liner_multiple_carets_and_ranges ()
 static void
 test_one_liner_fixit_insert_before ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 7);
   rich_location richloc (line_table, caret);
   richloc.add_fixit_insert_before ("&");
@@ -4590,7 +4597,7 @@ test_one_liner_fixit_insert_before ()
 static void
 test_one_liner_fixit_insert_after ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t start = linemap_position_for_column (line_table, 1);
   location_t finish = linemap_position_for_column (line_table, 3);
   location_t foo = make_location (start, start, finish);
@@ -4617,7 +4624,7 @@ test_one_liner_fixit_remove ()
 
   /* Normal.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  "          ^~~~~~\n"
 		  "          ------\n",
@@ -4626,7 +4633,7 @@ test_one_liner_fixit_remove ()
 
   /* Test of adding a prefix.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     pp_prefixing_rule (dc.get_reference_printer ()) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
     pp_set_prefix (dc.get_reference_printer (), xstrdup ("TEST PREFIX:"));
     ASSERT_STREQ ("TEST PREFIX: foo = bar.field;\n"
@@ -4637,7 +4644,7 @@ test_one_liner_fixit_remove ()
 
   /* Normal, with ruler.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.show_ruler_p = true;
     dc.m_source_printing.max_width = 104;
     ASSERT_STREQ ("          0         0         0         0         0         0         0         0         0         1    \n"
@@ -4651,7 +4658,7 @@ test_one_liner_fixit_remove ()
 
   /* Test of adding a prefix, with ruler.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.show_ruler_p = true;
     dc.m_source_printing.max_width = 50;
     pp_prefixing_rule (dc.get_reference_printer ()) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
@@ -4666,7 +4673,7 @@ test_one_liner_fixit_remove ()
 
   /* Test of adding a prefix, with ruler and line numbers.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.show_ruler_p = true;
     dc.m_source_printing.max_width = 50;
     dc.m_source_printing.show_line_numbers_p = true;
@@ -4686,7 +4693,7 @@ test_one_liner_fixit_remove ()
 static void
 test_one_liner_fixit_replace ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t start = linemap_position_for_column (line_table, 11);
   location_t finish = linemap_position_for_column (line_table, 15);
   location_t field = make_location (start, start, finish);
@@ -4704,7 +4711,7 @@ test_one_liner_fixit_replace ()
 static void
 test_one_liner_fixit_replace_non_equal_range ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 5);
   location_t start = linemap_position_for_column (line_table, 11);
   location_t finish = linemap_position_for_column (line_table, 15);
@@ -4729,7 +4736,7 @@ test_one_liner_fixit_replace_non_equal_range ()
 static void
 test_one_liner_fixit_replace_equal_secondary_range ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 5);
   location_t start = linemap_position_for_column (line_table, 11);
   location_t finish = linemap_position_for_column (line_table, 15);
@@ -4770,7 +4777,7 @@ test_one_liner_fixit_validation_adhoc_locations ()
     /* It should not have been discarded by the validator.  */
     ASSERT_EQ (1, richloc.get_num_fixit_hints ());
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  "       ^~~~~~~~~~                               "
 		  "          "
@@ -4796,7 +4803,7 @@ test_one_liner_fixit_validation_adhoc_locations ()
     /* It should not have been discarded by the validator.  */
     ASSERT_EQ (1, richloc.get_num_fixit_hints ());
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  "       ^~~~~~~~~~                               "
 		  "          "
@@ -4833,7 +4840,7 @@ test_one_liner_fixit_validation_adhoc_locations ()
     /* It should not have been discarded by the validator.  */
     ASSERT_EQ (1, richloc.get_num_fixit_hints ());
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  "       ^~~~~~~~~~                               "
 		  "          "
@@ -4857,7 +4864,7 @@ test_one_liner_fixit_validation_adhoc_locations ()
 static void
 test_one_liner_many_fixits_1 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 5);
   rich_location richloc (line_table, equals);
   for (int i = 0; i < 19; i++)
@@ -4875,7 +4882,7 @@ test_one_liner_many_fixits_1 ()
 static void
 test_one_liner_many_fixits_2 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 5);
   rich_location richloc (line_table, equals);
   for (int i = 0; i < 19; i++)
@@ -4918,7 +4925,7 @@ test_one_liner_labels ()
     richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
 
     {
-      test_diagnostic_context dc;
+      test_context dc;
       ASSERT_STREQ (" foo = bar.field;\n"
 		    " ^~~   ~~~ ~~~~~\n"
 		    " |     |   |\n"
@@ -4928,7 +4935,7 @@ test_one_liner_labels ()
 
     /* Verify that we can disable label-printing.  */
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.m_source_printing.show_labels_p = false;
       ASSERT_STREQ (" foo = bar.field;\n"
 		    " ^~~   ~~~ ~~~~~\n",
@@ -4945,7 +4952,7 @@ test_one_liner_labels ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label1);
     richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  " ^~~   ~~~ ~~~~~\n"
 		  " |     |   |\n"
@@ -4955,7 +4962,7 @@ test_one_liner_labels ()
 		  dc.test_show_locus (richloc));
 
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.m_source_printing.show_line_numbers_p = true;
       auto out = make_raw_html_for_locus (richloc, DK_ERROR, dc);
       ASSERT_STREQ
@@ -4983,7 +4990,7 @@ test_one_liner_labels ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label1);
     richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  " ^~~   ~~~ ~~~~~\n"
 		  " |     |   |\n"
@@ -5001,7 +5008,7 @@ test_one_liner_labels ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label1);
     richloc.add_range (foo, SHOW_RANGE_WITHOUT_CARET, &label2);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  " ~~~   ~~~ ^~~~~\n"
 		  " |     |   |\n"
@@ -5019,7 +5026,7 @@ test_one_liner_labels ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label1);
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label2);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  "       ^~~\n"
 		  "       |\n"
@@ -5053,7 +5060,7 @@ test_one_liner_labels ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label_1c);
     richloc.add_range (foo, SHOW_RANGE_WITHOUT_CARET, &label_2c);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  " ~~~   ~~~ ^~~~~\n"
 		  " |     |   |\n"
@@ -5075,7 +5082,7 @@ test_one_liner_labels ()
     text_range_label label (nullptr);
     gcc_rich_location richloc (bar, &label, nullptr);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" foo = bar.field;\n"
 		  "       ^~~\n",
 		  dc.test_show_locus (richloc));
@@ -5095,7 +5102,7 @@ test_diagnostic_show_locus_one_liner (const line_table_case &case_)
      ....................1234567890123456.  */
   const char *content = "foo = bar.field;\n";
 
-  diagnostic_show_locus_fixture f (case_, content);
+  source_printing_fixture f (case_, content);
 
   location_t line_end = linemap_position_for_column (line_table, 16);
 
@@ -5125,7 +5132,7 @@ test_diagnostic_show_locus_one_liner (const line_table_case &case_)
 
 /* Version of all one-liner tests exercising multibyte awareness.
    These are all called from test_diagnostic_show_locus_one_liner,
-   which uses diagnostic_show_locus_fixture_one_liner_utf8 to create
+   which uses source_printing_fixture_one_liner_utf8 to create
    the test file; see the notes in diagnostic-show-locus-selftest.h.
 
    Note: all of the below asserts would be easier to read if we used UTF-8
@@ -5140,7 +5147,7 @@ test_diagnostic_show_locus_one_liner (const line_table_case &case_)
 static void
 test_one_liner_simple_caret_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 18);
   rich_location richloc (line_table, caret);
   ASSERT_STREQ (" \xf0\x9f\x98\x82"
@@ -5156,7 +5163,7 @@ test_one_liner_simple_caret_utf8 ()
 static void
 test_one_liner_caret_and_range_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 18);
   location_t start = linemap_position_for_column (line_table, 12);
   location_t finish = linemap_position_for_column (line_table, 30);
@@ -5176,7 +5183,7 @@ test_one_liner_caret_and_range_utf8 ()
 static void
 test_one_liner_multiple_carets_and_ranges_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t foo
     = make_location (linemap_position_for_column (line_table, 7),
 		     linemap_position_for_column (line_table, 1),
@@ -5211,7 +5218,7 @@ test_one_liner_multiple_carets_and_ranges_utf8 ()
 static void
 test_one_liner_fixit_insert_before_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t caret = linemap_position_for_column (line_table, 12);
   rich_location richloc (line_table, caret);
   richloc.add_fixit_insert_before ("&");
@@ -5230,7 +5237,7 @@ test_one_liner_fixit_insert_before_utf8 ()
 static void
 test_one_liner_fixit_insert_after_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t start = linemap_position_for_column (line_table, 1);
   location_t finish = linemap_position_for_column (line_table, 8);
   location_t foo = make_location (start, start, finish);
@@ -5251,7 +5258,7 @@ test_one_liner_fixit_insert_after_utf8 ()
 static void
 test_one_liner_fixit_remove_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t start = linemap_position_for_column (line_table, 18);
   location_t finish = linemap_position_for_column (line_table, 30);
   location_t dot = make_location (start, start, finish);
@@ -5272,7 +5279,7 @@ test_one_liner_fixit_remove_utf8 ()
 static void
 test_one_liner_fixit_replace_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t start = linemap_position_for_column (line_table, 19);
   location_t finish = linemap_position_for_column (line_table, 30);
   location_t field = make_location (start, start, finish);
@@ -5295,7 +5302,7 @@ test_one_liner_fixit_replace_utf8 ()
 static void
 test_one_liner_fixit_replace_non_equal_range_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 10);
   location_t start = linemap_position_for_column (line_table, 19);
   location_t finish = linemap_position_for_column (line_table, 30);
@@ -5325,7 +5332,7 @@ test_one_liner_fixit_replace_non_equal_range_utf8 ()
 static void
 test_one_liner_fixit_replace_equal_secondary_range_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 10);
   location_t start = linemap_position_for_column (line_table, 19);
   location_t finish = linemap_position_for_column (line_table, 30);
@@ -5371,7 +5378,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 ()
     /* It should not have been discarded by the validator.  */
     ASSERT_EQ (1, richloc.get_num_fixit_hints ());
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" \xf0\x9f\x98\x82"
 		     "_foo = \xcf\x80"
 			     "_bar.\xf0\x9f\x98\x82"
@@ -5401,7 +5408,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 ()
     /* It should not have been discarded by the validator.  */
     ASSERT_EQ (1, richloc.get_num_fixit_hints ());
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" \xf0\x9f\x98\x82"
 		     "_foo = \xcf\x80"
 			     "_bar.\xf0\x9f\x98\x82"
@@ -5442,7 +5449,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 ()
     /* It should not have been discarded by the validator.  */
     ASSERT_EQ (1, richloc.get_num_fixit_hints ());
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" \xf0\x9f\x98\x82"
 		     "_foo = \xcf\x80"
 			     "_bar.\xf0\x9f\x98\x82"
@@ -5470,7 +5477,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 ()
 static void
 test_one_liner_many_fixits_1_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 10);
   rich_location richloc (line_table, equals);
   for (int i = 0; i < 19; i++)
@@ -5493,7 +5500,7 @@ test_one_liner_many_fixits_1_utf8 ()
 static void
 test_one_liner_many_fixits_2_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   location_t equals = linemap_position_for_column (line_table, 10);
   rich_location richloc (line_table, equals);
   const int nlocs = 19;
@@ -5554,7 +5561,7 @@ test_one_liner_labels_utf8 ()
     richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
 
     {
-      test_diagnostic_context dc;
+      test_context dc;
       ASSERT_STREQ (" \xf0\x9f\x98\x82"
 		       "_foo = \xcf\x80"
 			       "_bar.\xf0\x9f\x98\x82"
@@ -5580,7 +5587,7 @@ test_one_liner_labels_utf8 ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label1);
     richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" \xf0\x9f\x98\x82"
 		     "_foo = \xcf\x80"
 			     "_bar.\xf0\x9f\x98\x82"
@@ -5604,7 +5611,7 @@ test_one_liner_labels_utf8 ()
     richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label1);
     richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
 
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" \xf0\x9f\x98\x82"
 		     "_foo = \xcf\x80"
 			     "_bar.\xf0\x9f\x98\x82"
@@ -5629,7 +5636,7 @@ test_one_liner_labels_utf8 ()
     richloc.set_escape_on_output (true);
 
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
       ASSERT_STREQ (" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
 		    " ^~~~~~~~~~~~~   ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"
@@ -5640,7 +5647,7 @@ test_one_liner_labels_utf8 ()
 		    dc.test_show_locus (richloc));
     }
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
       ASSERT_STREQ
 	(" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
@@ -5659,7 +5666,7 @@ test_one_liner_labels_utf8 ()
 static void
 test_one_liner_colorized_utf8 ()
 {
-  test_diagnostic_context dc;
+  test_context dc;
   dc.m_source_printing.colorize_source_p = true;
   diagnostic_color_init (&dc, DIAGNOSTICS_COLOR_YES);
   const location_t pi = linemap_position_for_column (line_table, 12);
@@ -5683,9 +5690,9 @@ static const char * const one_liner_utf8_content
      1111222233334444567890122223333456789999000011112222345678999900001
      Byte columns.  */
 
-diagnostic_show_locus_fixture_one_liner_utf8::
-diagnostic_show_locus_fixture_one_liner_utf8 (const line_table_case &case_)
-: diagnostic_show_locus_fixture (case_, one_liner_utf8_content)
+source_printing_fixture_one_liner_utf8::
+source_printing_fixture_one_liner_utf8 (const line_table_case &case_)
+: source_printing_fixture (case_, one_liner_utf8_content)
 {
 }
 
@@ -5694,7 +5701,7 @@ diagnostic_show_locus_fixture_one_liner_utf8 (const line_table_case &case_)
 static void
 test_diagnostic_show_locus_one_liner_utf8 (const line_table_case &case_)
 {
-  diagnostic_show_locus_fixture_one_liner_utf8 f (case_);
+  source_printing_fixture_one_liner_utf8 f (case_);
 
   location_t line_end = linemap_position_for_column (line_table, 31);
 
@@ -5763,7 +5770,7 @@ test_add_location_if_nearby (const line_table_case &case_)
   /* Test of add_location_if_nearby on the same line as the
      primary location.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     const location_t missing_close_brace_1_39
       = linemap_position_for_line_and_column (line_table, ord_map, 1, 39);
     const location_t matching_open_brace_1_18
@@ -5781,7 +5788,7 @@ test_add_location_if_nearby (const line_table_case &case_)
   /* Test of add_location_if_nearby on a different line to the
      primary location.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     const location_t missing_close_brace_6_1
       = linemap_position_for_line_and_column (line_table, ord_map, 6, 1);
     const location_t matching_open_brace_3_1
@@ -5830,7 +5837,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_)
 
   /* The one-liner case (line 2).  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     const location_t x
       = linemap_position_for_line_and_column (line_table, ord_map, 2, 24);
     const location_t colon
@@ -5849,7 +5856,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_)
      span starts are printed due to the gap between the span at line 3
      and that at line 6).  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     const location_t y
       = linemap_position_for_line_and_column (line_table, ord_map, 3, 24);
     const location_t colon
@@ -5877,7 +5884,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_)
     rich_location richloc (line_table, colon);
     richloc.add_fixit_insert_before (y, ".");
     richloc.add_fixit_replace (colon, "=");
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.show_line_numbers_p = true;
     ASSERT_STREQ ("    3 |                        y\n"
 		  "      |                        .\n"
@@ -6083,7 +6090,7 @@ test_overlapped_fixit_printing (const line_table_case &case_)
 
   /* Example where 3 fix-it hints are printed as one.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_replace (open_paren, "const_cast<");
     richloc.add_fixit_replace (close_paren, "> (");
@@ -6152,7 +6159,7 @@ test_overlapped_fixit_printing (const line_table_case &case_)
 
   /* Example where two are consolidated during printing.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_replace (open_paren, "CAST (");
     richloc.add_fixit_replace (close_paren, ") (");
@@ -6168,7 +6175,7 @@ test_overlapped_fixit_printing (const line_table_case &case_)
 
   /* Example where none are consolidated during printing.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_replace (open_paren, "CST (");
     richloc.add_fixit_replace (close_paren, ") (");
@@ -6184,7 +6191,7 @@ test_overlapped_fixit_printing (const line_table_case &case_)
 
   /* Example of deletion fix-it hints.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_insert_before (open_paren, "(bar *)");
     source_range victim = {open_paren, close_paren};
@@ -6203,7 +6210,7 @@ test_overlapped_fixit_printing (const line_table_case &case_)
 
   /* Example of deletion fix-it hints that would overlap.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_insert_before (open_paren, "(longer *)");
     source_range victim = {expr_start, expr_finish};
@@ -6222,7 +6229,7 @@ test_overlapped_fixit_printing (const line_table_case &case_)
 
   /* Example of insertion fix-it hints that would overlap.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_insert_before (open_paren, "LONGER THAN THE CAST");
     richloc.add_fixit_insert_after (close_paren, "TEST");
@@ -6288,7 +6295,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_)
 
   /* Example where 3 fix-it hints are printed as one.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     file_cache &fc = dc.get_file_cache ();
     rich_location richloc (line_table, expr);
     richloc.add_fixit_replace (open_paren, "const_cast<");
@@ -6364,7 +6371,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_)
 
   /* Example where two are consolidated during printing.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_replace (open_paren, "CAST (");
     richloc.add_fixit_replace (close_paren, ") (");
@@ -6383,7 +6390,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_)
 
   /* Example where none are consolidated during printing.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_replace (open_paren, "CST (");
     richloc.add_fixit_replace (close_paren, ") (");
@@ -6402,7 +6409,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_)
 
   /* Example of deletion fix-it hints.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_insert_before (open_paren, "(bar\xf0\x9f\x98\x82 *)");
     source_range victim = {open_paren, close_paren};
@@ -6425,7 +6432,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_)
 
   /* Example of deletion fix-it hints that would overlap.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_insert_before (open_paren, "(long\xf0\x9f\x98\x82 *)");
     source_range victim = {expr_start, expr_finish};
@@ -6449,7 +6456,7 @@ test_overlapped_fixit_printing_utf8 (const line_table_case &case_)
 
   /* Example of insertion fix-it hints that would overlap.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, expr);
     richloc.add_fixit_insert_before
       (open_paren, "L\xf0\x9f\x98\x82NGER THAN THE CAST");
@@ -6513,7 +6520,7 @@ test_overlapped_fixit_printing_2 (const line_table_case &case_)
 
   /* Two insertions, in the wrong order.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     file_cache &fc = dc.get_file_cache ();
 
     rich_location richloc (line_table, col_20);
@@ -6542,7 +6549,7 @@ test_overlapped_fixit_printing_2 (const line_table_case &case_)
   /* Various overlapping insertions, some occurring "out of order"
      (reproducing the fix-it hints from PR c/81405).  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     rich_location richloc (line_table, col_20);
 
     richloc.add_fixit_insert_before (col_20, "{{");
@@ -6596,7 +6603,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_)
 
     /* Without line numbers.  */
     {
-      test_diagnostic_context dc;
+      test_context dc;
       ASSERT_STREQ ("       x = a;\n"
 		    "+      break;\n"
 		    "     case 'b':\n"
@@ -6606,7 +6613,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_)
 
     /* With line numbers.  */
     {
-      test_diagnostic_context dc;
+      test_context dc;
       dc.m_source_printing.show_line_numbers_p = true;
       ASSERT_STREQ ("    2 |       x = a;\n"
 		    "  +++ |+      break;\n"
@@ -6622,7 +6629,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_)
     rich_location richloc (line_table, case_loc);
     richloc.add_fixit_insert_before (case_start, "break;\n");
     ASSERT_TRUE (richloc.seen_impossible_fixit_p ());
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ ("     case 'b':\n"
 		  "     ^~~~~~~~~\n",
 		  dc.test_show_locus (richloc));
@@ -6669,7 +6676,7 @@ test_fixit_insert_containing_newline_2 (const line_table_case &case_)
     return;
 
   {
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ ("FILENAME:1:1:\n"
 		  "+#include <stdio.h>\n"
 		  " test (int ch)\n"
@@ -6682,7 +6689,7 @@ test_fixit_insert_containing_newline_2 (const line_table_case &case_)
   /* With line-numbering, the line spans are close enough to be
      consolidated, since it makes little sense to skip line 2.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_source_printing.show_line_numbers_p = true;
     ASSERT_STREQ ("  +++ |+#include <stdio.h>\n"
 		  "    1 | test (int ch)\n"
@@ -6725,7 +6732,7 @@ test_fixit_replace_containing_newline (const line_table_case &case_)
   if (finish > LINE_MAP_MAX_LOCATION_WITH_COLS)
     return;
 
-  test_diagnostic_context dc;
+  test_context dc;
   ASSERT_STREQ (" foo = bar ();\n"
 		"             ^\n",
 		dc.test_show_locus (richloc));
@@ -6768,7 +6775,7 @@ test_fixit_deletion_affecting_newline (const line_table_case &case_)
   if (finish > LINE_MAP_MAX_LOCATION_WITH_COLS)
     return;
 
-  test_diagnostic_context dc;
+  test_context dc;
   ASSERT_STREQ (" foo = bar (\n"
 		"          ~^\n"
 		"       );\n"
@@ -6808,7 +6815,7 @@ test_tab_expansion (const line_table_case &case_)
      into 11 spaces.  Recall that print_line() also puts one space before
      everything too.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_tabstop = tabstop;
     rich_location richloc (line_table,
 			   linemap_position_for_column (line_table,
@@ -6821,7 +6828,7 @@ test_tab_expansion (const line_table_case &case_)
   /* Confirm the display width was tracked correctly across the internal tab
      as well.  */
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.m_tabstop = tabstop;
     rich_location richloc (line_table,
 			   linemap_position_for_column (line_table,
@@ -6862,14 +6869,14 @@ test_escaping_bytes_1 (const line_table_case &case_)
   richloc.add_range (v_loc);
 
   {
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ (" before \1\2\3\v\x80\xff""after\n"
 		  "       ^   ~\n",
 		  dc.test_show_locus (richloc));
   }
   richloc.set_escape_on_output (true);
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
     ASSERT_STREQ
       (" before<U+0000><U+0001><U+0002><U+0003><U+000B><80><ff>after\n"
@@ -6877,7 +6884,7 @@ test_escaping_bytes_1 (const line_table_case &case_)
        dc.test_show_locus (richloc));
   }
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
     ASSERT_STREQ (" before<00><01><02><03><0b><80><ff>after\n"
 		  "       ^~~~            ~~~~\n",
@@ -6912,21 +6919,21 @@ test_escaping_bytes_2 (const line_table_case &case_)
   gcc_rich_location richloc (nul_loc);
 
   {
-    test_diagnostic_context dc;
+    test_context dc;
     ASSERT_STREQ ("  after\n"
 		  " ^\n",
 		  dc.test_show_locus (richloc));
   }
   richloc.set_escape_on_output (true);
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
     ASSERT_STREQ (" <U+0000>after\n"
 		  " ^~~~~~~~\n",
 		  dc.test_show_locus (richloc));
   }
   {
-    test_diagnostic_context dc;
+    test_context dc;
     dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
     ASSERT_STREQ (" <00>after\n"
 		  " ^~~~\n",
@@ -6965,7 +6972,7 @@ test_line_numbers_multiline_range ()
     = linemap_position_for_line_and_column (line_table, ord_map, 11, 4);
   location_t loc = make_location (caret, start, finish);
 
-  test_diagnostic_context dc;
+  test_context dc;
   dc.m_source_printing.show_line_numbers_p = true;
   dc.m_source_printing.min_margin_width = 0;
   gcc_rich_location richloc (loc);
@@ -6981,7 +6988,7 @@ test_line_numbers_multiline_range ()
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_source_printing_cc_tests ()
+source_printing_cc_tests ()
 {
   test_line_span ();
 
@@ -7017,7 +7024,8 @@ diagnostics_source_printing_cc_tests ()
   test_line_numbers_multiline_range ();
 }
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* #if CHECKING_P */
 
diff --git a/gcc/diagnostics/state-graphs.cc b/gcc/diagnostics/state-graphs.cc
index e2c8c1d33cf7..83f35327c53b 100644
--- a/gcc/diagnostics/state-graphs.cc
+++ b/gcc/diagnostics/state-graphs.cc
@@ -123,13 +123,14 @@ state_node_ref::set_json_attr (const char *key,
 
 #if CHECKING_P
 
+namespace diagnostics {
 namespace selftest {
 
 static void
 test_node_attrs ()
 {
-  diagnostics::digraphs::digraph g;
-  diagnostics::digraphs::node n (g, "a");
+  digraphs::digraph g;
+  digraphs::node n (g, "a");
   state_node_ref node_ref (n);
 
   ASSERT_EQ (node_ref.get_node_kind (), node_kind::other);
@@ -148,11 +149,12 @@ test_node_attrs ()
 /* Run all of the selftests within this file.  */
 
 void
-diagnostics_state_graphs_cc_tests ()
+state_graphs_cc_tests ()
 {
   test_node_attrs ();
 }
 
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
 
 #endif /* CHECKING_P */
diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc
index f88c1cf6dc79..c68d3e79a310 100644
--- a/gcc/selftest-run-tests.cc
+++ b/gcc/selftest-run-tests.cc
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stringpool.h"
 #include "attribs.h"
 #include "analyzer/analyzer-selftests.h"
+#include "diagnostics/diagnostics-selftests.h"
 #include "text-art/selftests.h"
 
 /* This function needed to be split out from selftest.cc as it references
@@ -94,20 +95,12 @@ selftest::run_tests ()
   digraph_cc_tests ();
   tristate_cc_tests ();
   ipa_modref_tree_cc_tests ();
-  diagnostics_selftest_logical_locations_cc_tests ();
+
+  /* Run the diagnostics selftests.  */
+  diagnostics::selftest::run_diagnostics_selftests ();
 
   /* Higher-level tests, or for components that other selftests don't
      rely on.  */
-  diagnostics_color_cc_tests ();
-  diagnostics_source_printing_cc_tests ();
-  diagnostics_html_sink_cc_tests ();
-  diagnostics_sarif_sink_cc_tests ();
-  diagnostics_digraphs_cc_tests ();
-  diagnostics_output_spec_cc_tests ();
-  diagnostics_state_graphs_cc_tests ();
-  diagnostics_lazy_paths_cc_tests ();
-  diagnostics_paths_output_cc_tests ();
-  edit_context_cc_tests ();
   fold_const_cc_tests ();
   spellcheck_cc_tests ();
   spellcheck_tree_cc_tests ();
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 06ce4a01f3a4..d57f3d63b5d2 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -221,19 +221,8 @@ extern void bitmap_cc_tests ();
 extern void cgraph_cc_tests ();
 extern void convert_cc_tests ();
 extern void dbgcnt_cc_tests ();
-extern void diagnostics_color_cc_tests ();
-extern void diagnostics_digraphs_cc_tests ();
-extern void diagnostics_html_sink_cc_tests ();
-extern void diagnostics_lazy_paths_cc_tests ();
-extern void diagnostics_output_spec_cc_tests ();
-extern void diagnostics_paths_output_cc_tests ();
-extern void diagnostics_sarif_sink_cc_tests ();
-extern void diagnostics_selftest_logical_locations_cc_tests ();
-extern void diagnostics_source_printing_cc_tests ();
-extern void diagnostics_state_graphs_cc_tests ();
 extern void digraph_cc_tests ();
 extern void dumpfile_cc_tests ();
-extern void edit_context_cc_tests ();
 extern void et_forest_cc_tests ();
 extern void fibonacci_heap_cc_tests ();
 extern void fold_const_cc_tests ();
diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
index c6fe3016f896..225b8d59b59f 100644
--- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
+++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
@@ -47,7 +47,7 @@ static void
 test_richloc (rich_location *richloc)
 {
   /* Run the diagnostic and fix-it printing code.  */
-  test_diagnostic_context dc;
+  diagnostics::selftest::test_context dc;
   diagnostic_show_locus (&dc, dc.m_source_printing,
 			 richloc, DK_ERROR, dc.get_reference_printer ());
 
-- 
2.26.3

