No functional change intended.
gcc/ChangeLog:
* Makefile.in (OBJS): Move diagnostics/lazy-paths.o to...
(OBJS-libcommon): ...here. Add
diagnostics/diagnostics-selftests.o.
* diagnostic.cc: Update for move of
selftest::test_diagnostic_context to
diagnostics::selftest::test_context.
* diagnostics/color.cc: Move selftests from selftest:: to
diagnostics::selftest::.
* diagnostics/diagnostics-selftests.cc: New file.
* diagnostics/diagnostics-selftests.h: New file.
* diagnostics/digraphs.cc: Move selftests from selftest:: to
diagnostics::selftest::.
* diagnostics/edit-context.cc: Likewise.
* diagnostics/html-sink.cc: Likewise.
* diagnostics/lazy-paths.cc: Likewise. Eliminate use of "tree"
by porting selftests from simple-diagnostic-path.h to
diagnostics/selftest-paths.h.
* diagnostics/output-spec.cc: Move selftests from selftest:: to
diagnostics::selftest::.
* diagnostics/paths-output.cc: Likewise.
* diagnostics/sarif-sink.cc: Likewise.
* diagnostics/selftest-context.cc: Move
selftest::test_diagnostic_context to
diagnostics::selftest::test_context.
* diagnostics/selftest-context.h: Likewise.
* diagnostics/selftest-logical-locations.cc: Move selftests from
selftest:: to diagnostics::logical_locations::selftest::.
* diagnostics/selftest-logical-locations.h: Move
selftest::logical_location_manager to
diagnostics::logical_locations::selftest::logical_location_manager.
* diagnostics/selftest-paths.cc: Move
selftest::test_diagnostic_path to
diagnostics::paths::selftest::test_path. Move
selftest::test_diagnostic_event to
diagnostics::paths::selftest::test_event.
* diagnostics/selftest-paths.h: Likewise, and move
selftest::test_diagnostic_thread to
diagnostics::paths::selftest::test_thread.
* diagnostics/selftest-source-printing.h: Move
selftest::diagnostic_show_locus_fixture to
diagnostics::selftest::source_printing_fixture.
* diagnostics/source-printing.cc: Move selftests from selftest::
to diagnostics::selftest:: and update for renames.
* diagnostics/state-graphs.cc: Likewise.
* selftest-run-tests.cc: Include
"diagnostics/diagnostics-selftests.h".
(selftest::run_tests): Replace invocation of the various diagnostics
selftests with a call to
diagnostics::selftest::run_diagnostics_selftests.
* selftest.h: Move decls of the various per-file diagnostics
invocation functions to diagnostics/diagnostics-selftests.h,
renaming due to diagostics prefix being implied by namespace.
gcc/c-family/ChangeLog:
* c-format.cc (test_type_mismatch_range_labels): Update for
move of selftest::test_diagnostic_context to
diagnostics::selftest::test_context.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/expensive_selftests_plugin.cc: Update for move of
selftest::test_diagnostic_context to
diagnostics::selftest::test_context.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
df-problems.o \
df-scan.o \
dfp.o \
- diagnostics/lazy-paths.o \
digraph.o \
dojump.o \
dominance.o \
diagnostics/html-sink.o \
diagnostics/sarif-sink.o \
diagnostics/text-sink.o \
+ diagnostics/lazy-paths.o \
diagnostics/macro-unwinding.o \
diagnostics/option-classifier.o \
diagnostics/paths.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 \
gcc_rich_location richloc (fmt, &fmt_label, nullptr);
richloc.add_range (param, SHOW_RANGE_WITHOUT_CARET, ¶m_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 ());
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;
#if CHECKING_P
+namespace diagnostics {
namespace selftest {
/* Test of an empty diagnostic_color_dict. */
/* Run all of the selftests within this file. */
void
-diagnostics_color_cc_tests ()
+color_cc_tests ()
{
test_empty_color_dict ();
test_default_color_dict ();
}
} // namespace selftest
+} // namespace diagnostics
#endif /* #if CHECKING_P */
--- /dev/null
+/* 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 */
--- /dev/null
+/* 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 */
#if CHECKING_P
+namespace diagnostics {
namespace selftest {
static void
/* 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 */
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. */
}
} // namespace selftest
+} // namespace diagnostics
#endif /* CHECKING_P */
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>. */
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;
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");
static void
test_metadata ()
{
- test_html_diagnostic_context dc;
+ test_html_context dc;
html_builder &b = dc.get_builder ();
{
/* 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 */
#define INCLUDE_VECTOR
#include "system.h"
#include "coretypes.h"
-#include "tree.h"
-#include "version.h"
-#include "intl.h"
#include "diagnostic.h"
#include "diagnostics/lazy-paths.h"
#include "selftest.h"
#include "diagnostics/selftest-context.h"
-#include "simple-diagnostic-path.h"
-#include "gcc-rich-location.h"
+#include "diagnostics/selftest-paths.h"
#include "diagnostics/text-sink.h"
using namespace diagnostics::paths;
#if CHECKING_P
+namespace diagnostics {
namespace selftest {
+using auto_fix_quotes = ::selftest::auto_fix_quotes;
+
class test_lazy_path : public lazy_path
{
public:
}
std::unique_ptr<path> make_inner_path () const final override
{
- tree fntype_void_void
- = build_function_type_array (void_type_node, 0, nullptr);
- tree fndecl_foo = build_fn_decl ("foo", fntype_void_void);
auto path
- = std::make_unique<simple_diagnostic_path> (m_logical_loc_mgr,
- &m_pp);
- path->add_event (UNKNOWN_LOCATION, fndecl_foo, 0, "first %qs", "free");
- path->add_event (UNKNOWN_LOCATION, fndecl_foo, 0, "double %qs", "free");
+ = std::make_unique<paths::selftest::test_path> (m_logical_loc_mgr,
+ &m_pp);
+ path->add_event (UNKNOWN_LOCATION, "foo", 0, "first %qs", "free");
+ path->add_event (UNKNOWN_LOCATION, "foo", 0, "double %qs", "free");
return path;
}
private:
- const tree_logical_location_manager m_logical_loc_mgr;
+ mutable logical_locations::selftest::test_manager m_logical_loc_mgr;
pretty_printer &m_pp;
};
static void
test_emission (pretty_printer *event_pp)
{
- struct test_rich_location : public gcc_rich_location
+ struct test_rich_location : public rich_location
{
test_rich_location (pretty_printer &event_pp)
- : gcc_rich_location (UNKNOWN_LOCATION),
+ : rich_location (line_table, UNKNOWN_LOCATION),
m_path (event_pp)
{
set_path (&m_path);
/* 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);
/* 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 ());
/* 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. */
pp_show_color (global_pp) = saved_show_color;
}
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
#endif /* #if CHECKING_P */
}
} // 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". */
}
private:
- test_diagnostic_context m_dc;
+ diagnostics::selftest::test_context m_dc;
test_spec_context m_ctxt;
diagnostics::sink &m_fmt;
};
/* 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 */
#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. */
static void
test_empty_path (pretty_printer *event_pp)
{
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, 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);
static void
test_intraprocedural_path (pretty_printer *event_pp)
{
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, 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);
static void
test_interprocedural_path_1 (pretty_printer *event_pp)
{
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_entry ("test", 0);
path.add_call ("test", 0, "make_boxed_int");
path.add_call ("make_boxed_int", 1, "wrapped_malloc");
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);
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);
static void
test_interprocedural_path_2 (pretty_printer *event_pp)
{
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_entry ("foo", 0);
path.add_call ("foo", 0, "bar");
path.add_call ("bar", 1, "baz");
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);
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);
static void
test_recursion (pretty_printer *event_pp)
{
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_entry ("factorial", 0);
for (int depth = 0; depth < 3; depth++)
path.add_call ("factorial", depth, "factorial");
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);
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);
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,
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);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_event (conditional, nullptr, 0,
"following %qs branch (when %qs is NULL)...",
"false", "p");
{
- 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);
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);
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);
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);
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);
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);
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);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_event (iter_test, nullptr, 0, "infinite loop here");
path.add_event (iter_test, nullptr, 0, "looping from here...");
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);
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);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_event (iter_test, nullptr, 0, "infinite loop here");
path.add_event (iter_test, nullptr, 0, "looping from here...");
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);
const location_t dst_loc,
const char *expected_str)
{
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
path.add_event (src_loc, nullptr, 0, "from here...");
path.connect_to_next_event ();
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);
control_flow_test t (SELFTEST_LOCATION, case_, content);
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
/* (1) */
path.add_event (t.get_line_and_column (1, 6), nullptr, 0,
"following %qs branch (when %qs is non-NULL)...",
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);
control_flow_test t (SELFTEST_LOCATION, case_, content);
- test_diagnostic_path path (event_pp);
+ logical_locations::selftest::test_manager logical_loc_mgr;
+ test_path path (logical_loc_mgr, event_pp);
/* (1) */
path.add_event (t.get_line_and_columns (6, 25, 35), nullptr, 0,
"allocated here");
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);
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
{
}
-} // 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 ()
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,
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,
/* 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. */
/* 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 ();
for_each_line_table_case (run_line_table_case_tests_per_version);
}
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
#endif /* CHECKING_P */
#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;
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 */
#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
+ /* Implementation of diagnostics::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
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);
};
} // namespace selftest
+} // namespace diagnostics
#endif /* #if CHECKING_P */
#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)
}
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;
/* 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));
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 */
#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;
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. */
#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)
-: path (m_test_logical_loc_mgr),
+test_path::
+test_path (logical_locations::selftest::test_manager &logical_loc_mgr,
+ pretty_printer *event_pp)
+: path (logical_loc_mgr),
+ m_test_logical_loc_mgr (logical_loc_mgr),
m_event_pp (event_pp)
{
add_thread ("main");
}
/* 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;
}
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);
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);
}
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);
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);
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,
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)),
{
}
-/* 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 */
#if CHECKING_P
+namespace diagnostics {
+namespace paths {
namespace selftest {
/* Concrete subclasses of the abstract base classes
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; }
/* 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);
};
/* 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 (logical_locations::selftest::test_manager &logical_loc_mgr,
+ pretty_printer *event_pp);
unsigned num_events () const final override;
const event & get_event (int idx) const final override;
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 */
#if CHECKING_P
+namespace diagnostics {
namespace selftest {
/* RAII class for use in selftests involving diagnostic_show_locus.
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
{
}
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;
};
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 */
#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,
/* 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_),
/* 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);
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);
}
{
- 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);
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. */
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);
/* 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;
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;
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);
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;
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));
}
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"
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",
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);
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"
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
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),
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 ("&");
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);
/* Normal. */
{
- test_diagnostic_context dc;
+ test_context dc;
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~\n"
" ------\n",
/* 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"
/* 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"
/* 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;
/* 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;
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);
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);
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);
/* 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"
" ^~~~~~~~~~ "
" "
/* 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"
" ^~~~~~~~~~ "
" "
/* 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"
" ^~~~~~~~~~ "
" "
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++)
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++)
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
{
- test_diagnostic_context dc;
+ test_context dc;
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
/* 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",
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"
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
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"
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"
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"
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"
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));
....................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);
/* 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
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"
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);
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),
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 ("&");
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);
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);
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);
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);
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);
/* 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"
/* 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"
/* 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"
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++)
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;
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"
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"
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"
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"
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"
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);
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)
{
}
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);
/* 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
/* 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
/* 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
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
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"
/* 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, "> (");
/* 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, ") (");
/* 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, ") (");
/* 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};
/* 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};
/* 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");
/* 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<");
/* 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, ") (");
/* 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, ") (");
/* 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};
/* 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};
/* 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");
/* 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);
/* 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, "{{");
/* Without line numbers. */
{
- test_diagnostic_context dc;
+ test_context dc;
ASSERT_STREQ (" x = a;\n"
"+ break;\n"
" case 'b':\n"
/* 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"
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));
return;
{
- test_diagnostic_context dc;
+ test_context dc;
ASSERT_STREQ ("FILENAME:1:1:\n"
"+#include <stdio.h>\n"
" test (int ch)\n"
/* 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"
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));
if (finish > LINE_MAP_MAX_LOCATION_WITH_COLS)
return;
- test_diagnostic_context dc;
+ test_context dc;
ASSERT_STREQ (" foo = bar (\n"
" ~^\n"
" );\n"
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,
/* 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,
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"
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",
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",
= 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);
/* Run all of the selftests within this file. */
void
-diagnostics_source_printing_cc_tests ()
+source_printing_cc_tests ()
{
test_line_span ();
test_line_numbers_multiline_range ();
}
-} // namespace selftest
+} // namespace diagnostics::selftest
+} // namespace diagnostics
#endif /* #if CHECKING_P */
#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);
/* 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 */
#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
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 ();
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 ();
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 ());