1 /* Self tests for lookup_name_info for GDB, the GNU debugger.
3 Copyright (C) 2017-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/selftest.h"
24 namespace lookup_name
{
26 /* Check that removing parameter info out of NAME produces EXPECTED.
27 COMPLETION_MODE indicates whether we're testing normal and
28 completion mode. FILE and LINE are used to provide better test
29 location information in case the check fails. */
32 check_make_paramless (const char *file
, int line
,
34 const char *name
, const char *expected
,
37 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
,
38 completion_mode
, true /* ignore_parameters */);
39 const char *result
= lookup_name
.language_lookup_name (lang
);
41 if (strcmp (result
, expected
) != 0)
43 error (_("%s:%d: make-paramless self-test failed: (completion=%d, lang=%d) "
44 "\"%s\" -> \"%s\", expected \"%s\""),
45 file
, line
, completion_mode
, lang
, name
,
53 /* Helper for CHECK and CHECK_INCOMPL. */
54 #define CHECK_1(INCOMPLETE, LANG, NAME, EXPECTED) \
57 check_make_paramless (__FILE__, __LINE__, \
59 (INCOMPLETE) ? "" : (EXPECTED), false); \
60 check_make_paramless (__FILE__, __LINE__, \
61 LANG, NAME, EXPECTED, true); \
65 /* Check that removing parameter info out of NAME produces EXPECTED.
66 Checks both normal and completion modes. */
67 #define CHECK(LANG, NAME, EXPECTED) \
68 CHECK_1(false, LANG, NAME, EXPECTED)
70 /* Similar, but used when NAME is incomplete -- i.e., NAME has
71 unbalanced parentheses. In this case, looking for the exact name
72 should fail / return empty. */
73 #define CHECK_INCOMPL(LANG, NAME, EXPECTED) \
74 CHECK_1 (true, LANG, NAME, EXPECTED)
76 /* None of these languages support function overloading like C++
77 does, so building a nameless lookup name ends up being just the
78 same as any other lookup name. Mainly this serves as smoke test
79 that C++-specific code doesn't mess up with other languages that
80 use some other scoping character ('.' vs '::'). */
81 CHECK (language_ada
, "pck.ada_hello", "pck__ada_hello");
82 CHECK (language_go
, "pck.go_hello", "pck.go_hello");
83 CHECK (language_fortran
, "mod::func", "mod::func");
85 /* D does support function overloading similar to C++, but we're
86 missing support for stripping parameters. At least make sure the
87 input name is preserved unmodified. */
88 CHECK (language_d
, "pck.d_hello", "pck.d_hello");
90 /* Just a few basic tests to make sure
91 lookup_name_info::make_paramless is well integrated with
92 cp_remove_params_if_any. gdb/cp-support.c has comprehensive
93 testing of C++ specifics. */
94 CHECK (language_cplus
, "function()", "function");
95 CHECK (language_cplus
, "function() const", "function");
96 CHECK (language_cplus
, "A::B::C()", "A::B::C");
97 CHECK (language_cplus
, "A::B::C", "A::B::C");
103 }} // namespace selftests::lookup_name
105 void _initialize_lookup_name_info_selftests ();
107 _initialize_lookup_name_info_selftests ()
109 selftests::register_test ("lookup_name_info",
110 selftests::lookup_name::run_tests
);